Attribute Changed :FixBug.bjs
[gitlive] / FixBug.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
12 FixBug=new XObject({
13     xtype: Gtk.Window,
14     listeners : {
15         destroy_event : function (self, event) {
16              this.el.hide();
17                         return false;
18         },
19         show : function (self) {
20         print("ON SHOW!");
21         
22             this.el.fullscreen();
23             this.el.grab_focus();
24             this.el.set_keep_above(true);
25             
26             this.get('/today-vew').load();
27             
28         }
29     },
30     border_width : 3,
31     default_height : 400,
32     default_width : 1200,
33     title : "Select Active Bug",
34     deletable : true,
35     modal : true,
36     show : function(c) {
37         
38         if (!this.el) {
39             this.init();
40         }
41         var _this = this;
42         /*[ 'xtype'  ].forEach(function(k) {
43             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
44         });
45         // shouild set path..
46         */
47     
48         
49         this.el.show_all();
50        // this.get('/ok_button').el.set_sensitive(false);
51         
52         // block until we return.
53         //    var run_ret = this.el.run();
54         //    if (run_ret < 1 ) {
55         //        return false;
56         //    }
57         //    print("RUN RETURN : " + run_ret);
58         
59         //print(JSON.stringify(this.get('bug').getValue()));
60         //return this.get('bug').getValue();
61         //this.success = c.success;
62     },
63     items : [
64         {
65             xtype: Gtk.VBox,
66             pack : "add",
67             items : [
68                 {
69                     xtype: Gtk.HBox,
70                     pack : "pack_start,false,true,3",
71                     items : [
72                         {
73                             xtype: Gtk.Label,
74                             label : "On this project:"
75                         },
76                         {
77                             xtype: Gtk.ComboBox,
78                             listeners : {
79                                 changed : function (self) {
80                                     print("store: active id = " + this.el.get_active_id());
81                                     this.get('/ticket-store').reload();
82                                     
83                                     
84                                 }
85                             },
86                             id : "project-select",
87                             init : function() {
88                                  this.el = new Gtk.ComboBox.with_entry();
89                                                             
90                                                             
91                                 this.model  = new XObject(this.model);
92                                 this.model.init();
93                                 this.el.set_model(this.model.el);
94                                 this.el.set_entry_text_column (0);
95                                 XObject.prototype.init.call(this);
96                                 
97                                  var t = this;
98                                 imports.Projects.Projects.fetch(  function(res) { 
99                                      t.load(res);
100                                 });
101                             },
102                             load : function(tr) {
103                                   this.model.el.clear();
104                                   this.raw_data = tr;                     
105                                      for(var i =0 ; i < tr.length; i++) {
106                                         var ret = {  };
107                                         this.model.el.append(ret);
108                                         //print(JSON.stringify(ret,null,4));
109                                        
110                                         this.model.el.set_value(ret.iter, 0, '' + tr[i].code + " - " + tr[i].name );
111                                         this.model.el.set_value(ret.iter, 1, '' + tr[i].id  );
112                                  
113                                         
114                                     }     
115                                     
116                             },
117                             model : {
118                                 xtype: Gtk.ListStore,
119                                 id : "project-store",
120                                 init : function() {
121                                     XObject.prototype.init.call(this);
122                                     this.el.set_column_types ( 3, [
123                                            GObject.TYPE_STRING, // file  
124                                           GObject.TYPE_STRING, // added
125                                           GObject.TYPE_STRING, // removed
126                                       ] );
127                                 }
128                             }
129                         },
130                         {
131                             xtype: Gtk.Button,
132                             listeners : {
133                                 button_press_event : function (self, event) {
134                                  
135                                     FixBug.el.hide();
136                                 }
137                             },
138                             height_request : 90,
139                             label : "Not working on Project",
140                             pack : "add"
141                         },
142                         {
143                             xtype: Gtk.Button,
144                             listeners : {
145                                 button_press_event : function (self, event) {
146                                 
147                                    FixBug.el.hide();
148                                 }
149                             },
150                             id : "ok_button",
151                             label : "Working on Selected Ticket",
152                             pack : "add"
153                         }
154                     ]
155                 },
156                 {
157                     xtype: Gtk.HPaned,
158                     pack : "pack_end,true,true,3",
159                     items : [
160                         {
161                             xtype: Gtk.VBox,
162                             pack : "add",
163                             width_request : 400,
164                             items : [
165                                 {
166                                     xtype: Gtk.HBox,
167                                     pack : "pack_start,false,true,3",
168                                     items : [
169                                         {
170                                             xtype: Gtk.Entry,
171                                             listeners : {
172                                                 key_release_event : function (self, event) {
173                                                     print(JSON.stringify(event,null,4)); //.keyval);
174                                                     return true;
175                                                 }
176                                             },
177                                             id : "search-entry",
178                                             pack : "pack_start,true,true,3"
179                                         },
180                                         {
181                                             xtype: Gtk.Button,
182                                             listeners : {
183                                                 clicked : function (self) {
184                                                     var active_id = this.get('/project-select').el.get_active();
185                                                      
186                                                     var project_id = this.get('/project-select').raw_data[active_id].id;
187                                                     
188                                                     var str = this.get('/search-entry').el.get_text();
189                                                     
190                                                     print(str);
191                                                     
192                                                     var _t = this;
193                                                     
194                                                     imports.Tasks.Tasks.query({
195                                                         project_id : project_id,
196                                                         'query[filter]' : 'me',
197                                                         'query[search]' : str
198                                                     }, function(res) { 
199                                                        // print(JSON.stringify(res,null,4));
200                                                         _t.get('/ticket-store').loadData(res);
201                                                     });
202                                                 }
203                                             },
204                                             label : "Search",
205                                             pack : "pack_end,false,true,3",
206                                             use_stock : true
207                                         }
208                                     ]
209                                 },
210                                 {
211                                     xtype: Gtk.ScrolledWindow,
212                                     pack : "pack_end,true,true,3",
213                                     shadow_type : Gtk.ShadowType.IN,
214                                     items : [
215                                         {
216                                             xtype: Gtk.TreeView,
217                                             fixed_height_mode : true,
218                                             id : "ticket-view",
219                                             pack : "add",
220                                             can_focus : true,
221                                             headers_visible : false,
222                                             init : function() {
223                                                 XObject.prototype.init.call(this);
224                                                 var description = new Pango.FontDescription.c_new();
225                                                 description.set_size(10000);
226                                                 this.el.modify_font(description);
227                                             
228                                                 this.selection = this.el.get_selection();
229                                                 this.selection.set_mode( Gtk.SelectionMode.SINGLE);
230                                                 var _t = this;
231                                             
232                                                 // is this really needed??
233                                                 this.selection.signal['changed'].connect(function() {
234                                                     print('selection changed');
235                                                 
236                                             
237                                                 });
238                                             
239                                             },
240                                             items : [
241                                                 {
242                                                     xtype: Gtk.ListStore,
243                                                     id : "ticket-store",
244                                                     pack : "set_model",
245                                                     columns : [
246                                                             GObject.TYPE_STRING, // title 
247                                                             GObject.TYPE_STRING, // tip
248                                                             GObject.TYPE_STRING // source..
249                                                     ],
250                                                     init : function() {
251                                                         XObject.prototype.init.call(this);
252                                                     
253                                                         this.el.set_column_types ( 2, [
254                                                             GObject.TYPE_STRING,  // real key
255                                                             GObject.TYPE_STRING // real type
256                                                             
257                                                             
258                                                         ] );
259                                                     
260                                                     
261                                                         
262                                                         // var t = this;
263                                                         //imports.Projects.Projects.fetch(  function(res) { 
264                                                         //    t.loadData(res);
265                                                        // });
266                                                             
267                                                                                     
268                                                     },
269                                                     loadData : function (data) {
270                                                             print("loading data");
271                                                                                         
272                                                         var el = this.el;
273                                                         this.el.clear();
274                                                         data.forEach(function(p) {
275                                                             var ret = {};
276                                                             el.append(ret);
277                                                            //print("ADD " + p.name);
278                                                              
279                                                             el.set_value(ret.iter, 0, p.id);
280                                                             el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' + 
281                                                                 '[' + p.status_name + '] <b>'   + p.summary  + "</b>\n"  +
282                                                                  '<span color="#666">' + p.description.split("\n").slice(0,3).join("\n") +
283                                                                  '</span>'
284                                                                  
285                                                                   );
286                                                             
287                                                         });
288                                                                   
289                                                                                          
290                                                     },
291                                                     reload : function() {
292                                                      
293                                                         var active_id = this.get('/project-select').el.get_active();
294                                                          
295                                                         var project_id = this.get('/project-select').raw_data[active_id].id;
296                                                         
297                                                         var _t = this;
298                                                         
299                                                         imports.Tasks.Tasks.query({
300                                                             project_id : project_id,
301                                                             'query[filter]' : 'me'
302                                                         }, function(res) { 
303                                                             print(JSON.stringify(res,null,4));
304                                                             _t.loadData(res);
305                                                         });
306                                                          
307                                                         
308                                                     }
309                                                 },
310                                                 {
311                                                     xtype: Gtk.TreeViewColumn,
312                                                     pack : "append_column",
313                                                     sizing : Gtk.TreeViewColumnSizing.FIXED,
314                                                     init : function() {
315                                                         XObject.prototype.init.call(this);
316                                                         this.el.add_attribute(this.items[0].el , 'markup', 1 );
317                                                     },
318                                                     items : [
319                                                         {
320                                                             xtype: Gtk.CellRendererText,
321                                                             pack : "pack_start"
322                                                         }
323                                                     ]
324                                                 }
325                                             ]
326                                         }
327                                     ]
328                                 }
329                             ]
330                         },
331                         {
332                             xtype: Gtk.HPaned,
333                             pack : "add",
334                             items : [
335                                 {
336                                     xtype: Gtk.VBox,
337                                     pack : "pack1,true,true",
338                                     items : [
339                                         {
340                                             xtype: Gtk.HBox,
341                                             pack : "pack_start,false,true,3",
342                                             items : [
343                                                 {
344                                                     xtype: Gtk.Label,
345                                                     label : "I am doing this:",
346                                                     pack : "pack_start,false,true,3"
347                                                 },
348                                                 {
349                                                     xtype: Gtk.Entry,
350                                                     pack : "pack_start,true,true,3"
351                                                 }
352                                             ]
353                                         },
354                                         {
355                                             xtype: Gtk.HBox,
356                                             pack : "pack_start,false,true,3",
357                                             items : [
358                                                 {
359                                                     xtype: Gtk.Label,
360                                                     label : "Since:",
361                                                     pack : "pack_start,false,true,3"
362                                                 },
363                                                 {
364                                                     xtype: Gtk.Entry,
365                                                     pack : "pack_start,false,false,3",
366                                                     width_request : 80
367                                                 },
368                                                 {
369                                                     xtype: Gtk.Label,
370                                                     label : "Until",
371                                                     pack : "pack_start,false,true,3"
372                                                 },
373                                                 {
374                                                     xtype: Gtk.Entry,
375                                                     pack : "pack_start,true,true,3"
376                                                 }
377                                             ]
378                                         },
379                                         {
380                                             xtype: Gtk.ScrolledWindow,
381                                             pack : "add",
382                                             id : "RightEditor",
383                                             items : [
384                                                 {
385                                                     xtype: Gtk.TextView,
386                                                     editable : false,
387                                                     id : "view",
388                                                     indent_width : 4,
389                                                     pack : "add",
390                                                     auto_indent : true,
391                                                     init : function() {
392                                                         XObject.prototype.init.call(this);
393                                                         var description = Pango.font_description_from_string("monospace");
394                                                     
395                                                         description.set_size(8000);
396                                                         this.el.modify_font(description);
397                                                     
398                                                     },
399                                                     load : function(str) {
400                                                     
401                                                     // show the help page for the active node..
402                                                      
403                                                     
404                                                     
405                                                      
406                                                         this.el.get_buffer().set_text(str, str.length);
407                                                      
408                                                         
409                                                          var buf = this.el.get_buffer();
410                                                          
411                                                          
412                                                         
413                                                     },
414                                                     show_line_numbers : true,
415                                                     items : [
416                                                         {
417                                                             xtype: GtkSource.Buffer,
418                                                             listeners : {
419                                                                 changed : function (self) {
420                                                                     /*
421                                                                     var s = new Gtk.TextIter();
422                                                                     var e = new Gtk.TextIter();
423                                                                     this.el.get_start_iter(s);
424                                                                     this.el.get_end_iter(e);
425                                                                     var str = this.el.get_text(s,e,true);
426                                                                     try {
427                                                                         Seed.check_syntax('var e = ' + str);
428                                                                     } catch (e) {
429                                                                         this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
430                                                                             red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
431                                                                            }));
432                                                                         //print("SYNTAX ERROR IN EDITOR");   
433                                                                         //print(e);
434                                                                         //console.dump(e);
435                                                                         return;
436                                                                     }
437                                                                     this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
438                                                                             red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
439                                                                            }));
440                                                                     
441                                                                      this.get('/LeftPanel.model').changed(  str , false);
442                                                                      */
443                                                                 }
444                                                             },
445                                                             pack : "set_buffer"
446                                                         }
447                                                     ]
448                                                 }
449                                             ]
450                                         }
451                                     ]
452                                 },
453                                 {
454                                     xtype: Gtk.VBox,
455                                     pack : "pack2,false,false",
456                                     width_request : 200,
457                                     items : [
458                                         {
459                                             xtype: Gtk.HBox,
460                                             pack : "pack_start,false,true,3",
461                                             items : [
462                                                 {
463                                                     xtype: Gtk.Button,
464                                                     listeners : {
465                                                         clicked : function (self) {
466                                                          
467                                                         }
468                                                     },
469                                                     label : "Next/Back",
470                                                     pack : "pack_end,false,true,3",
471                                                     use_stock : true
472                                                 }
473                                             ]
474                                         },
475                                         {
476                                             xtype: Gtk.ScrolledWindow,
477                                             pack : "pack_end,true,true,3",
478                                             shadow_type : Gtk.ShadowType.IN,
479                                             items : [
480                                                 {
481                                                     xtype: Gtk.TreeView,
482                                                     id : "today-view",
483                                                     pack : "add",
484                                                     can_focus : true,
485                                                     fixed_height_mode : true,
486                                                     headers_visible : false,
487                                                     init : function() {
488                                                         XObject.prototype.init.call(this);
489                                                         var description = new Pango.FontDescription.c_new();
490                                                         description.set_size(10000);
491                                                         this.el.modify_font(description);
492                                                     
493                                                         this.selection = this.el.get_selection();
494                                                         this.selection.set_mode( Gtk.SelectionMode.SINGLE);
495                                                         var _t = this;
496                                                     
497                                                         // is this really needed??
498                                                         this.selection.signal['changed'].connect(function() {
499                                                             print('selection changed');
500                                                         
501                                                     
502                                                         });
503                                                     
504                                                     },
505                                                     items : [
506                                                         {
507                                                             xtype: Gtk.ListStore,
508                                                             id : "today-store",
509                                                             pack : "set_model",
510                                                             columns : [
511                                                                     GObject.TYPE_STRING, // title 
512                                                                     GObject.TYPE_STRING, // tip
513                                                                     GObject.TYPE_STRING // source..
514                                                             ],
515                                                             init : function() {
516                                                                 XObject.prototype.init.call(this);
517                                                             
518                                                                 this.el.set_column_types ( 2, [
519                                                                     GObject.TYPE_STRING,  // real key
520                                                                     GObject.TYPE_STRING // real type
521                                                                     
522                                                                     
523                                                                 ] );
524                                                             
525                                                             
526                                                                 
527                                                                 // var t = this;
528                                                                 //imports.Projects.Projects.fetch(  function(res) { 
529                                                                 //    t.loadData(res);
530                                                                // });
531                                                                     
532                                                                                             
533                                                             },
534                                                             loadData : function (data) {
535                                                                     print("loading data");
536                                                                                                 
537                                                                 var el = this.el;
538                                                                 this.el.clear();
539                                                                 data.forEach(function(p) {
540                                                                     var ret = {};
541                                                                     el.append(ret);
542                                                                    //print("ADD " + p.name);
543                                                                      
544                                                                     el.set_value(ret.iter, 0, p.id);
545                                                                     el.set_value(ret.iter, 1,   '<b>#' + p.id + '</b>' + 
546                                                                         '[' + p.status_name + '] <b>'   + p.summary  + "</b>\n"  +
547                                                                          '<span color="#666">' + p.description.split("\n").slice(0,3).join("\n") +
548                                                                          '</span>'
549                                                                          
550                                                                           );
551                                                                     
552                                                                 });
553                                                                           
554                                                                                                  
555                                                             },
556                                                             reload : function() {
557                                                              
558                                                                 var active_id = this.get('/project-select').el.get_active();
559                                                                  
560                                                                 var project_id = this.get('/project-select').raw_data[active_id].id;
561                                                                 
562                                                                 var _t = this;
563                                                                  
564                                                                 var DT = imports.Date.Date;
565                                                                 
566                                                                 new imports.Request.Request( {
567                                                                    url : '/cash_invoice_entry',
568                                                                    params : {
569                                                                         'query[action_dt_from]' : (new DT()).format('Y-m-d'),
570                                                                          'query[action_dt_to]' : (new DT()).add(DT.DAY,1).format('Y-m-d'),
571                                                                         limit: 999,
572                                                                         'sort' : 'action_dt',
573                                                                         dir : 'ASC',
574                                                                         action : 'Hours'
575                                                                    },
576                                                                    
577                                                                    success : function(res) {
578                                                                        this.loadData();
579                                                                    },
580                                                                    scope : this
581                                                                     
582                                                                     
583                                                                 });
584                                                                  
585                                                                  
586                                                                 
587                                                             }
588                                                         },
589                                                         {
590                                                             xtype: Gtk.TreeViewColumn,
591                                                             pack : "append_column",
592                                                             sizing : Gtk.TreeViewColumnSizing.FIXED,
593                                                             init : function() {
594                                                                 XObject.prototype.init.call(this);
595                                                                 this.el.add_attribute(this.items[0].el , 'markup', 1 );
596                                                             },
597                                                             items : [
598                                                                 {
599                                                                     xtype: Gtk.CellRendererText,
600                                                                     pack : "pack_start"
601                                                                 }
602                                                             ]
603                                                         }
604                                                     ]
605                                                 }
606                                             ]
607                                         }
608                                     ]
609                                 }
610                             ]
611                         }
612                     ]
613                 }
614             ]
615         }
616     ]
617 });
618 FixBug.init();
619 XObject.cache['/FixBug'] = FixBug;