Pman.Std.js
[Pman.Core] / Pman.Std.js
1 //<script type="text/javascript">
2
3 /**
4
5 * All Our standard form fields
6
7 * should move this really..
8
9 */
10
11 Pman.Std = {
12     project_id : function (cfg) {
13         cfg = cfg || {};
14         cfg.storeListeners = cfg.storeListeners || {};
15         return  Roo.apply({
16                 
17             width: 200,
18             fieldLabel: "Project",
19             name : 'project_id_code',
20             hiddenName:  'project_id',
21             
22             allowBlank : false,
23             selectOnFocus:true,
24             qtip : "Select Project",
25             
26             
27             
28             xtype: 'ComboBox',
29             
30             store: {
31                 xtype : 'Store',
32                   // load using HTTP
33                 proxy: {
34                     xtype : 'HttpProxy',
35                     url: baseURL + '/Roo/Projects.html',
36                     method: 'GET'
37                 },
38                 reader: Pman.Readers.Projects,
39                 listeners : Roo.apply(
40                     {
41                         loadexception : Pman.loadException
42                     }, 
43                     cfg.storeListeners
44                 ),
45                 remoteSort : true,
46                 sortInfo: {
47                     field: 'code', direction: 'ASC'
48                 }
49             },
50             displayField:'code',
51             valueField : 'id',
52             
53             typeAhead: true,
54             forceSelection: true,
55             //mode: 'local',
56             triggerAction: 'all',
57             tpl: new Ext.Template(
58                 '<div class="x-grid-cell-text x-btn button">',
59                     '<b>{code}</b> {name}',
60                 '</div>'
61             ),
62             queryParam: 'query[project_search]',
63             loadingText: "Searching...",
64             listWidth: 400,
65            
66             minChars: 2,
67             pageSize:20 
68              
69         }, cfg);
70    },
71    
72     
73    company_id : function(cfg) { // really picks names...
74         cfg = cfg || {};
75         cfg.storeListeners = cfg.storeListeners || {};
76         // we may want to set up cfg listners default here???
77         cfg.listeners = cfg.listeners || {};
78            
79         return Roo.apply({
80                 // things we might want to change...
81                 
82                 name : 'addressto_name',
83                 displayField:'name',
84                 
85                 fieldLabel : "Sent To",
86                 allowBlank : true,
87                 qtip : "Enter Sent To",
88                 width: 290,
89                 
90                 
91                 value : '',
92                 xtype: 'ComboBoxAdder',
93                 selectOnFocus:true,
94                 allowBlank : false,
95                 
96                
97                 store: {
98                       // load using HTTP
99                     xtype: 'Store',
100                     proxy: {
101                         xtype : 'HttpProxy',
102                         url: baseURL + '/Roo/core_company',
103                         method: 'GET'
104                     },
105                     reader: Pman.Readers.Companies,
106                     
107                     listeners : Roo.apply(
108                         {
109                             loadexception : Pman.loadException
110                         }, 
111                         cfg.storeListeners
112                     ),
113                     remoteSort : true,
114                     sortInfo: {
115                         field: 'name', direction: 'ASC'
116                     }
117                     
118                 },
119               
120                 typeAhead: true,
121                 forceSelection: true,
122                 //mode: 'local',
123                 triggerAction: 'all',
124                 tpl: new Ext.Template(
125                     '<div class="x-grid-cell-text x-btn button">',
126                         '<b>{name}</b> {address}',
127                     '</div>'
128                 ),
129                 queryParam: 'query[name]',
130                 loadingText: "Searching...",
131                 listWidth: 400,
132                
133                 minChars: 2,
134                 pageSize:20 
135                 
136             }, cfg);
137     },
138     
139     doctype_name: function(cfg) {
140         cfg = cfg || {};
141         return Roo.apply({
142                 // things that might need chnaging
143                 name : 'doctype_name',
144                 width : 290,
145                 fieldLabel : "Type",
146                 allowBlank : false,
147                 
148                 // less likely
149                 qtip : "Select Document Type",
150                 
151                 value : '',
152                 // very unlinkly
153                 xtype : 'ComboBox',   
154                 store: {
155                     // load using HTTP
156                     xtype: 'Store',
157                     proxy: {
158                         xtype: 'HttpProxy',
159                         url: baseURL + '/Roo/Document_Types.html',
160                         method: 'GET'
161                     },
162                     
163                     reader: Pman.Readers.Document_Types,
164                     listeners : {
165                         beforeload: function(t, o) {
166                             //console.log(o.params);
167                             o.params.limit = 9999;
168                         },
169                         loadexception : Pman.loadException
170                 
171                     },
172                     remoteSort: true,
173                     sortInfo: {
174                         field: 'name', direction: 'ASC'
175                     }
176                 },
177                 displayField:'name',
178                 
179                 typeAhead: false,
180                 editable: false,
181                 //mode: 'local',
182                 triggerAction: 'all',
183                 //emptyText:'Select a state...',
184                 selectOnFocus:true 
185             }, cfg);
186     },
187     
188     
189     address_list_adder : function(cfg) {
190         cfg = cfg || {};
191         cfg.storeListeners = cfg.storeListeners || {};
192         return Roo.apply({
193                 
194                 name : 'send_to',
195                 fieldLabel : "To",
196                 idField : 'email',
197                 
198                  renderer : function(d) {
199                     return String.format('{0}', 
200                         d.name.length ? d.name : d.email
201                     );
202                 },
203                 
204                 
205                 xtype: 'ComboBoxLister',
206                 displayField:'name',
207                 value : '',
208                
209                 qtip : "Select an address to add.",
210                 selectOnFocus:true,
211                 allowBlank : true,
212                 width: 150,
213                 
214                 
215                 store: {
216                     xtype : 'Store',
217                       // load using HTTP
218                     proxy: {
219                         xtype : 'HttpProxy',
220                         url: baseURL + '/Roo/Person.html',
221                         method: 'GET'
222                     },
223                     reader: Pman.Readers.Companies,
224                     listeners : cfg.storeListeners, 
225                     remoteSort : true,
226                     sortInfo: {
227                         field: 'name', direction: 'ASC'
228                     }
229                 },
230                
231                 
232                 typeAhead: true,
233                 forceSelection: true,
234                 //mode: 'local',
235                 triggerAction: 'all',
236                 tpl: new Ext.Template(
237                     '<div class="x-grid-cell-text x-btn button">',
238                         '<b>{name}</b> {email}',
239                     '</div>'
240                 ),
241                 queryParam: 'query[name]',
242                 loadingText: "Searching...",
243                 listWidth: 400,
244                
245                 minChars: 2,
246                 pageSize:20,
247                 setList : function(ar) {
248                     var _this = this;
249                     Roo.each(ar, function(a) {
250                         _this.addItem(a);
251                     });
252                 },
253                 toList : function() {
254                     var ret = [];
255                     this.items.each(function(a) {
256                         ret.push(a.data);
257                     });
258                     return ret;
259                 }
260                 
261                  
262             }, cfg);
263     },
264     
265     
266     our_office_id : function(cfg) 
267     {
268         cfg = cfg || {};
269         cfg.listeners = cfg.listeners  || {};
270         return Roo.apply({
271             xtype: 'ComboBoxAdder',
272             fieldLabel: "Office / Department",
273             
274             hiddenName:  'office_id',
275             name : 'office_id_name',
276             
277             qtip : "Select Office",
278             width: 300,
279             allowBlank : true,
280             triggerAction: 'all',
281             
282             
283             typeAhead: true,
284             forceSelection: true,
285             selectOnFocus:true,
286             
287             displayField:'name',
288             valueField : 'id',
289             
290             store:  {
291                 xtype : 'Store',
292                   // load using HTTP
293                 proxy: {
294                     xtype : 'HttpProxy',
295                     url: baseURL + '/Roo/Office.html',
296                     method: 'GET'
297                 },
298                 reader: Pman.Readers.Office,
299                 listeners : Roo.apply({
300                     loadexception : Pman.loadException
301                     }, cfg.storeListeners
302                 ),
303                 remoteSort : true,
304                 sortInfo: {
305                     field: 'name', direction: 'ASC'
306                 }
307             },
308             listeners : Roo.apply({
309                 adderclick : function()
310                 {
311                      
312                     var ncfg = {
313                         company_id : Pman.Login.authUser.company_id * 1,
314                         company_id_name:  Pman.Login.authUser.company_id_name,
315                         address: '',
316                         phone: '',
317                         fax: '',
318                         email: ''
319                     };
320
321                     
322                     Pman.Preview.tmpDisable();
323                     
324                     Pman.Dialog.Office.show(ncfg, function(data) {
325                         _this.setFromData(data);
326                         Pman.Preview.tmpEnable();
327                     }); 
328                 } 
329             }, cfg.listeners),
330            
331             //mode: 'local',
332             
333             tpl: new Ext.Template(
334                 '<div class="x-grid-cell-text x-btn button">',
335                     '<b>{name}</b> {address}',
336                 '</div>'
337             ),
338             queryParam: 'query[name]',
339             loadingText: "Searching...",
340             listWidth: 400,
341            
342             minChars: 2,
343             pageSize:20 
344              
345              
346              
347         }, cfg);
348     },
349     
350     /**
351      * Depreciated - use Pman.I18n directly
352      * 
353      */
354
355     country: function(cfg) { return Pman.I18n.country(cfg); }, 
356     language: function(cfg) { return Pman.I18n.language(cfg); }, 
357        
358     languageList : function(cfg) { return Pman.I18n.languageList(cfg); },
359     countryList : function(cfg) { return Pman.I18n.countryList(cfg); }
360      
361         
362 };