[483] | 1 | define([ |
---|
| 2 | "dojo/_base/declare", |
---|
| 3 | "dojo/_base/lang", |
---|
| 4 | "dojo/dom-style", |
---|
| 5 | "dijit/_WidgetBase", |
---|
| 6 | "dijit/_WidgetsInTemplateMixin", |
---|
| 7 | "dijit/_TemplatedMixin", |
---|
| 8 | "dojox/math/_base", |
---|
| 9 | "dijit/registry", |
---|
| 10 | "dojo/text!./templates/FuncGen.html", |
---|
| 11 | "dojox/calc/_Executor", |
---|
| 12 | "dijit/form/ComboBox", // template |
---|
| 13 | "dijit/form/SimpleTextarea", // template |
---|
| 14 | "dijit/form/Button", // template |
---|
| 15 | "dijit/form/TextBox" // template |
---|
| 16 | ], function(declare, lang, domStyle, WidgetBase, WidgetsInTemplateMixin, TemplatedMixin, math, registry, template, calc){ |
---|
| 17 | |
---|
| 18 | var FuncGen = declare( |
---|
| 19 | "dojox.calc.FuncGen", |
---|
| 20 | [WidgetBase, TemplatedMixin, WidgetsInTemplateMixin], |
---|
| 21 | { |
---|
| 22 | // summary: |
---|
| 23 | // The dialog layout for making functions |
---|
| 24 | |
---|
| 25 | templateString: template, |
---|
| 26 | |
---|
| 27 | onSelect: function(){ |
---|
| 28 | // summary: |
---|
| 29 | // if they select something in the name combobox, then change the body and arguments to correspond to the function they selected |
---|
| 30 | this.reset(); |
---|
| 31 | }, |
---|
| 32 | onClear: function(){ |
---|
| 33 | // summary: |
---|
| 34 | // The clear button in the template calls this. |
---|
| 35 | // Clear the name, arguments, and body if the user says yes. |
---|
| 36 | var answer = confirm("Do you want to clear the name, argument, and body text?"); |
---|
| 37 | if(answer){ |
---|
| 38 | this.clear(); |
---|
| 39 | } |
---|
| 40 | }, |
---|
| 41 | saveFunction: function(name, args, body){ |
---|
| 42 | // override me |
---|
| 43 | }, |
---|
| 44 | onSaved: function(){ |
---|
| 45 | // this on save needs to be overriden if you want Executor parsing support |
---|
| 46 | //console.log("Save was pressed"); |
---|
| 47 | }, |
---|
| 48 | clear: function(){ |
---|
| 49 | // summary: |
---|
| 50 | // clear the name, arguments, and body |
---|
| 51 | this.textarea.set("value", ""); |
---|
| 52 | this.args.set("value", ""); |
---|
| 53 | this.combo.set("value", ""); |
---|
| 54 | }, |
---|
| 55 | reset: function(){ |
---|
| 56 | // summary: |
---|
| 57 | // set the arguments and body to match a function selected if it exists in the function list |
---|
| 58 | if(this.combo.get("value") in this.functions){ |
---|
| 59 | this.textarea.set("value", this.functions[this.combo.get("value")].body); |
---|
| 60 | this.args.set("value", this.functions[this.combo.get("value")].args); |
---|
| 61 | } |
---|
| 62 | }, |
---|
| 63 | onReset: function(){ |
---|
| 64 | // summary: |
---|
| 65 | // (Reset button on click event) reset the arguments and body to their previously saved state if the user says yes |
---|
| 66 | |
---|
| 67 | //console.log("Reset was pressed"); |
---|
| 68 | if(this.combo.get("value") in this.functions){ |
---|
| 69 | var answer = confirm("Do you want to reset this function?"); |
---|
| 70 | if(answer){ |
---|
| 71 | this.reset(); |
---|
| 72 | this.status.set("value", "The function has been reset to its last save point."); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | }, |
---|
| 76 | deleteThing: function(item){ |
---|
| 77 | // summary: |
---|
| 78 | // delete an item in the writestore |
---|
| 79 | if(this.writeStore.isItem(item)){ |
---|
| 80 | // delete it |
---|
| 81 | //console.log("Found item "+item); |
---|
| 82 | this.writeStore.deleteItem(item); |
---|
| 83 | this.writeStore.save(); |
---|
| 84 | }else{ |
---|
| 85 | //console.log("Unable to locate the item"); |
---|
| 86 | } |
---|
| 87 | }, |
---|
| 88 | deleteFunction: function(name){ |
---|
| 89 | // override me |
---|
| 90 | }, |
---|
| 91 | onDelete: function(){ |
---|
| 92 | // summary: |
---|
| 93 | // (Delete button on click event) delete a function if the user clicks yes |
---|
| 94 | |
---|
| 95 | //console.log("Delete was pressed"); |
---|
| 96 | |
---|
| 97 | var name; |
---|
| 98 | if((name = this.combo.get("value")) in this.functions){ |
---|
| 99 | var answer = confirm("Do you want to delete this function?"); |
---|
| 100 | if(answer){ |
---|
| 101 | var item = this.combo.item; |
---|
| 102 | |
---|
| 103 | //this.writeStore.fetchItemByIdentity({identity:name, onItem: this.deleteThing, onError:null}); |
---|
| 104 | |
---|
| 105 | this.writeStore.deleteItem(item); |
---|
| 106 | this.writeStore.save(); |
---|
| 107 | |
---|
| 108 | this.deleteFunction(name); |
---|
| 109 | delete this.functions[name]; |
---|
| 110 | this.clear(); |
---|
| 111 | } |
---|
| 112 | }else{ |
---|
| 113 | this.status.set("value", "Function cannot be deleted, it isn't saved."); |
---|
| 114 | } |
---|
| 115 | }, |
---|
| 116 | readyStatus: function(){ |
---|
| 117 | // summary: |
---|
| 118 | // set the status in the template to ready |
---|
| 119 | this.status.set("value", "Ready"); |
---|
| 120 | }, |
---|
| 121 | writeStore:null, //the user can save functions to the writestore |
---|
| 122 | readStore:null, // users cannot edit the read store contents, but they can use them |
---|
| 123 | functions:null, // use the names to get to the function |
---|
| 124 | |
---|
| 125 | /*postCreate: function(){ |
---|
| 126 | this.functions = []; // use the names to get to the function |
---|
| 127 | this.writeStore = new dojo.data.ItemFileWriteStore({data: {identifier: 'name', items:[]}}); |
---|
| 128 | |
---|
| 129 | this.combo.set("store", this.writeStore); |
---|
| 130 | },*/ |
---|
| 131 | |
---|
| 132 | startup: function(){ |
---|
| 133 | // summary: |
---|
| 134 | // make sure the parent has a close button if it needs to be able to close |
---|
| 135 | // link the write store too |
---|
| 136 | this.combo.set("store", this.writeStore); |
---|
| 137 | |
---|
| 138 | this.inherited(arguments);// this is super class startup |
---|
| 139 | // close is only valid if the parent is a widget with a close function |
---|
| 140 | var parent = registry.getEnclosingWidget(this.domNode.parentNode); |
---|
| 141 | if(parent && typeof parent.close == "function"){ |
---|
| 142 | this.closeButton.set("onClick", lang.hitch(parent, 'close')); |
---|
| 143 | }else{ |
---|
| 144 | domStyle.set(this.closeButton.domNode, { display: "none" }); // hide the button |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | }); |
---|
| 148 | |
---|
| 149 | return lang.mixin(calc, { FuncGen: FuncGen }); |
---|
| 150 | }); |
---|