Builder/EditProject.js
[app.Builder.js] / Builder / EditProject.js
1 //<Script type="text/javascript">
2
3 XN = imports.xnew;
4 Gtk = imports.gi.Gtk;
5 GObject = imports.gi.GObject;
6 console = imports.console;
7 Builder = imports['Builder.js'];
8 Roo = imports['Roo.js'];
9
10 /**
11  * add/edit project
12  * 
13  * project type: gtk or roo..
14  * 
15  * directory.
16  * 
17  * 
18  * 
19  */
20
21 var _form = { };
22
23
24
25 function create() // parent?
26 {
27     
28     
29     return {
30         xns : 'Gtk',
31         xtype : 'Dialog',
32         type: Gtk.WindowType.TOPLEVEL,
33         deletable : false,
34         modal : true,
35          
36         project : false,
37         
38         show : function (c) 
39         {
40             c = c || { name : '' , xtype : '' };
41             this.project  = c;
42             
43             for (k in _form) {
44                 if (!_form[k]) {
45                     Seed.print(k);
46                     continue;
47                 }
48                 
49                 _form[k].setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
50             }
51             this.el.show_all();
52             this.success = c.success;
53             
54             
55         },
56         
57         listeners : 
58         {
59             'delete-event' : function (widget, event) {
60                 this.el.hide();
61                 return true;
62             },
63             
64             response : function (w, id) 
65             {
66                 
67                 if (id < 1) {
68                     this.el.hide();
69                     return;
70                 }
71                 if (!_form.xtype.getValue().length) {
72                     
73                     XN.xnew({
74                         xtype : 'MessageDialog',
75                         xns : 'Gtk',
76                         modal : true,
77                         buttons : Gtk.ButtonsType.OK,
78                         'message-type' : Gtk.MessageType.ERROR,
79                         //"secondary-text"           gchar*                : Read / Write
80                         //"secondary-use-markup"     gboolean              : Read / Write
81                         text   : "You have to set Project type",
82                         "use-markup"     : true,
83                         listeners : 
84                         {
85                             'delete-event' : function (widget, event) {
86                                 this.el.hide();
87                                 return true;
88                             },
89                             _rendered : function()
90                             {
91                                 this.el.show_all();
92                             },
93                             response : function () {
94                                 this.el.hide();
95                             }
96                         }
97                    });
98                     
99                     return;
100                 }
101                 this.el.hide();
102                 
103                 
104                 
105                 
106                 this.project.name  = _form.name.getValue();
107                 this.project.xtype  = _form.xtype.getValue();
108                 
109                 
110                 
111                 
112                 var pr = Builder.Provider.ProjectManager.update(this.project);
113                 
114                 this.success(pr);
115                 Seed.print(id);
116             },
117             
118             _new  : function(self) {
119                 _win = this;
120                 _form = { };
121             },
122             _rendered : function()
123             {
124                 this.el.add_button("OK",1 );
125                 this.el.add_button("Cancel",0 );
126                 
127                 
128             }
129         },
130         
131         set : {
132             set_border_width : [ 0 ],
133             set_title : [ 'Project Properties' ],
134             set_default_size: [600, 400] //,
135             
136             //show_all : []
137         },
138      
139         items : [
140             {
141                 
142                 xtype : 'VBox',
143                 xns: 'Gtk',
144                 
145                 packing : function(p,e) {
146                     p.el.get_content_area().add(e.el)
147                 },
148                 items : [
149                     {
150                         xtype : 'HBox',
151                         xns: 'Gtk',
152                         packing : [ 'pack_start', false, true , 0 ],
153                         
154                         items : [
155                             {
156                                 xtype : 'Label',
157                                 packing : [ 'pack_start', false, true , 0 ],
158                                 xns: 'Gtk',
159                                 label : "Project Name:"
160                             },
161                             
162                             {
163                                 xtype : 'Entry',
164                                 
165                                 xns: 'Gtk',
166                                 packing : [ 'pack_end', true, true , 0 ],
167                                 listeners : {
168                                     _rendered  : function(self) {
169                                         
170                                         _form.name = this;
171                                     }
172                                 },
173                                 setValue : function(v) {
174                                     this.el.set_text(v);
175                                 },
176                                 getValue : function()
177                                 {
178                                     return this.el.get_text();
179                                 }
180                             }
181                          
182                         ]
183                         
184                     },
185                     {
186                         xtype : 'HBox',
187                         xns: 'Gtk',
188                         packing : [ 'pack_start', false, true , 0 ],
189                         
190                         items : [
191                             {
192                                 xtype : 'Label',
193                                 packing : [ 'pack_start', false, true , 0 ],
194                                 xns: 'Gtk',
195                                 label : "Project Type:"
196                             },
197                             
198                             
199                             {
200                 
201                                 xns : 'Gtk',
202                                 xtype : 'ComboBox',
203                                 packing : [ 'pack_end', true, true , 0 ],
204                                 set : {
205                                  //   set_text_column : [1]
206                                    //set_size_request : [150,-1]
207                                 },
208                                 
209                             
210                                 setValue : function(v)
211                                 {
212                                     var el = this.el;
213                                     el.set_active(-1);
214                                     Roo.each(this.model.data, function(n, ix) {
215                                         if (v == n.xtype) {
216                                             el.set_active(ix);
217                                             return false;
218                                         }
219                                     })
220                                 },
221                                 getValue : function() 
222                                 {
223                                     var ix = this.el.get_active();
224                                     if (ix < 0 ) {
225                                         return '';
226                                     }
227                                     return this.model.data[ix].xtype;
228                                     /*
229                                     var iter = new Gtk.TreeIter();
230                                     if (this.el.get_active_iter(iter)) {
231                                         return '';
232                                     }
233                                     var value = new GObject.Value('');
234                                     this.model.el.get_value(iter, 0, value);
235                                     return value.value;
236                                     */
237                                 },
238                                 
239                                 
240                                 listeners : {
241                                     
242                                     _new : function ()
243                                     {
244                                         _view = this;
245                                     },
246                                     
247                                     _rendered  : function ()
248                                     {
249                                         
250                                         _form.xtype = this;
251                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );  
252                                         //this.el.add_attribute(this.items[0].el , 'popup', 2 );     
253                                          
254                                      
255                                   
256                                     }
257                                 },
258                                 items : [
259                                    {
260                                         
261                                         
262                                    
263                                         xns : 'Gtk',
264                                         xtype : 'CellRendererText',
265                                         packing : ['pack_start'],
266                                         
267
268                                          
269                                     },
270                                     {
271                                         xns : 'Gtk',
272                                         packing : [ 'set_model' ],
273                                         xtype : 'ListStore',
274                                         
275                                         listeners : {
276                                             _new : function()
277                                             {
278                                                 _view.model = this;
279                                             },
280                                             _rendered :  function ()
281                                             {
282                                              
283                                                 this.el.set_column_types ( 2, [
284                                                     GObject.TYPE_STRING,  // real key
285                                                     GObject.TYPE_STRING // real type
286                                                     
287                                                     
288                                                 ] );
289                                                 
290                                                 this.data = [
291                                                     { xtype: 'Roo', desc : "Roo Project" },
292                                                     { xtype: 'Gtk', desc : "Gtk Project" },    
293                                                     //{ xtype: 'JS', desc : "Javascript Class" }
294                                                 ]
295                                                 
296                                                 this.loadData(this.data);
297                                                 
298                                                 return;
299                                                
300                                             
301                                             
302                                             }
303                                         },
304                                        
305                                        
306                                         
307                                         loadData : function (data) {
308                                             
309                                             var iter = new Gtk.TreeIter();
310                                             var el = this.el;
311                                             Roo.each(data, function(p) {
312                                                 
313                                                 el.append(iter);
314                                                 
315                                                  
316                                                 el.set_value(iter, 0, p.xtype);
317                                                 el.set_value(iter, 1, p.desc);
318                                                 
319                                             });
320                                              
321                                             
322                                             
323                                         }
324                                          
325                                     }
326                                   
327                                          
328                                 ]
329                             }
330                  
331                                 
332                         ]
333                     },
334                     {
335                         xtype : 'Label',
336                         packing : [ 'pack_end', true, true , 0 ],
337                         xns: 'Gtk',
338                         label : ""
339                     },
340                     
341                     
342                     
343                     
344                 ]
345             }
346         ]
347     };
348     
349 }
350 //_win = XN.xnew(create());