source: Dev/branches/rest-dojo-ui/client/rft/ui/ObjectBox.js @ 350

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

Merge and integrate mockups in proper pages.

File size: 5.9 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/lang',
4    'dijit/_WidgetBase',
5    'dijit/_TemplatedMixin',
6    'dijit/_WidgetsInTemplateMixin',
7    'rft/ui/LineWithActionsWidget',
8    'dojo/text!./templates/ObjectBox.html',
9    ], function(declare, lang, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, LineWithActionsWidget, template){
10        return declare('rft.ui.ObjectBox', [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
11            baseClass: "rftObjectBox",
12            templateString: template,
13           
14            constructor: function() {
15                this.title = "";
16                this.subTitle = "";
17                this.lowerTitle = "";
18                this.objectType = "SessionTemplate";
19                this.actions = {}
20               
21            },
22            postCreate: function() {
23                this.line1 = new LineWithActionsWidget({
24                    title: this.title || "Untitled",
25                    modifiers: 'green',
26                    actions: {
27                        "inspectIcon": {
28                            callback: lang.hitch(this, "_inspectObject"),
29                            properties: {
30                                blockButton: false,
31                                modifiers: "white",
32                                icon: "Inspect"
33                            }
34                        }
35                    }
36                }).placeAt(this.line1Node);
37                this.line2 = new LineWithActionsWidget({
38                    title: this.subTitle || "",
39                    modifiers: 'green',
40                    actions: {}
41                }).placeAt(this.line1Node);
42                var line3Actions = this._createLine3Actions();
43                this.line3 = new LineWithActionsWidget({
44                    title: this.lowerTitle || "",
45                    modifiers: 'green',
46                    actions: line3Actions
47                }).placeAt(this.line1Node);
48                this.line1.startup();
49                this.line2.startup();
50                this.line3.startup();
51                this.inherited(arguments);
52            },
53            _createLine3Actions: function() {
54                var ac = {};
55                if (this.actions["edit"]) {
56                    ac["edit"] = {
57                        callback: lang.hitch(this, "_editObject", this.actions["edit"]),
58                        properties: {
59                            blockButton: true,
60                            label: "Edit/View",
61                            modifiers: "trans",
62                            icon: "Edit"
63                        }
64                    };
65                    delete this.actions["edit"];
66                }
67                if (this.actions["delete"]) {
68                    ac["delete"] = {
69                        callback: lang.hitch(this, "_deleteObject", this.actions["delete"]),
70                        properties: {
71                            blockButton: true,
72                            label: "Delete",
73                            modifiers: "trans",
74                            icon: "Delete"
75                        }
76                    };
77                    delete this.actions["delete"];
78                }
79                for (action in this.actions) {
80                    ac[action] = {
81                        callback: lang.hitch(this, this.actions[action]),
82                        properties: {
83                            blockButton: true,
84                            label: action,
85                            modifiers: "trans",
86                            icon: action.charAt(0).toUpperCase()+action.slice(1)
87                        }
88                    }
89                }
90                return ac;
91            },
92           
93            _setObjectReference: function(identifier) {
94            // TODO: Set this ObjectBox to refer to a certain database object
95        },
96        _getObjectInfo: function() {
97            // TODO: Query the database and retrieve a JSON array of object properties
98        },
99        _inspectObject: function() {
100            // TODO: Get object information (or retrieve from cache), then display in popup
101        },
102        _editObject: function(customFunction) {
103            // TODO: Pass an edit call to the page script, along with reference to the object contained in this ObjectBox
104            alert("Default edit code");
105            customFunction();
106        },
107        _deleteObject: function(customFunction) {
108            // TODO: Pass a delete call to the page script, along with reference to the object contained in this ObjectBox
109            customFunction();
110        },
111           
112           
113        _setTitleAttr: function(value) {
114            this.title = value;
115            if (this.line1 && this.line1.set) {
116                this.line1.set('title', this.title);
117            }
118        },
119        _setSubTitleAttr: function(value) {
120            this.subTitle = value;
121            if (this.line2 && this.line2.set) {
122                this.line2.set('title', this.subTitle);
123            }
124        },
125        _setLowerTitleAttr: function(value) {
126            this.lowerTitle = value;
127            if (this.line3 && this.line3.set) {
128                this.line3.set('title', this.lowerTitle);
129            }
130        },
131        _setObjectTypeAttr: function(value) {
132            this.objectType = value;
133            this.iconNode.className = "rftIcon typeIcon rftIcon"+this.objectType;
134        },
135
136        /* This is an experiment to embed the creation function in the ObjectBox class itself. This method cannot be static, but can be called externally as such:
137         * rft.ui.ObjectBox().CreateNew(args, ref, loc);
138         * TODO: Check with Hendrik if I should do this or not!
139         * */
140         CreateNew: function(arguments, reference, location) {
141            var newBox = new rft.ui.ObjectBox(arguments);
142            newBox.startup();
143            newBox.placeAt(reference, location);
144        }
145    });
146});
Note: See TracBrowser for help on using the repository browser.