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