| 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", |
| 13 |
"dijit/form/SimpleTextarea", |
| 14 |
"dijit/form/Button", |
| 15 |
"dijit/form/TextBox" |
| 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 |
|
| 23 |
|
| 24 |
|
| 25 |
templateString: template, |
| 26 |
|
| 27 |
onSelect: function(){ |
| 28 |
|
| 29 |
|
| 30 |
this.reset(); |
| 31 |
}, |
| 32 |
onClear: function(){ |
| 33 |
|
| 34 |
|
| 35 |
|
| 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 |
|
| 43 |
}, |
| 44 |
onSaved: function(){ |
| 45 |
|
| 46 |
|
| 47 |
}, |
| 48 |
clear: function(){ |
| 49 |
|
| 50 |
|
| 51 |
this.textarea.set("value", ""); |
| 52 |
this.args.set("value", ""); |
| 53 |
this.combo.set("value", ""); |
| 54 |
}, |
| 55 |
reset: function(){ |
| 56 |
|
| 57 |
|
| 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 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 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 |
|
| 78 |
|
| 79 |
if(this.writeStore.isItem(item)){ |
| 80 |
|
| 81 |
|
| 82 |
this.writeStore.deleteItem(item); |
| 83 |
this.writeStore.save(); |
| 84 |
}else{ |
| 85 |
|
| 86 |
} |
| 87 |
}, |
| 88 |
deleteFunction: function(name){ |
| 89 |
|
| 90 |
}, |
| 91 |
onDelete: function(){ |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 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 |
|
| 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 |
|
| 118 |
|
| 119 |
this.status.set("value", "Ready"); |
| 120 |
}, |
| 121 |
writeStore:null, |
| 122 |
readStore:null, |
| 123 |
functions:null, |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
startup: function(){ |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
this.combo.set("store", this.writeStore); |
| 137 |
|
| 138 |
this.inherited(arguments); |
| 139 |
|
| 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" }); |
| 145 |
} |
| 146 |
} |
| 147 |
}); |
| 148 |
|
| 149 |
return lang.mixin(calc, { FuncGen: FuncGen }); |
| 150 |
}); |