sync
[Pman.Admin] / Pman.Dialog.Groups.js
1 //<script type="text/javascript">
2
3 // generic groups edit dialog 
4
5 Pman.Dialog.Groups = {
6     dialog : false,
7     form : false,
8     id: 'Group',
9     create: function()
10     {
11         if (this.dialog) {
12             return;
13         }
14         var _this = this;
15         this.dialog = new Roo.LayoutDialog(Roo.get(document.body).createChild({tag:'div'}),  { 
16             autoCreated: true,
17             title: 'edit team',
18             modal: true,
19             width:  650,
20             height: 150,
21             shadow:true,
22             minWidth:200,
23             minHeight:150,
24             //proxyDrag: true,
25             closable: false,
26             draggable: false,
27             center: {
28                 autoScroll:false,
29                 titlebar: false,
30                // tabPosition: 'top',
31                 hideTabs: true,
32                 closeOnTab: true,
33                 alwaysShowTabs: false
34             }
35         });
36         this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);
37         this.dialog.addButton("Cancel", this.dialog.hide, this.dialog);
38        
39         this.dialog.addButton("Save", this.save, this);
40         this.layout = this.dialog.getLayout();
41         this.layout.beginUpdate();
42         
43        
44         
45         this.form = new Roo.form.Form({
46             labelWidth: 250 ,
47             listeners : {
48                 actionfailed : function(f, act) {
49                     _this.dialog.el.unmask();
50                     // error msg???
51                     
52                     Pman.standardActionFailed(f,act);
53                               
54                 },
55                 actioncomplete: function(f, act) {
56                     _this.dialog.el.unmask();
57                     //console.log('load completed'); 
58                     // error messages?????
59                     
60                    
61                     if (act.type == 'load') {
62                         
63                         _this.data = act.result.data;
64                        // _this.loaded();
65                         return;
66                     }
67                     
68                     
69                     if (act.type == 'submit') { // only submitted here if we are 
70                         _this.dialog.hide();
71                         if (_this.callback) {
72                             _this.callback.call(this, act.result.data);
73                         }
74                         return; 
75                     }
76                     // unmask?? 
77                 }
78             }
79         
80             
81             
82              
83         });
84         //?? will this work...
85         this.form.addxtype.apply(this.form,[{
86                 name : 'name',
87                 fieldLabel : "Group Name",  // should be team name for other one.!!!!!
88                 value : '',
89                 allowBlank : false,
90                 qtip : "Enter Group name",
91                 xtype : 'TextField',
92                 width : 300
93             },
94             {
95                 
96                 xtype: 'ComboBox',
97                 fieldLabel: "Leader",
98                 name : 'leader_name',
99                 selectOnFocus:true,
100                 qtip : "Select Person Who opened",
101                 allowBlank : true,
102                 width: 280,
103                 
104                 store: new Roo.data.Store({
105                       // load using HTTP
106                     proxy: new Roo.data.HttpProxy({
107                         url: baseURL + '/Roo/core_person',
108                         method: 'GET'
109                     }),
110                     reader: new Roo.data.JsonReader({}, []),
111                     listeners : {
112                         beforeload : function(st,o)
113                         {
114                             // compnay myst be set..
115                              
116                             o.params.company_id = Pman.Login.authUser.company_id * 1;
117                              
118                              
119                         }
120                     }
121                 }),
122                  
123                 
124                 displayField:'name',
125                 valueField : 'id',
126                 hiddenName:  'leader',
127                 typeAhead: true,
128                 forceSelection: true,
129                 doForce : function(){
130                     if(this.el.dom.value.length > 0){
131                         this.el.dom.value =
132                             this.lastSelectionText === undefined ? "" : this.lastSelectionText;
133                         this.applyEmptyText();
134                         if (!this.el.dom.value.length) {
135                             this.setFromData({  id: 0, name:  '----'  });
136                         }
137                     }
138                 },
139
140                 //mode: 'local',
141                 triggerAction: 'all',
142                 tpl: new Roo.Template(
143                     '<div class="x-grid-cell-text x-btn button">',
144                         '<b>{name}</b> {role}',
145                     '</div>'
146                 ),
147                 queryParam: 'query[name]',
148                 loadingText: "Searching...",
149                 listWidth: 300,
150                
151                 minChars: 2,
152                 pageSize:20 
153                  
154                  
155             },
156             
157             
158             {
159                 name : 'id',
160                 value : '',
161                 xtype : 'Hidden'
162                 
163             },{
164                 name : 'type', // 0 == Group, 1 == team..
165                 value : '',
166                 xtype : 'Hidden'
167                 
168             }
169         ]);
170         var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
171         ef.dom.style.margin = 10;
172          
173         this.form.render(ef.dom);
174
175         var vp = this.dialog.getLayout().add('center', new Roo.ContentPanel(ef, {
176             autoCreate : true,
177             //title: 'Org Details',
178             //toolbar: this.tb,
179             width: 250,
180             maxWidth: 250,
181             fitToFrame:true
182         }));
183           
184
185         
186         
187         this.layout.endUpdate();
188     },
189     _id : 0,
190     show : function(data, callback)
191     {
192         this.callback= callback;
193         this._id = data.id;
194         this.data = data;
195         this.create();
196         this.form.reset();
197         this.form.setValues(data);
198         this.dialog.show();
199         
200         this.dialog.setTitle(data.type ? "Edit Group" : "Edit Team");
201         var lw = Roo.get(this.form.findField('leader').el.dom.parentNode.parentNode.parentNode);
202         // change the label!?!!?
203         lw.setVisibilityMode(Roo.Element.DISPLAY);
204         if (this.data.type) {
205             // show the leader..
206             lw.show();
207             
208             this.form.findField('leader').setFromData({
209                 id:  this.data.leader,
210                 name : this.data.leader ? this.data.leader_name : ''
211             });
212             
213         } else {
214             // hide the leader
215             lw.hide();
216         }
217         
218         
219         
220
221     },
222     save : function()
223     {
224          this.form.doAction('submit', {
225             url: baseURL + '/Roo/core_group.php',
226             method: 'POST',
227             params: {
228                 _id: this._id ,
229                 ts : Math.random()
230             } 
231         });
232     }
233      
234          
235 };