1 //<script type="text/javascript">
3 Pman.Dialog.PersonEditor = function(config)
6 Roo.apply(this, config);
10 Pman.Dialog.PersonEditor.prototype = {
12 itemList : false, // list of itemTypes used on form.
13 dialogConfig : false, //
17 itemTypes : false, // set in contructor
34 this.dialog = new Ext.LayoutDialog(Ext.get(document.body).createChild({tag:'div'}),
37 title: 'Edit Contact Details',
50 // tabPosition: 'top',
58 this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);
59 if (this.itemList.indexOf('save_send') > -1 ) {
60 this.dialog.addButton("Send Introduction Mail", this.saveSend, this);
63 this.dialog.addButton("Cancel", this.dialog.hide, this.dialog);
67 this.dialog.addButton("Save", this.save, this);
68 this.layout = this.dialog.getLayout();
69 this.layout.beginUpdate();
72 this.form = new Ext.form.Form({
75 actionfailed : function(f, act) {
76 _this.dialog.el.unmask();
78 Pman.standardActionFailed(f,act);
81 actioncomplete: function(f, act) {
82 _this.dialog.el.unmask();
83 if (act.type == 'load') {
85 _this.data = act.result.data;
89 if ((act.type == 'load') || (act.type == 'setdata')) {
90 var data = _this.data;
91 // we dont have a form where company name is sent in - and is editable..
92 //this.form.findField('office_id')
93 if(!data.countries && _this.form.findField('countries')){
94 _this.form.findField('countries').setValue();// set empty array by default...
97 if (_this.form.findField('company_id') && _this.form.findField('company_id').setFromData) {
98 _this.form.findField('company_id').setFromData( data.company_id ? {
100 name : data.company_id_name,
101 remarks: data.company_id_remarks,
102 address: data.company_id_address,
103 tel: data.company_id_tel,
104 fax: data.company_id_fax,
105 email: data.company_id_email
106 } : { id: 0, name : '' });
110 if (_this.form.findField('office_id') && _this.form.findField('office_id').setFromData) {
111 // set up the office details.. new, edit, staff
113 _this.form.findField('office_id').setFromData(data.office_id ? {
115 name: data.office_id_name,
116 remarks: data.office_id_remarks,
117 address: data.office_id_address,
118 tel: data.office_id_tel,
119 fax: data.office_id_fax,
120 email: data.office_id_email
121 // should we add in company_name etc. ????
123 } : { id: 0, name: '' });
126 if (_this.form.findField('project_id')) {
127 _this.form.findbyId('project_id_fs').setExpand(data.project_id ? true: false);
130 _this.form.findField('project_id').setFromData(data.project_id ?{
131 id : data.project_id,
132 code : data.project_id_code
133 } : { id: 0, code :'' } );
137 if (this.type == 'staff') {
138 _this.form.findField('passwd1').allowBlank = false;
139 _this.form.findField('passwd2').allowBlank = false;
141 _this.form.findField('passwd1').allowBlank = true;
142 _this.form.findField('passwd2').allowBlank = true;
151 if (act.type == 'submit') { // only submitted here if we are
156 if (_this.callback) {
157 _this.callback.call(this, act.result.data);
159 if (_this.sendAfterSave) {
160 act.result.data.rawPasswd = _this.form.findField('passwd1').getValue();
161 _this.sendIntro([ act.result.data ], "Sending Welcome Message");
172 this.loadItemTypes();
173 Roo.each(this.itemList, function(il) {
174 if (typeof(il) != 'object') {
175 // no permission for Core offices.. - can not show department...
176 if (il == 'office_id_name' && !Pman.hasPerm('Core.Offices','S')) {
180 _this.form.addxtype(_this.itemTypes[il]);
183 _this.form.addxtype(Roo.apply(il, _this.itemTypes[il.name]));
186 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
187 ef.dom.style.margin = 10;
189 this.form.render(ef.dom);
191 var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
193 //title: 'Org Details',
203 this.layout.endUpdate();
209 loadItemTypes : function()
213 company_id_name_ro : {
214 name : 'company_id_name',
215 fieldLabel : "Company",
224 xtype: 'ComboBoxAdder',
225 fieldLabel: "Company",
226 name : 'company_id_name',
228 qtip : "Select Company",
237 url: baseURL + '/Roo/Companies.html',
240 reader: Pman.Readers.Companies,
242 beforeload : function(st,o)
245 o.params['!comptype'] = 'OWNER';
247 loadexception : Pman.loadException
251 field: 'name', direction: 'ASC'
256 hiddenName: 'company_id',
258 forceSelection: true,
260 triggerAction: 'all',
261 tpl: new Ext.Template(
262 '<div class="x-grid-cell-text x-btn button">',
263 '<b>{name}</b> {address}',
266 queryParam: 'query[name]',
267 loadingText: "Searching...",
273 adderclick : function()
276 Pman.Dialog.CoreCompanies.show( { id: 0 }, function(data) {
277 cb.setFromData(data);
286 office_id_name_ro : {
287 name : 'office_id_name',
288 fieldLabel : "Office",
297 xtype: 'ComboBoxAdder',
298 fieldLabel: "Office / Department",
299 name : 'office_id_name',
301 qtip : "Select Office",
310 url: baseURL + '/Roo/Office.html',
313 reader: Pman.Readers.Office,
315 beforeload : function(st,o)
317 // compnay myst be set..
318 var coid = _this.form.findField('company_id').getValue();
319 o.params.company_id = coid;
321 loadexception : Pman.loadException
325 field: 'name', direction: 'ASC'
329 adderclick : function()
336 if (_this.type == 'new') {
337 data = _this.form.findField('company_id').lastData;
339 Ext.MessageBox.alert("Error", "Select An Company First");
344 company_id : data.id ,
345 company_id_name: data.name,
346 address: data.address,
352 } else { // all other tyeps have the data in the caller data array.
355 company_id : data.company_id,
356 company_id_name: data.company_id_name,
357 address: data.company_id_address,
358 phone: data.company_id_tel,
359 fax: data.company_id_fax,
360 email: data.company_id_email
367 Pman.Dialog.Office.show(cfg, function(data) {
368 cb.setFromData(data);
371 beforequery : function (qe) {
372 var coid = _this.form.findField('company_id').getValue();
374 Ext.MessageBox.alert("Error", "Select An Company First");
381 hiddenName: 'office_id',
383 forceSelection: true,
385 triggerAction: 'all',
386 tpl: new Ext.Template(
387 '<div class="x-grid-cell-text x-btn button">',
388 '<b>{name}</b> {address}',
391 queryParam: 'query[name]',
392 loadingText: "Searching...",
402 fieldLabel : "Contact Name",
411 fieldLabel : "Role / Position",
414 qtip : "Enter Role / Position",
421 fieldLabel : "Phone",
424 qtip : "Enter phone Number",
440 fieldLabel : "Email",
443 qtip : "Enter email",
449 fieldLabel : "Email address (one per line)",
452 qtip : "Enter email addresse",
461 fieldLabel : "Email",
464 qtip : "Enter email",
469 xtype: 'ComboBoxArray',
471 fieldLabel : 'Country',
472 hiddenName : 'countries',
473 name : 'countries_name',
480 displayField : 'title',
482 emptyText : "Select Country",
483 forceSelection : true,
485 triggerAction : 'all',
490 xtype: 'SimpleStore',
493 return Pman.I18n.simpleStoreData('c');
495 fields : [ 'code', 'title' ]
501 fieldLabel : "New Password ",
503 allowBlank : true, // must be filled in as we rely on it for login details..
504 inputType: 'password', // << if comment out this input type, it should be ok
505 xtype : 'SecurePass',
507 imageRoot : rootURL + '/Pman/templates/images'
512 fieldLabel : "Password (type again to confirm)",
514 allowBlank : true, // must be filled in as we rely on it for login details..
515 inputType: 'password', // << if comment out this input type, it should be ok
520 xtype : 'FieldSetEx',
521 name: 'project_id_fs',
525 style: 'width:420px;',
526 legend : "Always File Messages from this Person in Project",
528 Pman.Std.project_id({
530 fieldLabel : "Project",
535 name : 'action_type_str',
537 qtip : "Action Type",
538 fieldLabel : "Action Required",
544 store: new Ext.data.SimpleStore({
546 fields: [ 'code', 'desc' ],
547 data: [[ 'ACTION_REQUIRED', "Yes"] , [ 'NOTIFY', "No"] ]
552 hiddenName: 'action_type',
553 value : 'ACTION_REQUIRED',
554 forceSelection: true,
557 // queryParam: 'query[project]',
558 // loadingText: "Searching...",
567 id : { name : 'id', value : '', xtype : 'Hidden' },
568 save_send : { name : '_save_send', value : 0, xtype : 'Hidden' },
569 active : { name : 'active', value : 1, xtype : 'Hidden' },
570 company_id : { name : 'company_id', value : '', xtype : 'Hidden' },
571 company_id_email : { name : 'company_id_email', value : '', xtype : 'Hidden' },
572 company_id_address : { name : 'company_id_address', value : '', xtype : 'Hidden' },
573 company_id_tel : { name : 'company_id_tel', value : '', xtype : 'Hidden' },
574 company_id_fax : { name : 'company_id_fax', value : '', xtype : 'Hidden' },
575 project_id_addto : { name : 'project_id_addto', value : '', xtype : 'Hidden' }
578 }, //end getItemTypes
580 saveSend : function(bt, e)
585 save : function(bt, e, andsend)
587 // ensure a company has been selected..
588 this.sendAfterSave = andsend || 0;
590 if (this.form.findField('bulklist')) {
595 if (this.form.findField('company_id') && !this.form.findField('company_id').getValue()) {
596 Ext.MessageBox.alert("Error", "Select a Company");
600 if (this.form.findField('passwd1')) {
602 var p1 = this.form.findField('passwd1').getValue();
603 var p2 = this.form.findField('passwd2').getValue();
605 if (this.sendAfterSave && !p1.length) {
606 Ext.MessageBox.alert("Error", "You must create a password to send introduction mail");
610 if (Pman.Login.authUser.id < 0 && !p1.length) {
611 Ext.MessageBox.alert("Error", "You must create a password for the admin account");
616 if (p1.length || p2.length) {
618 Ext.MessageBox.alert("Error", "Passwords do not match");
625 // ensure it's blank!
626 if (this.form.findField('project_id')) {
627 if (!this.form.findbyId('project_id_fs').expanded) {
628 this.form.findField('project_id').setFromData({
634 this.dialog.el.mask("Sending");
635 this.form.doAction('submit', {
636 url: baseURL + '/Roo/Person.html',
647 show: function (data, callback)
650 this.callback = callback;
657 this.dialog.el.mask("Loading");
658 this.form.doAction('load', {
659 url: baseURL + '/Roo/Person.html',
666 // this.fireEvent('show');
670 this.form.setValues(data);
672 this.form.fireEvent('actioncomplete', this.form,{
678 // no need to load...
682 saveBulk: function() {
683 // similar action to SendIntro
684 // we build a fake list of data..
685 if (!this.form.findField('company_id').getValue()) {
686 Roo.MessageBox.alert("Error", "Select the Company Name");
693 Roo.MessageBox.confirm("Send Welcome", "Send Welcome Messages and Generate Passwords?",
700 Roo.each(_this.form.findField('bulklist').getValue().split("\n"), function(v) {
701 if (!v.length || !v.replace(new RegExp(' ', 'g'), '').length) {
707 company_id : _this.form.findField('company_id').getValue(),
708 office_id : _this.form.findField('office_id').getValue(),
716 Roo.MessageBox.alert("Error", "No addresses found");
720 _this.sendIntro(adr, "Creating Account / Sending Welcome", _this.callback)
732 sendIntro : function(ar, msg, callback) {
733 // can hanlde multiple items -- will be usefull for later usage
734 // when we do list of multiple users..
737 Roo.MessageBox.show({
738 title: "Please wait...",
745 //this.sendData = ar; console.log(ar);
747 var wis = function ()
749 if (i == ar.length) {
750 Roo.MessageBox.hide();
751 Roo.MessageBox.alert("Done", "Done - " + msg);
753 callback.call(this, false);
757 Roo.MessageBox.updateProgress(
758 (i+1)/ar.length, msg + " : " + ar[i].email
765 url : baseURL+'/Core/SendIntro.html',
768 success : function(resp, opts) {
773 Roo.MessageBox.show({
774 title: "Please wait...",
780 // error condition!?!?