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