1 //<script type="text/javascript">
5 * generic person list - used by perms. and staff lists.
11 Pman.Tab.PersonList = function(config)
13 Roo.apply(this, config);
16 Pman.Tab.PersonList.prototype = {
18 //--- things that should be set!!!!
19 id : '', // should be set to something!
20 type : 0, // means!! = 0 = Groups (perms) 1= teams - loose grouping..
22 hiddenColumns: false, // lsit of cols to hide..
23 itemDisplayName : false, /// eg "Staff Employees / Contacts etc."
24 permName : 'Core.Person', // or 'Core.Staff'
25 getLeftSelections : function() { return []; },
28 // beforeload handler... -- override on extended versions..
29 beforeload: function(t, o) {
30 //console.log(o.params);
32 alert('person list not configured');
34 var tms = _this.getLeftSelections();
37 o.params['query[in_group]'] = tms[0].data.id;
39 o.params['query[name]'] = this.searchBox.getValue();
40 o.params['query[type]'] = this.type; // group type..
41 o.params['query[person_internal_only_all]'] = 1;
42 o.params['query[person_inactive]'] = this.showInActive ? 0 : 1;
48 alert('person list not configured');
52 this.c_office_id_name(),
62 alert('person list not configured');
64 return Pman.Dialog.PersonStaff;
66 bulkAdd : function() {
67 //return Pman.Dialog.PersonBulkAdd
70 newDefaults : function() {
71 alert('person list not configured');
76 company_id : Pman.Login.authUser.company_id,
77 company_id_name : Pman.Login.authUser.company_id_name,
78 company_id_address : Pman.Login.authUser.company_id_address,
79 company_id_tel : Pman.Login.authUser.company_id_tel,
80 company_id_fax : Pman.Login.authUser.company_id_fax
86 /// --- end extendable bits...
90 showInActive : 0, // toggle var for hiding and showing active staff..
98 refreshWestPanel : function() /// used wher???
100 var actpan = this.parentLayout.getRegion('west').getActivePanel();
101 if (actpan && actpan.controller) {
102 actpan.controller.paging.onClick('refresh');
107 if (!actpan || !actpan.id) {
110 Pman.Tab[actpan.id].refresh();
115 this.delayedCreate();
117 this.paging.onClick('refresh');
120 loadFirst: function(){
122 this.delayedCreate();
124 this.paging.onClick('first');
129 add : function(parentLayout, region) {
133 parentLayout.getRegion(region).showPanel(this.panel);
136 this.parentLayout = parentLayout;
138 this.layout = new Roo.BorderLayout(
139 parentLayout.getEl().createChild({tag:'div'}),
151 this.tab = parentLayout.add(region, new Roo.NestedLayoutPanel(
152 this.layout, {title: this.title, background: true, controller : this}));
154 this.tab.on('activate', function() {
155 _this.delayedCreate();
156 // _this.paging.onClick('refresh');
159 delayedCreate : function ()
167 var refreshPager = function() {
170 this.layout.beginUpdate();
172 var frm = this.layout.getRegion('center').getEl().createChild({tag:'div'});
173 //this.grid = new Roo.grid.EditorGrid(frm, {
174 this.grid = new Roo.grid.Grid(frm, {
178 id: this.id + '-grid',
179 ds: new Roo.data.Store({
181 proxy: new Roo.data.HttpProxy({
182 url: baseURL + '/Roo/Person.html',
185 reader: Pman.Readers.Person,
189 beforeload: function(t, o) {
190 //console.log(o.params);
192 return _this.beforeload(t,o);
196 loadexception : Pman.loadException,
197 update : function (_self, record, operation)
199 if (operation != 'commit') {
202 // only used to change active status.
205 url : baseURL + '/Roo/Person.php',
209 active: record.data.active
212 success : function() {
217 Roo.MessageBox.alert("Error", "saving failed", function() {
218 _this.grid.footer.onClick('first');
229 field: 'name', direction: 'ASC'
232 cm: new Roo.grid.ColumnModel(
235 autoExpandColumn: _this.id + '-name' , // fixme!!!!
241 rowdblclick : function(g, ri, e) {
242 var s = g.getDataSource().getAt(ri).data;
243 if (_this.dialog() && Pman.hasPerm(_this.permName, 'E')) {
244 _this.dialog().show(s,refreshPager);
249 cellclick : function (_self, rowIndex, columnIndex, e)
251 var di = this.colModel.getDataIndex(columnIndex);
252 if (di != 'active') {
256 var rec = _this.grid.ds.getAt(rowIndex);
258 rec.set('active', rec.data.active ? 0 : 1);
269 this.panel = this.layout.add('center', new Roo.GridPanel(this.grid , {
273 title: this.title || "Staff",
279 if (this.hiddenColumns) {
280 var cm = this.grid.getColumnModel();
281 Roo.each(this.hiddenColumns, function(c) {
282 cm.setHidden(cm.getIndexByDataIndex(c), true);
288 var gridFoot = this.grid.getView().getFooterPanel(true);
289 this.paging = new Roo.PagingToolbar(gridFoot, this.grid.getDataSource(), {
292 displayMsg: "Displaying " + (this.itemDisplayName || "Staff") + " {0} - {1} of {2}",
293 emptyMsg: "No " + (this.itemDisplayName || "Staff") + " found"
295 var grid = this.grid;
298 this.toolbar = new Roo.Toolbar(this.grid.getView().getHeaderPanel(true));
300 var tb = this.toolbar;
303 if (this.parentLayout.getRegion('west') && this.parentLayout.getRegion('west').panels.length) {
306 '<b><i><font color="red">'+
308 "Drag person to add or remove from group" :
309 "Drag person to add or remove from team"
316 //if (this.permName == 'Core.Staff') {
318 this.paging.add( '-',
320 text: "Show old staff",
323 toggleHandler: function(btn,pressed) {
324 _this.showInActive = (pressed ? 1 : 0);
325 btn.setText(pressed ? "Hide old staff": "Show old staff" );
336 this.searchBox = new Roo.form.TextField({
340 specialkey : function(f,e)
343 if (e.getKey() == 13) {
353 var dg = _this.dialog();
357 cls: 'x-btn-text-icon',
358 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
359 hidden : !dg || (_this.newDefaults() === false) || !Pman.hasPerm(this.permName, 'A'),
360 handler : function(){
361 dg.show( _this.newDefaults(), refreshPager );
364 { ///... for contacts stuff...
366 cls: 'x-btn-text-icon',
367 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
368 hidden : !this.bulkAdd() || !Pman.hasPerm(this.permName, 'A'),
369 handler : function(){
371 // Pman.Dialog.PersonBulkAdd.show( { id : 0 }, refreshPager );
372 _this.bulkAdd().show( { id : 0 }, refreshPager );
378 cls: 'x-btn-text-icon',
379 icon: Roo.rootURL + 'images/default/tree/leaf.gif',
380 hidden : !dg || !Pman.hasPerm(this.permName, 'E'),
381 handler : function(){
382 var s = grid.getSelectionModel().getSelections();
383 if (!s.length || (s.length > 1)) {
384 Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
387 dg.show( s[0].data,refreshPager);
391 text: "Toogle Active",
392 cls: 'x-btn-text-icon',
393 icon: rootURL + '/Pman/templates/images/trash.gif',
394 hidden : (this.permName != 'Core.Staff') || !Pman.hasPerm(this.permName, 'E'), // SPECIFIC TO STAFF!!!!!!
395 handler : function(){
397 var s = grid.getSelectionModel().getSelections();
399 Roo.MessageBox.alert("Error", "Select People Row");
403 for(var i = 0; i < s.length; i++) {
404 r.push(s[i].data.id);
409 grid.getView().mainWrap.mask("Sending");
413 url: baseURL + '/Roo/Person.html',
416 _toggleActive : r.join(',')
418 success: function(resp) {
419 var res = Pman.processResponse(resp);
420 grid.getView().mainWrap.unmask();
422 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
428 failure: function(act) {
429 grid.getView().mainWrap.unmask();
430 Roo.MessageBox.alert("Error", "Error Sending");
440 cls: 'x-btn-text-icon',
441 hidden : !Pman.hasPerm(_this.permName, 'D'),
442 icon: rootURL + '/Pman/templates/images/trash.gif',
443 handler : function(){
444 Pman.genericDelete(_this, 'Person');
457 icon: rootURL + '/Pman/templates/images/search.gif', // icons can also be specified inline
460 handler : function () {
461 _this.grid.getSelectionModel().clearSelections();
469 icon: rootURL + '/Pman/templates/images/edit-clear.gif', // icons can also be specified inline
471 qtip: "Reset Search",
472 handler : function () {
473 _this.searchBox.setValue('');
474 _this.grid.getSelectionModel().clearSelections();
484 text: "Switch to Selected User",
485 hidden : _this.permName != 'Core.Staff' || !Pman.hasPerm('Core.Staff', 'E'),
487 click : function () {
488 var s = grid.getSelectionModel().getSelections();
490 Roo.MessageBox.alert("Error", "Select a Person");
494 url : baseURL+ '/Login.php',
496 'switch' : s[0].data.id
500 success : function() {
501 document.location = baseURL + '?ts=' + Math.random();
504 failure : function() {
521 // add stuff to toolbar?
522 //this.innerLayout.endUpdate();
523 this.layout.endUpdate();
529 show: function (parentLayout, region)
531 this.add(parentLayout, region);
532 this.grid.getDataSource().load({
542 c_project_id_code : function(cfg) {
546 dataIndex : 'project_id_code',
549 renderer : function(v,x,r) {
550 return String.format('<span qtip="{0}">{1}</span>',
560 c_name : function(cfg) {
563 id : this.id + '-name',
570 c_company_id_comptype : function(cfg) {
573 header : "Company Type",
574 dataIndex : 'company_id_comptype',
580 c_company_id_name : function(cfg) {
583 header : "Company / Office",
584 dataIndex : 'company_id_name',
587 renderer: function(v,x,r) {
588 return String.format('{0}{1}{2}',
590 r.data.office_id ? ' / ' : '',
591 r.data.office_id_name);
597 c_office_id_name : function(cfg) {
600 header : "Office / Dept.",
601 dataIndex : 'office_id_name',
607 c_role : function(cfg) {
610 header : "Role / Position",
617 c_phone : function(cfg) {
627 c_fax : function(cfg) {
637 c_email : function(cfg) {
644 renderer : function (v) {
645 return (v.length && v.indexOf('@') > 0 ) ?
646 String.format('<a href="mailto:{0}">{0}</a>',v) : v;
651 c_active : function(cfg) {
655 dataIndex : 'active',
658 renderer : function(v) {
659 // work out what the column is..
661 var state = v> 0 ? '-checked' : '';
663 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
675 // need two version of this
676 // (one can be used as edit + ProjectDirectory ADD)
677 // - the other one needs selection combos's for company / office