Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtupleContact.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Dialog.XtupleContact = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             closable : false,
34             collapsible : false,
35             height : 450,
36             modal : true,
37             resizable : false,
38             title : "Contact Details",
39             width : 800,
40             items : [
41                 {
42                     xtype: 'ContentPanel',
43                     xns: Roo,
44                     region : 'center',
45                     items : [
46                         {
47                             xtype: 'Form',
48                             xns: Roo.form,
49                             listeners : {
50                                 actioncomplete : function(_self,action)
51                                 {
52                                     if (action.type == 'setdata') {
53                                         if (_this.data.cntct_id) {
54                                             this.load({ method: 'GET', params: { '_id' : _this.data.cntct_id }});
55                                             return;
56                                         } 
57                                         // we need to fetch crmct id..
58                                         new Pman.Request({
59                                             method : 'GET',
60                                             url : baseURL + '/Roo/crmacct',
61                                             params : {
62                                                 crmacct_cust_id : _this.data.customer_id
63                                             },
64                                             success : function(r) {
65                                 //                Roo.log(r);
66                                                 try {
67                                                     _this.form.findField('cntct_crmacct_id').setValue(r.data[0].crmacct_id);
68                                                 } catch(e) {
69                                                     Roo.MessageBox.alert("Error", "Sorry, we failed got get some data from the server, please cancel and try again");
70                                                 }
71                                             }
72                                         });
73                                 
74                                     }
75                                     if (action.type == 'load') {
76                                         _this.form.findField('cntct_name').sync();
77                                           _this.form.findField('addr_view').sync();
78                                     
79                                         return;
80                                     }
81                                     if (action.type =='submit') {
82                                     
83                                         _this.dialog.hide();
84                                          _this.form.setValues(action.result.data);
85                                          if (_this.callback) {
86                                             _this.callback.call(_this, _this.form.getValues());
87                                          }
88                                          _this.form.reset();
89                                          return;
90                                     }
91                                 },
92                                 rendered : function (form)
93                                 {
94                                     _this.form= form;
95                                 }
96                             },
97                             method : 'POST',
98                             style : 'margin:10px;',
99                             url : baseURL + '/Roo/cntct.php',
100                             items : [
101                                 {
102                                     xtype: 'FieldSet',
103                                     xns: Roo.form,
104                                     legend : "Details",
105                                     style : 'width:750px',
106                                     items : [
107                                         {
108                                             xtype: 'Row',
109                                             xns: Roo.form,
110                                             labelAlign : 'right',
111                                             labelWidth : 70,
112                                             width : 800,
113                                             items : [
114                                                 {
115                                                     xtype: 'ComboBox',
116                                                     xns: Roo.form,
117                                                     listeners : {
118                                                         blur : function (_self)
119                                                         {
120                                                          _this.form.findField('cntct_name').sync();
121                                                         }
122                                                     },
123                                                     allowBlank : true,
124                                                     displayField : 'hnfc_code',
125                                                     editable : false,
126                                                     emptyText : "Title",
127                                                     fieldLabel : 'Name',
128                                                     hiddenName : 'cntct_honorific',
129                                                     listWidth : 400,
130                                                     loadingText : "Searching...",
131                                                     minChars : 2,
132                                                     name : 'cntct_honorific',
133                                                     qtip : "Select title",
134                                                     queryParam : 'query[addr_line1]',
135                                                     selectOnFocus : true,
136                                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{hnfc_code}</b> </div>',
137                                                     triggerAction : 'all',
138                                                     typeAhead : true,
139                                                     valueField : 'hnfc_code',
140                                                     width : 60,
141                                                     store : {
142                                                         xtype: 'Store',
143                                                         xns: Roo.data,
144                                                         sortInfo : { direction : 'ASC', field: 'addr_line1' },
145                                                         remoteSort : true,
146                                                         listeners : {
147                                                             beforeload : function (_self, o){
148                                                                 o.params = o.params || {};
149                                                                 // set more here
150                                                             }
151                                                         },
152                                                         proxy : {
153                                                             xtype: 'HttpProxy',
154                                                             xns: Roo.data,
155                                                             method : 'GET',
156                                                             url : baseURL + '/Roo/hnfc.php'
157                                                         },
158                                                         reader : {
159                                                             xtype: 'JsonReader',
160                                                             xns: Roo.data,
161                                                             id : 'hnfc_id',
162                                                             root : 'data',
163                                                             totalProperty : 'total',
164                                                             fields : [{'name':'hnfc_id','type':'int'},'hnfc_code']
165                                                         }
166                                                     }
167                                                 },
168                                                 {
169                                                     xtype: 'Row',
170                                                     xns: Roo.form,
171                                                     hideLabels : true,
172                                                     labelAlign : 'top',
173                                                     width : 700,
174                                                     items : [
175                                                         {
176                                                             xtype: 'TextField',
177                                                             xns: Roo.form,
178                                                             listeners : {
179                                                                 keyup : function (_self, e)
180                                                                 {
181                                                                        _this.form.findField('cntct_name').sync();
182                                                                 }
183                                                             },
184                                                             fieldLabel : 'first_name',
185                                                             name : 'cntct_first_name',
186                                                             qtip : "First name",
187                                                             width : 200
188                                                         },
189                                                         {
190                                                             xtype: 'TextField',
191                                                             xns: Roo.form,
192                                                             listeners : {
193                                                                 keyup : function (_self, e)
194                                                                 {
195                                                                        _this.form.findField('cntct_name').sync();
196                                                                 }
197                                                             },
198                                                             fieldLabel : 'initials',
199                                                             name : 'cntct_initials',
200                                                             qtip : "Initials",
201                                                             width : 40
202                                                         },
203                                                         {
204                                                             xtype: 'TextField',
205                                                             xns: Roo.form,
206                                                             listeners : {
207                                                                 keyup : function (_self, e)
208                                                                 {
209                                                                        _this.form.findField('cntct_name').sync();
210                                                                 }
211                                                             },
212                                                             fieldLabel : 'last_name',
213                                                             name : 'cntct_last_name',
214                                                             qtip : "Last name",
215                                                             width : 200
216                                                         }
217                                                     ]
218                                                 }
219                                             ]
220                                         },
221                                         {
222                                             xtype: 'Column',
223                                             xns: Roo.form,
224                                             labelAlign : 'right',
225                                             labelWidth : 70,
226                                             width : 900,
227                                             items : [
228                                                 {
229                                                     xtype: 'Row',
230                                                     xns: Roo.form,
231                                                     labelAlign : 'right',
232                                                     labelWidth : 70,
233                                                     width : 900,
234                                                     items : [
235                                                         {
236                                                             xtype: 'TextField',
237                                                             xns: Roo.form,
238                                                             qtip : "Job Title",
239                                                             fieldLabel : 'Job Title',
240                                                             name : 'cntct_title',
241                                                             width : 335
242                                                         },
243                                                         {
244                                                             xtype: 'TextField',
245                                                             xns: Roo.form,
246                                                             fieldLabel : 'Unique#',
247                                                             name : 'cntct_number',
248                                                             width : 100
249                                                         }
250                                                     ]
251                                                 }
252                                             ]
253                                         }
254                                     ]
255                                 },
256                                 {
257                                     xtype: 'FieldSet',
258                                     xns: Roo.form,
259                                     labelAlign : 'right',
260                                     labelWidth : 70,
261                                     legend : "Contact",
262                                     style : 'width:300px',
263                                     items : [
264                                         {
265                                             xtype: 'TextField',
266                                             xns: Roo.form,
267                                             fieldLabel : 'Phone',
268                                             name : 'cntct_phone',
269                                             width : 200
270                                         },
271                                         {
272                                             xtype: 'TextField',
273                                             xns: Roo.form,
274                                             fieldLabel : 'Mobile',
275                                             name : 'cntct_phone2',
276                                             width : 200
277                                         },
278                                         {
279                                             xtype: 'TextField',
280                                             xns: Roo.form,
281                                             fieldLabel : 'Fax',
282                                             name : 'cntct_fax',
283                                             width : 200
284                                         }
285                                     ]
286                                 },
287                                 {
288                                     xtype: 'FieldSet',
289                                     xns: Roo.form,
290                                     legend : "Online",
291                                     style : 'width:400px; margin-left:10px',
292                                     items : [
293                                         {
294                                             xtype: 'TextField',
295                                             xns: Roo.form,
296                                             fieldLabel : 'Email',
297                                             name : 'cntct_email',
298                                             vtype : 'email',
299                                             width : 250
300                                         },
301                                         {
302                                             xtype: 'TextField',
303                                             xns: Roo.form,
304                                             fieldLabel : 'Website',
305                                             name : 'cntct_webaddr',
306                                             vtype : 'url',
307                                             width : 250
308                                         }
309                                     ]
310                                 },
311                                 {
312                                     xtype: 'FieldSet',
313                                     xns: Roo.form,
314                                     hideLabels : true,
315                                     legend : "Notes",
316                                     style : 'width:300px; clear: both;',
317                                     items : [
318                                         {
319                                             xtype: 'TextArea',
320                                             xns: Roo.form,
321                                             fieldLabel : 'notes',
322                                             height : 100,
323                                             name : 'cntct_notes',
324                                             width : 290
325                                         }
326                                     ]
327                                 },
328                                 {
329                                     xtype: 'FieldSet',
330                                     xns: Roo.form,
331                                     hideLabels : true,
332                                     legend : "Address",
333                                     style : 'width:400px; margin-left:10px',
334                                     items : [
335                                         {
336                                             xtype: 'ComboBox',
337                                             xns: Roo.form,
338                                             listeners : {
339                                                 add : function (combo)
340                                                 {
341                                                    Pman.Dialog.XtupleAddress.show({
342                                                         addr_id : '',
343                                                         customer_id : _this.form.findField('customer_id').getValue()
344                                                    
345                                                    }, function(d) {
346                                                                Roo.log(d);
347                                                         if (!d) {
348                                                             return;
349                                                         }
350                                                         var s = {};
351                                                         for (var k in d) {
352                                                             s['cntct_addr_id_' + k] = d[k];
353                                                         }
354                                                 
355                                                         s.cntct_addr_id = d.addr_id;
356                                                         Roo.log(s);                
357                                                         _this.form.setValues(s);
358                                                         // if d contains a value.. use it..
359                                                         _this.form.findField('addr_view').sync();
360                                                    
361                                                    
362                                                    });
363                                                 },
364                                                 edit : function (combo, record)
365                                                 {
366                                                   Pman.Dialog.XtupleAddress.show({
367                                                         addr_id : this.getValue(),
368                                                         customer_id : _this.form.findField('customer_id').getValue()
369                                                    
370                                                    }, function(d) {
371                                                    
372                                                        // Roo.log(d);
373                                                         if (!d) {
374                                                             return;
375                                                         }
376                                                         var s = {};
377                                                         for (var k in d) {
378                                                             s['cntct_addr_id_' + k] = d[k];
379                                                         }
380                                                         s.cntct_addr_id = d.addr_id;
381                                                         Roo.log(s);
382                                                         _this.form.setValues(s);
383                                                             _this.form.findField('addr_view').sync();
384                                                         // if d contains a value.. use it..
385                                                    
386                                                    });
387                                                 },
388                                                 select : function (combo, record, index)
389                                                 {
390                                                     var s = {};
391                                                     for (var k in record.data) {
392                                                         s['cntct_addr_id_' + k] = record.data[k];
393                                                     }
394                                                 
395                                                     _this.form.setValues(s);
396                                                     _this.form.findField('addr_view').sync();
397                                                 }
398                                             },
399                                             allowBlank : false,
400                                             alwaysQuery : true,
401                                             displayField : 'addr_line1',
402                                             editable : false,
403                                             emptyText : "Select address",
404                                             fieldLabel : 'addr',
405                                             forceSelection : true,
406                                             hiddenName : 'cntct_addr_id',
407                                             listWidth : 400,
408                                             loadingText : "Searching...",
409                                             minChars : 2,
410                                             name : 'cntct_addr_id_addr_line1',
411                                             pageSize : 20,
412                                             qtip : "Select addr",
413                                             queryParam : 'query[addr_line1]',
414                                             selectOnFocus : true,
415                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>#{addr_id} - {addr_line1}</b> </div>',
416                                             triggerAction : 'all',
417                                             typeAhead : true,
418                                             valueField : 'addr_id',
419                                             width : 380,
420                                             store : {
421                                                 xtype: 'Store',
422                                                 xns: Roo.data,
423                                                 listeners : {
424                                                     beforeload : function (_self, o){
425                                                         o.params = o.params || {};
426                                                         o.params._customer_id = _this.form.findField('customer_id').getValue();
427                                                         // set more here
428                                                     }
429                                                 },
430                                                 remoteSort : true,
431                                                 sortInfo : { direction : 'ASC', field: 'addr_line1' },
432                                                 proxy : {
433                                                     xtype: 'HttpProxy',
434                                                     xns: Roo.data,
435                                                     method : 'GET',
436                                                     url : baseURL + '/Roo/addr.php'
437                                                 },
438                                                 reader : {
439                                                     xtype: 'JsonReader',
440                                                     xns: Roo.data,
441                                                     id : 'addr_id',
442                                                     root : 'data',
443                                                     totalProperty : 'total',
444                                                     fields : [{'name':'addr_id','type':'int'},'addr_line1']
445                                                 }
446                                             }
447                                         },
448                                         {
449                                             xtype: 'TextArea',
450                                             xns: Roo.form,
451                                             fieldLabel : 'notes',
452                                             height : 80,
453                                             name : 'addr_view',
454                                             width : 380,
455                                             sync : function() {
456                                                 var vals= _this.form.getFieldValues();
457                                                 var lines = [];
458                                                 if (vals.cntct_addr_id * 1 < 1) {
459                                                     this.setValue("No address set, this will cause an error");
460                                                     return;
461                                                 }
462                                                 for (var i in vals) {
463                                                     if (i.match(/^cntct_addr_id_addr/) && vals[i].length) {
464                                                         lines.push(vals[i]);
465                                                     }
466                                                 }
467                                                 this.setValue(lines.join("\n"));
468                                             }
469                                         }
470                                     ]
471                                 },
472                                 {
473                                     xtype: 'Hidden',
474                                     xns: Roo.form,
475                                     name : 'cntct_name',
476                                     readName : function() {
477                                         var ar = [ 'honorific', 'first_name', 'initials', 'last_name' ];
478                                         var out = [];
479                                         Roo.each(ar, function (n) {
480                                             var v = _this.form.findField('cntct_' + n).getValue();
481                                             if (v.trim().length) {
482                                                 out.push(v.trim());
483                                             }
484                                         });
485                                         return out.join(' ');
486                                     },
487                                     sync : function() {
488                                         var dname = this.readName();
489                                         if (!dname.length && this.getValue().length) {
490                                             _this.form.findField('cntct_first_name').setValue(this.getValue());
491                                      
492                                               
493                                         } else {
494                                         
495                                             this.setValue(dname);
496                                         }
497                                         _this.dialog.setTitle("Contact Details - " + this.getValue());
498                                         if (_this.form.findField('cntct_id').getValue() * 1 < 1) {
499                                             var cn = 'C' +    _this.form.findField('customer_id').getValue()  + '-';
500                                             _this.form.findField('cntct_number').setValue(cn + this.getValue());
501                                         }
502                                         
503                                         
504                                     }
505                                 },
506                                 {
507                                     xtype: 'Hidden',
508                                     xns: Roo.form,
509                                     name : 'cntct_addr_id_addr_line2'
510                                 },
511                                 {
512                                     xtype: 'Hidden',
513                                     xns: Roo.form,
514                                     name : 'cntct_addr_id_addr_line3'
515                                 },
516                                 {
517                                     xtype: 'Hidden',
518                                     xns: Roo.form,
519                                     name : 'cntct_addr_id_addr_city'
520                                 },
521                                 {
522                                     xtype: 'Hidden',
523                                     xns: Roo.form,
524                                     name : 'cntct_addr_id_addr_state'
525                                 },
526                                 {
527                                     xtype: 'Hidden',
528                                     xns: Roo.form,
529                                     name : 'cntct_addr_id_addr_country'
530                                 },
531                                 {
532                                     xtype: 'Hidden',
533                                     xns: Roo.form,
534                                     name : 'customer_id'
535                                 },
536                                 {
537                                     xtype: 'Hidden',
538                                     xns: Roo.form,
539                                     name : 'cntct_crmacct_id'
540                                 },
541                                 {
542                                     xtype: 'Hidden',
543                                     xns: Roo.form,
544                                     name : 'cntct_id'
545                                 }
546                             ]
547                         }
548                     ]
549                 }
550             ],
551             center : {
552                 xtype: 'LayoutRegion',
553                 xns: Roo
554             },
555             buttons : [
556                 {
557                     xtype: 'Button',
558                     xns: Roo,
559                     listeners : {
560                         click : function (_self, e)
561                         {
562                             _this.dialog.hide();
563                         }
564                     },
565                     text : "Cancel"
566                 },
567                 {
568                     xtype: 'Button',
569                     xns: Roo,
570                     listeners : {
571                         click : function (_self, e)
572                         {
573                             // do some checks?
574                              var id=    _this.form.findField('cntct_crmacct_id').getValue();
575                             if (!id) {
576                                 Roo.MessageBox.alert("Error", "Sorry, Something failed, please cancel and try re-creatating");
577                                 return;
578                             }
579                              
580                          
581                             _this.form.doAction('submit');
582                         
583                         }
584                     },
585                     text : "Save"
586                 }
587             ]
588         });
589     }
590 };