source: Dev/branches/rest-dojo-ui/client/dojox/calc/FuncGen.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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