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