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');
35 var tms = _this.getLeftSelections();
38 o.params['query[in_group]'] = tms[0].data.id;
40 o.params['query[name]'] = this.searchBox.getValue();
41 o.params['query[type]'] = this.type; // group type..
42 o.params['query[person_internal_only_all]'] = 1;
43 o.params['query[person_inactive]'] = this.showInActive ? 0 : 1;
50 alert('person list not configured');
54 this.c_office_id_name(),
64 alert('person list not configured');
66 return Pman.Dialog.PersonStaff;
68 bulkAdd : function() {
69 //return Pman.Dialog.PersonBulkAdd
72 newDefaults : function() {
73 alert('person list not configured');
78 company_id : Pman.Login.authUser.company_id,
79 company_id_name : Pman.Login.authUser.company_id_name,
80 company_id_address : Pman.Login.authUser.company_id_address,
81 company_id_tel : Pman.Login.authUser.company_id_tel,
82 company_id_fax : Pman.Login.authUser.company_id_fax
88 /// --- end extendable bits...
92 showInActive : 0, // toggle var for hiding and showing active staff..
100 refreshWestPanel : function() /// used wher???
102 var actpan = this.parentLayout.getRegion('west').getActivePanel();
103 if (actpan && actpan.controller) {
104 actpan.controller.paging.onClick('refresh');
109 if (!actpan || !actpan.id) {
112 Pman.Tab[actpan.id].refresh();
117 this.delayedCreate();
119 this.paging.onClick('refresh');
122 loadFirst: function(){
124 this.delayedCreate();
126 this.paging.onClick('first');
131 add : function(parentLayout, region) {
135 parentLayout.getRegion(region).showPanel(this.panel);
138 this.parentLayout = parentLayout;
140 this.layout = new Roo.BorderLayout(
141 parentLayout.getEl().createChild({tag:'div'}),
153 this.tab = parentLayout.add(region, new Roo.NestedLayoutPanel(
154 this.layout, {title: this.title, background: true, controller : this}));
156 this.tab.on('activate', function() {
157 _this.delayedCreate();
158 // _this.paging.onClick('refresh');
161 delayedCreate : function ()
169 var refreshPager = function() {
172 this.layout.beginUpdate();
174 var frm = this.layout.getRegion('center').getEl().createChild({tag:'div'});
175 //this.grid = new Roo.grid.EditorGrid(frm, {
176 this.grid = new Roo.grid.Grid(frm, {
180 id: this.id + '-grid',
181 ds: new Roo.data.Store({
183 proxy: new Roo.data.HttpProxy({
184 url: baseURL + '/Roo/Person.html',
187 reader: Pman.Readers.Person,
191 beforeload: function(t, o) {
192 //console.log(o.params);
194 return _this.beforeload(t,o);
198 loadexception : Pman.loadException,
199 update : function (_self, record, operation)
201 if (operation != 'commit') {
204 // only used to change active status.
207 url : baseURL + '/Roo/Person.php',
211 active: record.data.active
214 success : function() {
219 Roo.MessageBox.alert("Error", "saving failed", function() {
220 _this.grid.footer.onClick('first');
231 field: 'name', direction: 'ASC'
234 cm: new Roo.grid.ColumnModel(
237 autoExpandColumn: 'name', // fixme!!!!
243 rowdblclick : function(g, ri, e) {
244 var s = g.getDataSource().getAt(ri).data;
245 if (_this.dialog() && Pman.hasPerm(_this.permName, 'E')) {
246 _this.dialog().show(s,refreshPager);
251 cellclick : function (_self, rowIndex, columnIndex, e)
253 var di = this.colModel.getDataIndex(columnIndex);
254 if (di != 'active') {
258 var rec = _this.grid.ds.getAt(rowIndex);
260 rec.set('active', rec.data.active ? 0 : 1);
271 this.panel = this.layout.add('center', new Roo.GridPanel(this.grid , {
275 title: this.title || "Staff",
281 if (this.hiddenColumns) {
282 var cm = this.grid.getColumnModel();
283 Roo.each(this.hiddenColumns, function(c) {
284 cm.setHidden(cm.getIndexByDataIndex(c), true);
290 var gridFoot = this.grid.getView().getFooterPanel(true);
291 this.paging = new Roo.PagingToolbar(gridFoot, this.grid.getDataSource(), {
294 displayMsg: "Displaying " + (this.itemDisplayName || "Staff") + " {0} - {1} of {2}",
295 emptyMsg: "No " + (this.itemDisplayName || "Staff") + " found"
297 var grid = this.grid;
300 this.toolbar = new Roo.Toolbar(this.grid.getView().getHeaderPanel(true));
302 var tb = this.toolbar;
305 if (this.parentLayout.getRegion('west') && this.parentLayout.getRegion('west').panels.length) {
308 '<b><i><font color="red">'+
310 "Drag person to add or remove from group" :
311 "Drag person to add or remove from team"
318 //if (this.permName == 'Core.Staff') {
320 this.paging.add( '-',
322 text: "Show old staff",
325 toggleHandler: function(btn,pressed) {
326 _this.showInActive = (pressed ? 1 : 0);
327 btn.setText(pressed ? "Hide old staff": "Show old staff" );
338 this.searchBox = new Roo.form.TextField({
342 specialkey : function(f,e)
345 if (e.getKey() == 13) {
355 var dg = _this.dialog();
359 cls: 'x-btn-text-icon',
360 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
361 hidden : !dg || (_this.newDefaults() === false) || !Pman.hasPerm(this.permName, 'A'),
362 handler : function(){
363 dg.show( _this.newDefaults(), refreshPager );
366 { ///... for contacts stuff...
368 cls: 'x-btn-text-icon',
369 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
370 hidden : !this.bulkAdd() || !Pman.hasPerm(this.permName, 'A'),
371 handler : function(){
373 // Pman.Dialog.PersonBulkAdd.show( { id : 0 }, refreshPager );
374 _this.bulkAdd().show( { id : 0 }, refreshPager );
380 cls: 'x-btn-text-icon',
381 icon: Roo.rootURL + 'images/default/tree/leaf.gif',
382 hidden : !dg || !Pman.hasPerm(this.permName, 'E'),
383 handler : function(){
384 var s = grid.getSelectionModel().getSelections();
385 if (!s.length || (s.length > 1)) {
386 Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
389 dg.show( s[0].data,refreshPager);
393 text: "Toogle Active",
394 cls: 'x-btn-text-icon',
395 icon: rootURL + '/Pman/templates/images/trash.gif',
396 hidden : (this.permName != 'Core.Staff') || !Pman.hasPerm(this.permName, 'E'), // SPECIFIC TO STAFF!!!!!!
397 handler : function(){
399 var s = grid.getSelectionModel().getSelections();
401 Roo.MessageBox.alert("Error", "Select People Row");
405 for(var i = 0; i < s.length; i++) {
406 r.push(s[i].data.id);
411 grid.getView().mainWrap.mask("Sending");
415 url: baseURL + '/Roo/Person.html',
418 _toggleActive : r.join(',')
420 success: function(resp) {
421 var res = Pman.processResponse(resp);
422 grid.getView().mainWrap.unmask();
424 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
430 failure: function(act) {
431 grid.getView().mainWrap.unmask();
432 Roo.MessageBox.alert("Error", "Error Sending");
442 cls: 'x-btn-text-icon',
443 hidden : !Pman.hasPerm(_this.permName, 'D'),
444 icon: rootURL + '/Pman/templates/images/trash.gif',
445 handler : function(){
446 Pman.genericDelete(_this, 'Person');
459 icon: rootURL + '/Pman/templates/images/search.gif', // icons can also be specified inline
462 handler : function () {
463 _this.grid.getSelectionModel().clearSelections();
471 icon: rootURL + '/Pman/templates/images/edit-clear.gif', // icons can also be specified inline
473 qtip: "Reset Search",
474 handler : function () {
475 _this.searchBox.setValue('');
476 _this.grid.getSelectionModel().clearSelections();
487 text: "Switch to Selected User",
488 hidden : _this.permName != 'Core.Staff' || !Pman.hasPerm('Core.Staff', 'E'),
490 click : function () {
491 var s = grid.getSelectionModel().getSelections();
493 Roo.MessageBox.alert("Error", "Select a Person");
497 url : baseURL+ '/Login.php',
499 'switch' : s[0].data.id
503 success : function() {
504 document.location = baseURL + '?ts=' + Math.random();
507 failure : function(d) {
509 Roo.MessageBox.alert("Error", d);
525 // add stuff to toolbar?
526 //this.innerLayout.endUpdate();
527 this.layout.endUpdate();
533 show: function (parentLayout, region)
535 this.add(parentLayout, region);
536 this.grid.getDataSource().load({
546 c_project_id_code : function(cfg) {
550 dataIndex : 'project_id_code',
553 renderer : function(v,x,r) {
554 return String.format('<span qtip="{0}">{1}</span>',
564 c_name : function(cfg) {
567 // id : (this.id + '-name').toLowerCase(),
574 c_company_id_comptype : function(cfg) {
577 header : "Company Type",
578 dataIndex : 'company_id_comptype',
584 c_company_id_name : function(cfg) {
587 header : "Company / Office",
588 dataIndex : 'company_id_name',
591 renderer: function(v,x,r) {
592 return String.format('{0}{1}{2}',
594 r.data.office_id ? ' / ' : '',
595 r.data.office_id_name);
601 c_office_id_name : function(cfg) {
604 header : "Office / Dept.",
605 dataIndex : 'office_id_name',
611 c_role : function(cfg) {
614 header : "Role / Position",
621 c_phone : function(cfg) {
631 c_fax : function(cfg) {
641 c_email : function(cfg) {
648 renderer : function (v) {
649 return (v.length && v.indexOf('@') > 0 ) ?
650 String.format('<a href="mailto:{0}">{0}</a>',v) : v;
655 c_active : function(cfg) {
659 dataIndex : 'active',
662 renderer : function(v) {
663 // work out what the column is..
665 var state = v> 0 ? '-checked' : '';
667 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
679 // need two version of this
680 // (one can be used as edit + ProjectDirectory ADD)
681 // - the other one needs selection combos's for company / office