Pman.js
[Pman.Core] / Pman.Dialog.Office.js
1 //<script type="text/javascript">
2
3   
4 Pman.Dialog.Office = {
5     dialog : false,
6     form : false,
7     create: function()
8     {
9         if (this.dialog) {
10             return;
11         }
12         
13         this.dialog = new Ext.LayoutDialog(Ext.get(document.body).createChild({tag:'div'}),  { 
14             autoCreated: true,
15             title: "Edit Office / Department / Sub Company",
16             modal: true,
17             width:  650,
18             height: 400,
19             shadow:true,
20             minWidth:200,
21             minHeight:180,
22             //proxyDrag: true,
23             closable: false,
24             draggable: false,
25             center: {
26                 autoScroll:false,
27                 titlebar: false,
28                // tabPosition: 'top',
29                 hideTabs: true,
30                 closeOnTab: true,
31                 alwaysShowTabs: false
32             }
33         });
34         this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);
35         this.dialog.addButton("Cancel", this.dialog.hide, this.dialog);
36        
37         this.dialog.addButton("Save", this.save, this);
38         this.layout = this.dialog.getLayout();
39         this.layout.beginUpdate();
40         
41         var dg = Pman.Dialog.Office;
42         
43         this.form = new Ext.form.Form({
44             labelWidth: 250 ,
45             listeners : {
46                 actionfailed : function(f, act) {
47                     dg.dialog.el.unmask();
48                     // error msg???
49                     
50                     Pman.standardActionFailed(f,act);
51                               
52                 },
53                 actioncomplete: function(f, act) {
54                     dg.dialog.el.unmask();
55                     //console.log('load completed'); 
56                     // error messages?????
57                     
58                    
59                     if (act.type == 'load') {
60                         
61                         dg.data = act.result.data;
62                        // dg.loaded();
63                         return;
64                     }
65                     
66                     
67                     if (act.type == 'submit') { // only submitted here if we are 
68                         dg.dialog.hide();
69                         if (dg.callback) {
70                             dg.callback.call(this, act.result.data);
71                         }
72                         return; 
73                     }
74                     // unmask?? 
75                 }
76             }
77         
78             
79             
80              
81         });
82         //?? will this work...
83         this.form.addxtype.apply(this.form,[{
84                 'name' : 'id',
85                 'value' : '',
86                 'xtype' : 'Hidden'
87                 
88             },{
89                 'name' : 'company_id',
90               
91                 'value' : '',
92                 'xtype' : 'Hidden'
93             },{
94                 'name' : 'company_id_name',
95                 'fieldLabel' : "Company",
96                 'value' : '',
97                 'xtype' : 'TextField',
98                 readOnly : true,
99                 
100                 'width' : 300
101             },
102             {
103                 'name' : 'name',
104                 'fieldLabel' : "Office / Department / Sub Comp. Name",
105                 'value' : '',
106                 'allowBlank' : false,
107                 'qtip' : "Enter name",
108                 'xtype' : 'TextField',
109                 'width' : 300
110             },{
111                 'name' : 'address',
112                 'fieldLabel' : "Address",
113                 'value' : '',
114                  
115                 'qtip' : "Enter address",
116                 'xtype' : 'TextArea',
117                 'height' : 100,
118                 'width' : 300
119             },{
120                 'name' : 'phone',
121                 'fieldLabel' : "Phone",
122                 'value' : '',
123                 
124                 'qtip' : "Enter phone",
125                 'xtype' : 'TextField',
126                 'width' : 300
127             },{
128                 'name' : 'fax',
129                 'fieldLabel' : "fax",
130                 'value' : '',
131                 
132                 'qtip' : "Enter fax",
133                 'xtype' : 'TextField',
134                 'width' : 300
135             },{
136                 'name' : 'email',
137                 'fieldLabel' : "Email",
138                 'value' : '',
139              
140                 'qtip' : "Enter email",
141                 'xtype' : 'TextField',
142                 'width' : 300
143             }
144         ]);
145         var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
146         ef.dom.style.margin = 10;
147          
148         this.form.render(ef.dom);
149
150         var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
151             autoCreate : true,
152             //title: 'Org Details',
153             //toolbar: this.tb,
154             width: 250,
155             maxWidth: 250,
156             fitToFrame:true
157         }));
158           
159
160         
161         
162         this.layout.endUpdate();
163     },
164     _id : 0,
165     show : function(data, callback)
166     {
167         this.callback= callback;
168         this._id = data.id;
169         this.create();
170         this.form.reset();
171         
172         
173         this.form.setValues(data);
174         this.dialog.show();
175         this.form.findField('name').focus();
176         
177
178     },
179     save : function()
180     {
181          this.form.doAction('submit', {
182             url: baseURL + '/Roo/Office.html',
183             method: 'POST',
184             params: {
185                 _id: this._id ,
186                 ts : Math.random()
187             } 
188         });
189     } 
190     
191     
192          
193 };