init
[Pman.Core] / Pman.Dialog.Projects.js
1 //<script type="text/javascript">
2   
3 Pman.Dialog.Projects = {
4     dialog : false,
5     form : false,
6     create: function()
7     {
8         if (this.dialog) {
9             return;
10         }
11         
12         this.dialog = new Ext.LayoutDialog(Ext.get(document.body).createChild({tag:'div'}),  { 
13             autoCreated: true,
14             title: "Edit Project",
15             modal: true,
16             width:  450,
17             height: 450,
18             shadow:true,
19             minWidth:200,
20             minHeight:180,
21             //proxyDrag: true,
22             closable: false,
23             draggable: false,
24             center: {
25                 autoScroll:false,
26                 titlebar: false,
27                // tabPosition: 'top',
28                 hideTabs: true,
29                 closeOnTab: true,
30                 alwaysShowTabs: false
31             }
32         });
33         this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);
34         this.dialog.addButton("Cancel", this.dialog.hide, this.dialog);
35        
36         this.dialog.addButton("Save", this.save, this);
37         this.layout = this.dialog.getLayout();
38         this.layout.beginUpdate();
39         
40         var dg = Pman.Dialog.Projects;
41         
42         this.form = new Ext.form.Form({
43             labelWidth: 100 ,
44             listeners : {
45                 actionfailed : function(f, act) {
46                     dg.dialog.el.unmask();
47                     // error msg???
48                     Pman.standardActionFailed(f,act);
49                               
50                 },
51                 actioncomplete: function(f, act) {
52                     dg.dialog.el.unmask();
53                     //console.log('load completed'); 
54                     // error messages?????
55                     
56                    
57                     if (act.type == 'load') {
58                         
59                         dg.data = act.result.data;
60                        // dg.loaded();
61                         return;
62                     }
63                     
64                     
65                     if (act.type == 'submit') { // only submitted here if we are 
66                         dg.dialog.hide();
67                         if (dg.callback) {
68                             dg.callback.call(this, act.result.data);
69                         }
70                         return; 
71                     }
72                     // unmask?? 
73                 }
74             }
75         
76             
77             
78              
79         });
80         //?? will this work...
81         this.form.addxtype.apply(this.form,[
82             
83             {
84                 name : 'code',
85                 fieldLabel : "Code",
86                 value : '',
87                 allowBlank : false,
88                 qtip : "Enter Project Code",
89                 xtype : 'TextField',
90                 width : 100
91             },
92             {
93                 name : 'name',
94                 fieldLabel : "Project Name",
95                 value : '',
96                 allowBlank : true,
97                 qtip : "Enter Project Name",
98                 xtype : 'TextField',
99                 width : 300
100             },
101             {
102                 
103                 xtype: 'ComboBox',
104                 name : 'type_desc',
105                 selectOnFocus:true,
106                 qtip : "Project type",
107                 fieldLabel : "Project type",
108
109                 allowBlank : false,
110                 width: 200,
111                 
112                 
113                 store: new Ext.data.SimpleStore({
114                       // load using HTTP
115                     fields: [ 'code', 'desc' ],
116                     data: Pman.Tab.ProjectsMgr.getTypes()
117                 }),
118                 displayField:'desc',
119                 editable : false,
120                 valueField : 'code',
121                 hiddenName:  'type',
122                 typeAhead: true,
123                 forceSelection: true,
124                 mode: 'local',
125                 triggerAction: 'all' 
126                // queryParam: 'query[project]',
127                // loadingText: "Searching...",
128                 //listWidth: 400
129                
130                  
131                
132             },
133              // CLIENT picklist.
134              {
135                 
136                 xtype: 'ComboBoxAdder',
137                 fieldLabel: "Client",
138                 name : 'client_id_name',
139                 selectOnFocus:true,
140                 qtip : "Select Client",
141                 allowBlank : true,
142                 width: 277,
143                 
144                 store: new Ext.data.Store({
145                       // load using HTTP
146                     proxy: new Ext.data.HttpProxy({
147                         url: baseURL + '/Roo/Companies.html',
148                         method: 'GET'
149                     }),
150                     reader: Pman.Readers.Companies,
151                     listeners : {
152                         loadexception : Pman.loadException
153                     }
154                 }),
155                 displayField:'name',
156                 valueField : 'id',
157                 hiddenName:  'client_id',
158                 typeAhead: true,
159                 forceSelection: true,
160                 //mode: 'local',
161                 triggerAction: 'all',
162                 tpl: new Ext.Template(
163                     '<div class="x-grid-cell-text x-btn button">',
164                         '<b>{name}</b> {address}',
165                     '</div>'
166                 ),
167                 queryParam: 'query[name]',
168                 loadingText: "Searching...",
169                 listWidth: 400,
170                
171                 minChars: 2,
172                 pageSize:20,
173                  
174                 listeners : {
175                     adderclick : function()
176                     {
177                         var cb = this;
178                         Pman.Dialog.Companies.show( {  id: 0 },  function(data) {
179                             cb.setFromData(data);
180                         }); 
181                     },
182                     blur : function(f) {
183                         if (!f.el.getValue().length) {
184                             this.setFromData({
185                                 id: 0,
186                                 name : ""
187                             });
188                         }
189                     }
190                 }
191
192                   
193             },
194               // TEAM: picklist
195             {
196                 
197                 xtype: 'ComboBox',
198                 fieldLabel: "Team",
199                 name : 'team_id_name',
200                 selectOnFocus:true,
201                 qtip : "Select Team",
202                 allowBlank : true,
203                 width: 300,
204                 
205                 store: new Ext.data.Store({
206                       // load using HTTP
207                     proxy: new Ext.data.HttpProxy({
208                         url: baseURL + '/Roo/Groups.html',
209                         method: 'GET'
210                         
211                     }),
212                     reader: Pman.Readers.Groups,
213                     listeners : {
214                         beforeload: function(g, o) {
215                             o.params = o.params ? o.params : {};
216                             o.params.type = 1;
217                             o.params['query[group_pulldown]'] = 1;
218                             
219                         },
220                         loadexception : Pman.loadException
221                     
222                     }
223                 }),
224                 displayField:'name',
225                 valueField : 'id',
226                 hiddenName:  'team_id',
227                 typeAhead: true,
228                 forceSelection: true,
229                 //mode: 'local',
230                 triggerAction: 'all' ,
231                 queryParam: 'query[name]',
232                 loadingText: "Searching...",
233                 //listWidth: 400,
234                
235                 minChars: 2,
236                // pageSize:20,
237                 
238                 listeners : {
239                     blur : function(f) {
240                         if (!f.el.getValue().length) {
241                             this.setFromData({
242                                 id: 0,
243                                 name : ""
244                             });
245                         }
246                     }
247                 }
248                 
249                   
250             },
251          
252             // Office (is related to team leader?!?)
253             
254             // Files stored:
255             
256             {
257                 name : 'file_location',
258                 fieldLabel : "File Location",
259                 value : '',
260                 qtip : "Where are the files stored?",
261                 allowBlank : true,
262                 xtype : 'TextField',
263                 width : 300
264             },
265             
266             // things to go in..
267             // Location (Files)
268             // Client? - pick from contacts..
269             // team? 
270             // team leaders???
271             // office in charge..
272             // email list????? == oru project list..
273             
274             
275             
276          
277             
278             
279             {
280                 name : 'remarks',
281                 fieldLabel : "Remarks",
282                 value : '',
283                 allowBlank : true,
284                 qtip : "Enter Project Remarks",
285                 xtype : 'TextArea',
286                 width : 300,
287                 height : 100
288             },
289                  // opened by?
290             // opened date.. 
291             {
292                 xtype : 'FieldSet',
293                 legend: 'Opened',
294                 style: 'width:393px;padding:0 0 2 10;',
295                 items : [
296                     {
297                         name : 'open_date',
298                         fieldLabel : "Date",
299                         value : '',
300                         allowBlank : true,
301                         qtip : "Enter Date Opened",
302                         xtype : 'DateField',
303                         altFormats : 'Y-m-d|d/m/Y',
304                         width : 100,
305                         format: 'd/m/Y'
306                     },
307                     
308                     
309                       
310                     {
311                         
312                         xtype: 'ComboBox',
313                         fieldLabel: "By",
314                         name : 'open_by_name',
315                         selectOnFocus:true,
316                         qtip : "Select Person Who opened",
317                         allowBlank : true,
318                         width: 250,
319                         
320                         store: new Ext.data.Store({
321                               // load using HTTP
322                             proxy: new Ext.data.HttpProxy({
323                                 url: baseURL + '/Roo/Person.html',
324                                 method: 'GET'
325                             }),
326                             reader: Pman.Readers.Person,
327                             listeners : {
328                                 beforeload : function(st,o)
329                                 {
330                                     // compnay myst be set..
331                                      
332                                     o.params.company_id = Pman.Login.authUser.company_id * 1;
333                                      
334                                      
335                                 },
336                                 loadexception : Pman.loadException
337                             
338                             }
339                         }),
340                          
341                         
342                         displayField:'name',
343                         valueField : 'id',
344                         hiddenName:  'open_by',
345                         typeAhead: true,
346                         forceSelection: true,
347                         doForce : function(){
348                             if(this.el.dom.value.length > 0){
349                                 this.el.dom.value =
350                                     this.lastSelectionText === undefined ? "" : this.lastSelectionText;
351                                 this.applyEmptyText();
352                                 if (!this.el.dom.value.length) {
353                                     this.setFromData({  id: 0, name:  '----'  });
354                                 }
355                             }
356                         },
357
358                         //mode: 'local',
359                         triggerAction: 'all',
360                         tpl: new Ext.Template(
361                             '<div class="x-grid-cell-text x-btn button">',
362                                 '<b>{name}</b> {role}',
363                             '</div>'
364                         ),
365                         queryParam: 'query[name]',
366                         loadingText: "Searching...",
367                         listWidth: 300,
368                        
369                         minChars: 2,
370                         pageSize:20 
371                          
372                     }
373                 ]
374                  
375             },
376             {
377                 name : 'id',
378                 value : '',
379                 xtype : 'Hidden'
380                 
381             }
382         ]);
383         var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
384         ef.dom.style.margin = 10;
385          
386         this.form.render(ef.dom);
387
388         var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
389             autoCreate : true,
390             //title: 'Org Details',
391             //toolbar: this.tb,
392             width: 250,
393             maxWidth: 250,
394             fitToFrame:true
395         }));
396           
397
398         
399         
400         this.layout.endUpdate();
401     },
402     _id : 0,
403     show : function(data, callback)
404     {
405         this.callback= callback;
406         this._id = data.id;
407         this.data = data;
408         this.create();
409         this.form.reset();
410         this.form.setValues(data);
411         if (data.id) {
412              
413             this.form.findField('client_id').setFromData({
414                 id: data.client_id,
415                 name: data.client_id_name
416             });
417             this.form.findField('team_id').setFromData({
418                 id: data.team_id,
419                 name: data.team_id_name
420             });
421             this.form.findField('open_by').setFromData({
422                 id: data.open_by,
423                 name: data.open_by_name
424             });
425         }
426         this.dialog.show();
427         
428
429     },
430     save : function()
431     {
432          this.form.doAction('submit', {
433             url: baseURL + '/Roo/Projects.html',
434             method: 'POST',
435             params: {
436                 _id: this._id ,
437                 ts : Math.random()
438             } 
439         });
440     }
441     
442     
443     
444     
445          
446 };