FixBug.js
[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 GtkClutter = imports.gi.GtkClutter;
11 Gdl = imports.gi.Gdl;
12 console = imports.console;
13 XObject = imports.XObject.XObject;
14 FixBug=new XObject({
15     xtype: Gtk.Dialog,
16     listeners : {
17         destroy_event : function (self, event) {
18              this.el.hide();
19                         return false;
20         },
21         response : function (self, id) {
22           // hide
23          if (id < 1) {
24                 this.el.hide();
25                 return;
26             }
27             if (!this.get('bug').getValue().length) {
28                 print("ERROR");
29                     return;
30                 }
31          
32                 this.el.hide();
33                 
34                 var val = this.get('bug').getValue();
35                 Seed.print(val);
36         }
37     },
38     border_width : 3,
39     default_height : 150,
40     default_width : 600,
41     title : "Project Properties",
42     deletable : true,
43     modal : true,
44     show : function(c) {
45         
46         if (!this.el) {
47             this.init();
48         }
49         var _this = this;
50         /*[ 'xtype'  ].forEach(function(k) {
51             _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
52         });
53         // shouild set path..
54         */
55         this.el.show_all();
56         this.success = c.success;
57     },
58     items : [
59         {
60             xtype: Gtk.VBox,
61             pack : function(p,e) {
62                         p.el.get_content_area().add(e.el)
63                     },
64             items : [
65                 {
66                     xtype: Gtk.HBox,
67                     pack : "pack_start,false,true,3",
68                     items : [
69                         {
70                             xtype: Gtk.Label,
71                             label : "Select Active Bug:",
72                             pack : "pack_start,false,true,3"
73                         },
74                         {
75                             xtype: Gtk.ComboBox,
76                             id : "bug",
77                             pack : "pack_end,true,true,3",
78                             getValue : function() {
79                                  var ix = this.el.get_active();
80                                         if (ix < 0 ) {
81                                             return '';
82                                         }
83                                         return this.get('model').data[ix].xtype;
84                             },
85                             init : function() {
86                                 XObject.prototype.init.call(this);
87                               this.el.add_attribute(this.items[0].el , 'markup', 1 );  
88                             },
89                             setValue : function(v)
90                                             {
91                                                 var el = this.el;
92                                                 el.set_active(-1);
93                                                 this.get('model').data.forEach(function(n, ix) {
94                                                     if (v == n.xtype) {
95                                                         el.set_active(ix);
96                                                         return false;
97                                                     }
98                                                 });
99                                             },
100                             items : [
101                                 {
102                                     xtype: Gtk.CellRendererText,
103                                     pack : "pack_start"
104                                 },
105                                 {
106                                     xtype: Gtk.ListStore,
107                                     id : "model",
108                                     pack : "set_model",
109                                     init : function() {
110                                         XObject.prototype.init.call(this);
111                                     
112                                             this.el.set_column_types ( 2, [
113                                                 GObject.TYPE_STRING,  // real key
114                                                 GObject.TYPE_STRING // real type
115                                                 
116                                                 
117                                             ] );
118                                             var Ticket = imports.tests.tickets.Ticket;
119                                             
120                                             var data = Tickets.fetchBugs("http://www.roojs.com/mtrack/index.php/Gitlive/web.hex");
121                                     /*        this.data = [
122                                                 { xtype: 'Roo', desc : "Roo Project" },
123                                                 { xtype: 'Gtk', desc : "Gtk Project" },    
124                                                 //{ xtype: 'JS', desc : "Javascript Class" }
125                                             ]
126                                       */      
127                                             this.loadData(this.data);
128                                                                     
129                                     },
130                                     loadData : function (data) {
131                                                                                 
132                                                 var iter = new Gtk.TreeIter();
133                                                 var el = this.el;
134                                                 data.forEach(function(p) {
135                                                     
136                                                     el.append(iter);
137                                                     
138                                                      
139                                                     el.set_value(iter, 0, p.id);
140                                                     el.set_value(iter, 1, '#' + p.id + p.name );
141                                                     
142                                                 });
143                                                   
144                                                                          
145                                     }
146                                 }
147                             ]
148                         }
149                     ]
150                 }
151             ]
152         },
153         {
154             xtype: Gtk.Button,
155             pack : "add_action_widget,1",
156             label : "OK"
157         },
158         {
159             xtype: Gtk.Button,
160             pack : "add_action_widget,0",
161             label : "Cancel"
162         }
163     ]
164 });
165 FixBug.init();
166 XObject.cache['/FixBug'] = FixBug;