| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> |
| 3 |
<mx:Script> |
| 4 |
import mx.controls.*; |
| 5 |
import mx.rpc.events.*; |
| 6 |
import mx.utils.ArrayUtil; |
| 7 |
|
| 8 |
[Bindable] |
| 9 |
public var recipes:Array; |
| 10 |
|
| 11 |
public function init():void |
| 12 |
{ |
| 13 |
getRecipes(); |
| 14 |
} |
| 15 |
/* |
| 16 |
this is a C Comment |
| 17 |
*/ |
| 18 |
|
| 19 |
public function onFault(event:FaultEvent):void |
| 20 |
{ |
| 21 |
Alert.show(event.fault.faultString, "Error"); |
| 22 |
} |
| 23 |
|
| 24 |
public function onViewsResult(event:ResultEvent):void |
| 25 |
{ |
| 26 |
recipes = ArrayUtil.toArray(event.result); |
| 27 |
} |
| 28 |
|
| 29 |
public function getRecipes():void |
| 30 |
{ |
| 31 |
views.getView("recipes_all", ['nid','title','body','changed']); |
| 32 |
} |
| 33 |
|
| 34 |
public function saveRecipe():void |
| 35 |
{ |
| 36 |
var edit:Object; |
| 37 |
if (recipes_select.selectedItem) { |
| 38 |
edit = recipes_select.selectedItem; |
| 39 |
} |
| 40 |
else { |
| 41 |
edit = new Object; |
| 42 |
} |
| 43 |
|
| 44 |
edit.type = "recipe"; |
| 45 |
|
| 46 |
edit.title = dish.text; |
| 47 |
edit.body = recipe.text; |
| 48 |
|
| 49 |
if (edit.title == "" || edit.body == "") { |
| 50 |
Alert.show("Enter some content", "Error"); |
| 51 |
} |
| 52 |
|
| 53 |
node.save(edit); |
| 54 |
getRecipes(); |
| 55 |
} |
| 56 |
|
| 57 |
public function onSaved(event:ResultEvent):void |
| 58 |
{ |
| 59 |
Alert.show("Recipe was saved", "Saved"); |
| 60 |
} |
| 61 |
|
| 62 |
public function newRecipe():void |
| 63 |
{ |
| 64 |
recipes_select.selectedItem = undefined; |
| 65 |
|
| 66 |
dish.text = ""; |
| 67 |
recipe.text = ""; |
| 68 |
} |
| 69 |
</mx:Script> |
| 70 |
|
| 71 |
<mx:RemoteObject showBusyCursor="true" destination="amfphp" source="views" id="views"> |
| 72 |
<mx:method name="getView" result="onViewsResult(event)" fault="onFault(event)" /> |
| 73 |
</mx:RemoteObject> |
| 74 |
|
| 75 |
<mx:RemoteObject showBusyCursor="true" destination="amfphp" source="node" id="node"> |
| 76 |
<mx:method name="save" result="onSaved(event)" fault="onFault(event)" /> |
| 77 |
</mx:RemoteObject> |
| 78 |
|
| 79 |
<mx:Panel width="500" height="400" layout="absolute" title="Recipes" horizontalCenter="0" verticalCenter="0"> |
| 80 |
<mx:DataGrid x="10" y="10" width="460" id="recipes_select" dataProvider="{recipes}" > |
| 81 |
<mx:columns> |
| 82 |
<mx:DataGridColumn headerText="NID" dataField="nid" width="40"/> |
| 83 |
<mx:DataGridColumn headerText="Dish" dataField="title"/> |
| 84 |
</mx:columns> |
| 85 |
</mx:DataGrid> |
| 86 |
|
| 87 |
<mx:Label x="10" y="160" text="Dish"/> |
| 88 |
|
| 89 |
<mx:TextInput x="10" y="186" width="460" id="dish" text="{recipes_select.selectedItem.title}"/> |
| 90 |
<!-- an |
| 91 |
html comment --> |
| 92 |
|
| 93 |
<mx:Label x="10" y="216" text="Recipe"/> |
| 94 |
|
| 95 |
<mx:TextArea x="10" y="242" width="460" height="75" id="recipe" text="{recipes_select.selectedItem.body}"/> |
| 96 |
|
| 97 |
<mx:Button x="416" y="328" label="Save" click="saveRecipe()"/> |
| 98 |
|
| 99 |
<mx:Button x="420" y="158" label="New" click="newRecipe()"/> |
| 100 |
|
| 101 |
</mx:Panel> |
| 102 |
</mx:Application> |