1 //<script type="text/javascript">
5 * generic person list - used by perms. and staff lists.
7 * -- this is probably depreciated now..
13 Pman.Tab.PersonList = function(config)
15 Roo.apply(this, config);
18 Pman.Tab.PersonList.prototype = {
20 //--- things that should be set!!!!
21 id : '', // should be set to something!
22 type : 0, // means!! = 0 = Groups (perms) 1= teams - loose grouping..
24 hiddenColumns: false, // lsit of cols to hide..
25 itemDisplayName : false, /// eg "Staff Employees / Contacts etc."
26 permName : 'Core.Person', // or 'Core.Staff'
27 getLeftSelections : function() { return []; },
30 // beforeload handler... -- override on extended versions..
31 beforeload: function(t, o) {
32 //console.log(o.params);
34 alert('person list not configured');
37 var tms = _this.getLeftSelections();
40 o.params['query[in_group]'] = tms[0].data.id;
42 o.params['query[name]'] = this.searchBox.getValue();
43 o.params['query[type]'] = this.type; // group type..
44 o.params['query[person_internal_only_all]'] = 1;
45 o.params['query[person_inactive]'] = this.showInActive ? 0 : 1;
52 alert('person list not configured');
56 this.c_office_id_name(),
66 alert('person list not configured');
68 return Pman.Dialog.PersonStaff;
70 bulkAdd : function() {
71 //return Pman.Dialog.PersonBulkAdd
74 newDefaults : function() {
75 alert('person list not configured');
80 company_id : Pman.Login.authUser.company_id,
81 company_id_name : Pman.Login.authUser.company_id_name,
82 company_id_address : Pman.Login.authUser.company_id_address,
83 company_id_tel : Pman.Login.authUser.company_id_tel,
84 company_id_fax : Pman.Login.authUser.company_id_fax
90 /// --- end extendable bits...
94 showInActive : 0, // toggle var for hiding and showing active staff..
102 refreshWestPanel : function() /// used wher???
104 var actpan = this.parentLayout.getRegion('west').getActivePanel();
105 if (actpan && actpan.controller) {
106 actpan.controller.paging.onClick('refresh');
111 if (!actpan || !actpan.id) {
114 Pman.Tab[actpan.id].refresh();
119 this.delayedCreate();
121 this.paging.onClick('refresh');
124 loadFirst: function(){
126 this.delayedCreate();
128 this.paging.onClick('first');
133 add : function(parentLayout, region) {
137 parentLayout.getRegion(region).showPanel(this.panel);
140 this.parentLayout = parentLayout;
142 this.layout = new Roo.BorderLayout(
143 parentLayout.getEl().createChild({tag:'div'}),
155 this.tab = parentLayout.add(region, new Roo.NestedLayoutPanel(
156 this.layout, {title: this.title, background: true, controller : this}));
158 this.tab.on('activate', function() {
159 _this.delayedCreate();
160 // _this.paging.onClick('refresh');
163 delayedCreate : function ()
171 var refreshPager = function() {
174 this.layout.beginUpdate();
176 var frm = this.layout.getRegion('center').getEl().createChild({tag:'div'});
177 //this.grid = new Roo.grid.EditorGrid(frm, {
178 this.grid = new Roo.grid.Grid(frm, {
182 id: this.id + '-grid',
183 ds: new Roo.data.Store({
185 proxy: new Roo.data.HttpProxy({
186 url: baseURL + '/Roo/Person.html',
189 reader: Pman.Readers.Person,
193 beforeload: function(t, o) {
194 //console.log(o.params);
196 return _this.beforeload(t,o);
200 loadexception : Pman.loadException,
201 update : function (_self, record, operation)
203 if (operation != 'commit') {
206 // only used to change active status.
209 url : baseURL + '/Roo/Person.php',
213 active: record.data.active
216 success : function() {
221 Roo.MessageBox.alert("Error", "saving failed", function() {
222 _this.grid.footer.onClick('first');
233 field: 'name', direction: 'ASC'
236 cm: new Roo.grid.ColumnModel(
239 autoExpandColumn: 'name', // fixme!!!!
245 rowdblclick : function(g, ri, e) {
246 var s = g.getDataSource().getAt(ri).data;
247 if (_this.dialog() && Pman.hasPerm(_this.permName, 'E')) {
248 _this.dialog().show(s,refreshPager);
253 cellclick : function (_self, rowIndex, columnIndex, e)
255 var di = this.colModel.getDataIndex(columnIndex);
256 if (di != 'active') {
260 var rec = _this.grid.ds.getAt(rowIndex);
262 rec.set('active', rec.data.active ? 0 : 1);
273 this.panel = this.layout.add('center', new Roo.GridPanel(this.grid , {
277 title: this.title || "Staff",
283 if (this.hiddenColumns) {
284 var cm = this.grid.getColumnModel();
285 Roo.each(this.hiddenColumns, function(c) {
286 cm.setHidden(cm.getIndexByDataIndex(c), true);
292 var gridFoot = this.grid.getView().getFooterPanel(true);
293 this.paging = new Roo.PagingToolbar(gridFoot, this.grid.getDataSource(), {
296 displayMsg: "Displaying " + (this.itemDisplayName || "Staff") + " {0} - {1} of {2}",
297 emptyMsg: "No " + (this.itemDisplayName || "Staff") + " found"
299 var grid = this.grid;
302 this.toolbar = new Roo.Toolbar(this.grid.getView().getHeaderPanel(true));
304 var tb = this.toolbar;
307 if (this.parentLayout.getRegion('west') && this.parentLayout.getRegion('west').panels.length) {
310 '<b><i><font color="red">'+
312 "Drag person to add or remove from group" :
313 "Drag person to add or remove from team"
320 //if (this.permName == 'Core.Staff') {
322 this.paging.add( '-',
324 text: "Show old staff",
327 toggleHandler: function(btn,pressed) {
328 _this.showInActive = (pressed ? 1 : 0);
329 btn.setText(pressed ? "Hide old staff": "Show old staff" );
340 this.searchBox = new Roo.form.TextField({
344 specialkey : function(f,e)
347 if (e.getKey() == 13) {
357 var dg = _this.dialog();
361 cls: 'x-btn-text-icon',
362 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
363 hidden : !dg || (_this.newDefaults() === false) || !Pman.hasPerm(this.permName, 'A'),
364 handler : function(){
365 dg.show( _this.newDefaults(), refreshPager );
368 { ///... for contacts stuff...
370 cls: 'x-btn-text-icon',
371 icon: Roo.rootURL + 'images/default/dd/drop-add.gif',
372 hidden : !this.bulkAdd() || !Pman.hasPerm(this.permName, 'A'),
373 handler : function(){
375 // Pman.Dialog.PersonBulkAdd.show( { id : 0 }, refreshPager );
376 _this.bulkAdd().show( { id : 0 }, refreshPager );
382 cls: 'x-btn-text-icon',
383 icon: Roo.rootURL + 'images/default/tree/leaf.gif',
384 hidden : !dg || !Pman.hasPerm(this.permName, 'E'),
385 handler : function(){
386 var s = grid.getSelectionModel().getSelections();
387 if (!s.length || (s.length > 1)) {
388 Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
391 dg.show( s[0].data,refreshPager);
395 text: "Toogle Active",
396 cls: 'x-btn-text-icon',
397 icon: rootURL + '/Pman/templates/images/trash.gif',
398 hidden : (this.permName != 'Core.Staff') || !Pman.hasPerm(this.permName, 'E'), // SPECIFIC TO STAFF!!!!!!
399 handler : function(){
401 var s = grid.getSelectionModel().getSelections();
403 Roo.MessageBox.alert("Error", "Select People Row");
407 for(var i = 0; i < s.length; i++) {
408 r.push(s[i].data.id);
413 grid.getView().mainWrap.mask("Sending");
417 url: baseURL + '/Roo/Person.html',
420 _toggleActive : r.join(',')
422 success: function(resp) {
423 var res = Pman.processResponse(resp);
424 grid.getView().mainWrap.unmask();
426 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg : "Error Sending");
432 failure: function(act) {
433 grid.getView().mainWrap.unmask();
434 Roo.MessageBox.alert("Error", "Error Sending");
444 cls: 'x-btn-text-icon',
445 hidden : !Pman.hasPerm(_this.permName, 'D'),
446 icon: rootURL + '/Pman/templates/images/trash.gif',
447 handler : function(){
448 Pman.genericDelete(_this, 'Person');
461 icon: rootURL + '/Pman/templates/images/search.gif', // icons can also be specified inline
464 handler : function () {
465 _this.grid.getSelectionModel().clearSelections();
473 icon: rootURL + '/Pman/templates/images/edit-clear.gif', // icons can also be specified inline
475 qtip: "Reset Search",
476 handler : function () {
477 _this.searchBox.setValue('');
478 _this.grid.getSelectionModel().clearSelections();
489 text: "Switch to Selected User",
490 hidden : _this.permName != 'Core.Staff' || !Pman.hasPerm('Core.Staff', 'E'),
492 click : function () {
493 var s = grid.getSelectionModel().getSelections();
495 Roo.MessageBox.alert("Error", "Select a Person");
499 url : baseURL+ '/Login.php',
501 'switch' : s[0].data.id
505 success : function() {
506 document.location = baseURL + '?ts=' + Math.random();
509 failure : function(d) {
511 Roo.MessageBox.alert("Error", d);
527 // add stuff to toolbar?
528 //this.innerLayout.endUpdate();
529 this.layout.endUpdate();
535 show: function (parentLayout, region)
537 this.add(parentLayout, region);
538 this.grid.getDataSource().load({
548 c_project_id_code : function(cfg) {
552 dataIndex : 'project_id_code',
555 renderer : function(v,x,r) {
556 return String.format('<span qtip="{0}">{1}</span>',
566 c_name : function(cfg) {
569 // id : (this.id + '-name').toLowerCase(),
576 c_company_id_comptype : function(cfg) {
579 header : "Company Type",
580 dataIndex : 'company_id_comptype',
586 c_company_id_name : function(cfg) {
589 header : "Company / Office",
590 dataIndex : 'company_id_name',
593 renderer: function(v,x,r) {
594 return String.format('{0}{1}{2}',
596 r.data.office_id ? ' / ' : '',
597 r.data.office_id_name);
603 c_office_id_name : function(cfg) {
606 header : "Office / Dept.",
607 dataIndex : 'office_id_name',
613 c_role : function(cfg) {
616 header : "Role / Position",
623 c_phone : function(cfg) {
633 c_fax : function(cfg) {
643 c_email : function(cfg) {
650 renderer : function (v) {
651 return (v.length && v.indexOf('@') > 0 ) ?
652 String.format('<a href="mailto:{0}">{0}</a>',v) : v;
657 c_active : function(cfg) {
661 dataIndex : 'active',
664 renderer : function(v) {
665 // work out what the column is..
667 var state = v> 0 ? '-checked' : '';
669 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
681 // need two version of this
682 // (one can be used as edit + ProjectDirectory ADD)
683 // - the other one needs selection combos's for company / office