Builder/EditProject.js
[app.Builder.js] / Builder / EditProject.js
1 //<Script type="text/javascript">
2
3  
4 Gtk = imports.gi.Gtk;
5 GObject = imports.gi.GObject;
6 console = imports.console;
7 XObject = imports.XObject.XObject;
8
9 StandardErrorDialog = imports.Builder.StandardErrorDialog.StandardErrorDialog;
10 ProjectManager =      imports.Builder.Provider.ProjectManager.ProjectManager;
11 /**
12  * add/edit project
13  * 
14  * project type: gtk or roo..
15  * 
16  * directory.
17  * 
18  * 
19  * 
20  */
21
22  
23 EditProject = new XObject({
24     
25         
26         xtype : Gtk.Dialog,
27         type: Gtk.WindowType.TOPLEVEL,
28         deletable : false,
29         modal : true,
30         border_width : 0,
31         title : "Project Properties",
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             this.el.set_default_size(600, 400);
40         },
41         show : function (c) 
42         {
43             
44             c = c || { name : '' , xtype : '' };
45             this.project  = c;
46             var _this = this;
47             [ 'xtype' , 'name' ].forEach(function(k) {
48                 _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
49             });
50             if (!this.el) {
51                 this.init();
52             }
53             this.el.show_all();
54             this.success = c.success;
55             
56             
57         },
58         
59         listeners :  {
60             
61             'delete-event' : function (widget, event) {
62                 this.el.hide();
63                 return true;
64             },
65             
66             response : function (w, id) 
67             {
68                 
69                 if (id < 1) {
70                     this.el.hide();
71                     return;
72                 }
73                 if (!this.get('xtype').getValue().length) {
74                     StandardErrorDialog.show("You have to set Project type");
75                      
76                     return;
77                 }
78                 this.el.hide();
79                 
80                 
81                 
82                 
83                 this.project.name  = this.get('name').getValue();
84                 this.project.xtype  = this.get('xtype').getValue();
85                 
86                 
87                 
88                 
89                 var pr = ProjectManager.update(this.project);
90                 
91                 this.success(pr);
92                 Seed.print(id);
93             },
94             
95         
96             
97         },
98         
99       
100         items : [
101             {
102                 
103                 xtype : Gtk.VBox,
104                 pack : function(p,e) {
105                     p.el.get_content_area().add(e.el)
106                 },
107                 items : [
108                     {
109                         xtype : Gtk.HBox,
110                         pack : [ 'pack_start', false, true , 0 ],
111                         items : [
112                             {
113                                 xtype : Gtk.Label,
114                                 pack : [ 'pack_start', false, true , 0 ],
115                                 label : "Project Name:"
116                             },
117                             
118                             {
119                                 xtype : Gtk.Entry,
120                                 id : 'name',
121                                 pack : [ 'pack_end', true, true , 0 ],
122                                 
123                                 setValue : function(v) 
124                                 {
125                                     this.el.set_text(v);
126                                 },
127                                 getValue : function()
128                                 {
129                                     return this.el.get_text();
130                                 }
131                             }
132                          
133                         ]
134                         
135                     },
136                     {
137                         xtype : Gtk.HBox,
138                         pack : [ 'pack_start', false, true , 0 ],
139                         items : [
140                             {
141                                 xtype : Gtk.Label,
142                                 pack : [ 'pack_start', false, true , 0 ],
143                                 label : "Project Type:"
144                             },
145                             {
146                                 xtype : Gtk.ComboBox,
147                                 id : 'xtype',
148                                 pack : [ 'pack_end', true, true , 0 ],
149                                 init : function() {
150                                     XObject.prototype.init.call(this); 
151                                     this.el.add_attribute(this.items[0].el , 'markup', 1 );  
152                                 },
153                                 setValue : function(v)
154                                 {
155                                     var el = this.el;
156                                     el.set_active(-1);
157                                     this.get('model').data.forEach(function(n, ix) {
158                                         if (v == n.xtype) {
159                                             el.set_active(ix);
160                                             return false;
161                                         }
162                                     });
163                                 },
164                                 getValue : function() 
165                                 {
166                                     var ix = this.el.get_active();
167                                     if (ix < 0 ) {
168                                         return '';
169                                     }
170                                     return this.get('model').data[ix].xtype;
171                                     /*
172                                     var iter = new Gtk.TreeIter();
173                                     if (this.el.get_active_iter(iter)) {
174                                         return '';
175                                     }
176                                     var value = new GObject.Value('');
177                                     this.model.el.get_value(iter, 0, value);
178                                     return value.value;
179                                     */
180                                 },
181                                 
182                                 
183                                 items : [
184                                     {
185                                         xtype : Gtk.CellRendererText,
186                                         pack : ['pack_start']
187                                     },
188                                     {
189                                         id : 'model',
190                                         pack : [ 'set_model' ],
191                                         xtype : Gtk.ListStore,
192                                         init : function ()
193                                         {
194                                             XObject.prototype.init.call(this); 
195                              
196                                      
197                                             this.el.set_column_types ( 2, [
198                                                 GObject.TYPE_STRING,  // real key
199                                                 GObject.TYPE_STRING // real type
200                                                 
201                                                 
202                                             ] );
203                                             
204                                             this.data = [
205                                                 { xtype: 'Roo', desc : "Roo Project" },
206                                                 { xtype: 'Gtk', desc : "Gtk Project" },    
207                                                 //{ xtype: 'JS', desc : "Javascript Class" }
208                                             ]
209                                             
210                                             this.loadData(this.data);
211                                                 
212                                             
213                                             
214                                         },
215                                        
216                                        
217                                         
218                                         loadData : function (data) {
219                                             
220                                             var iter = new Gtk.TreeIter();
221                                             var el = this.el;
222                                             data.forEach(function(p) {
223                                                 
224                                                 el.append(iter);
225                                                 
226                                                  
227                                                 el.set_value(iter, 0, p.xtype);
228                                                 el.set_value(iter, 1, p.desc);
229                                                 
230                                             });
231                                              
232                                             
233                                             
234                                         }
235                                          
236                                     }
237                                   
238                                          
239                                 ]
240                             }
241                  
242                                 
243                         ]
244                     },
245                     {
246                         xtype : Gtk.Label,
247                         pack : [ 'pack_end', true, true , 0 ],
248                         
249                         label : ""
250                     }
251                     
252                     
253                     
254                     
255                 ]
256             }
257         ]
258     }
259     
260 )
261 //_win = XN.xnew(create());