Pman.Dialog.CorePersonContact.js
[Pman.Core] / Pman.Dialog.CorePersonContact.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.CorePersonContact = {
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 : 350,
36             resizable : false,
37             title : "Edit / Create Contact Details",
38             width : 500,
39             items : [
40                 {
41                     xtype: 'ContentPanel',
42                     xns: Roo,
43                     region : 'center',
44                     items : [
45                         {
46                             xtype: 'Form',
47                             xns: Roo.form,
48                             listeners : {
49                                 actioncomplete : function(_self,action)
50                                 {
51                                     if (action.type == 'setdata') {
52                                        //_this.dialog.el.mask("Loading");
53                                        //this.load({ method: 'GET', params: { '_id' : _this.data.id }});
54                                        return;
55                                     }
56                                     if (action.type == 'load') {
57                                         _this.dialog.el.unmask();
58                                         return;
59                                     }
60                                     if (action.type =='submit') {
61                                     
62                                         _this.dialog.el.unmask();
63                                         _this.dialog.hide();
64                                     
65                                          if (_this.callback) {
66                                             _this.callback.call(_this, _this.form.getValues());
67                                          }
68                                          _this.form.reset();
69                                          return;
70                                     }
71                                 },
72                                 rendered : function (form)
73                                 {
74                                     _this.form= form;
75                                 }
76                             },
77                             method : 'POST',
78                             style : 'margin:10px;',
79                             url : baseURL + '/Roo/Person.php',
80                             items : [
81                                 {
82                                     xtype: 'ComboBox',
83                                     xns: Roo.form,
84                                     listeners : {
85                                         add : function (combo)
86                                         {
87                                         
88                                             Pman.Dialog.Companies.show( {  id: 0 },  function(data) {
89                                                     _this.form.setValues({
90                                                             company_id_name : data.name,
91                                                             company_id : data.id
92                                                     });
93                                             }); 
94                                         }
95                                     },
96                                     allowBlank : 'false',
97                                     displayField : 'code',
98                                     editable : 'false',
99                                     emptyText : "Select Companies",
100                                     fieldLabel : 'Company',
101                                     forceSelection : true,
102                                     hiddenName : 'company_id',
103                                     listWidth : 400,
104                                     loadingText : "Searching...",
105                                     minChars : 2,
106                                     name : 'company_id_code',
107                                     pageSize : 20,
108                                     qtip : "Select Companies",
109                                     queryParam : 'query[code]',
110                                     selectOnFocus : true,
111                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{code}</b> </div>',
112                                     triggerAction : 'all',
113                                     typeAhead : true,
114                                     valueField : 'id',
115                                     width : 300,
116                                     store : {
117                                         xtype: 'Store',
118                                         xns: Roo.data,
119                                         remoteSort : true,
120                                         sortInfo : { direction : 'ASC', field: 'id' },
121                                         listeners : {
122                                             beforeload : function (_self, o){
123                                                 o.params = o.params || {};
124                                                 // set more here
125                                             }
126                                         },
127                                         proxy : {
128                                             xtype: 'HttpProxy',
129                                             xns: Roo.data,
130                                             method : 'GET',
131                                             url : baseURL + '/Roo/Companies.php'
132                                         },
133                                         reader : {
134                                             xtype: 'JsonReader',
135                                             xns: Roo.data,
136                                             id : 'id',
137                                             root : 'data',
138                                             totalProperty : 'total',
139                                             fields : [{"name":"id","type":"int"},{"name":"code","type":"string"}]
140                                         }
141                                     }
142                                 },
143                                 {
144                                     xtype: 'ComboBox',
145                                     xns: Roo.form,
146                                     listeners : {
147                                         add : function (combo)
148                                         {
149                                             var coid = _this.form.findField('company_id').getValue();
150                                             if (!coid ) {
151                                             
152                                                  Ext.MessageBox.alert("Error", "Select An Company First");
153                                                 return false;
154                                         
155                                             }
156                                             Pman.Dialog.Office.show(cfg, function(data) {
157                                                         _this.form.setValues({
158                                                             office_id_name : data.name,
159                                                             office_id : data.id
160                                                     });
161                                                 }); 
162                                             
163                                             
164                                         },
165                                         beforequery : function (combo, query, forceAll, cancel, e)
166                                         {
167                                         
168                                         }
169                                     },
170                                     allowBlank : 'false',
171                                     displayField : 'name',
172                                     editable : 'false',
173                                     emptyText : "Select Office",
174                                     fieldLabel : 'Office',
175                                     forceSelection : true,
176                                     hiddenName : 'office_id',
177                                     listWidth : 400,
178                                     loadingText : "Searching...",
179                                     minChars : 2,
180                                     name : 'office_id_name',
181                                     pageSize : 20,
182                                     qtip : "Select Office",
183                                     queryParam : 'query[name]',
184                                     selectOnFocus : true,
185                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
186                                     triggerAction : 'all',
187                                     typeAhead : true,
188                                     valueField : 'id',
189                                     width : 300,
190                                     store : {
191                                         xtype: 'Store',
192                                         xns: Roo.data,
193                                         listeners : {
194                                             beforeload : function (_self, o){
195                                                 o.params = o.params || {};
196                                                 var coid = _this.form.findField('company_id').getValue();
197                                                 o.params.company_id = coid;
198                                             }
199                                         },
200                                         remoteSort : true,
201                                         sortInfo : { direction : 'ASC', field: 'id' },
202                                         proxy : {
203                                             xtype: 'HttpProxy',
204                                             xns: Roo.data,
205                                             method : 'GET',
206                                             url : baseURL + '/Roo/Office.php'
207                                         },
208                                         reader : {
209                                             xtype: 'JsonReader',
210                                             xns: Roo.data,
211                                             id : 'id',
212                                             root : 'data',
213                                             totalProperty : 'total',
214                                             fields : [{"name":"id","type":"int"},{"name":"name","type":"string"}]
215                                         }
216                                     }
217                                 },
218                                 {
219                                     xtype: 'TextField',
220                                     xns: Roo.form,
221                                     fieldLabel : 'Name',
222                                     name : 'name',
223                                     width : 300
224                                 },
225                                 {
226                                     xtype: 'TextField',
227                                     xns: Roo.form,
228                                     fieldLabel : 'Role',
229                                     name : 'role',
230                                     width : 200
231                                 },
232                                 {
233                                     xtype: 'TextField',
234                                     xns: Roo.form,
235                                     fieldLabel : 'Phone',
236                                     name : 'phone',
237                                     width : 200
238                                 },
239                                 {
240                                     xtype: 'TextField',
241                                     xns: Roo.form,
242                                     fieldLabel : 'Fax',
243                                     name : 'fax',
244                                     width : 200
245                                 },
246                                 {
247                                     xtype: 'TextField',
248                                     xns: Roo.form,
249                                     fieldLabel : 'Email',
250                                     name : 'email',
251                                     width : 200
252                                 },
253                                 {
254                                     xtype: 'Hidden',
255                                     xns: Roo.form,
256                                     name : 'id'
257                                 }
258                             ]
259                         }
260                     ]
261                 }
262             ],
263             center : {
264                 xtype: 'LayoutRegion',
265                 xns: Roo
266             },
267             buttons : [
268                 {
269                     xtype: 'Button',
270                     xns: Roo,
271                     listeners : {
272                         click : function (_self, e)
273                         {
274                             _this.dialog.hide();
275                         }
276                     },
277                     text : "Cancel"
278                 },
279                 {
280                     xtype: 'Button',
281                     xns: Roo,
282                     listeners : {
283                         click : function (_self, e)
284                         {
285                             // do some checks?
286                              
287                             
288                             _this.dialog.el.mask("Saving");
289                             _this.form.doAction("submit");
290                         
291                         }
292                     },
293                     text : "Save"
294                 }
295             ]
296         });
297     }
298 };