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]));
187 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
188 ef.dom.style.margin = 10;
190 this.form.render(ef.dom);
192 var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
194 //title: 'Org Details',
204 this.layout.endUpdate();
210 loadItemTypes : function()
214 company_id_name_ro : {
215 name : 'company_id_name',
216 fieldLabel : "Company",
225 xtype: 'ComboBoxAdder',
226 fieldLabel: "Company",
227 name : 'company_id_name',
229 qtip : "Select Company",
238 url: baseURL + '/Roo/core_company',
241 reader: Pman.Readers.Companies,
243 beforeload : function(st,o)
246 o.params['!comptype'] = 'OWNER';
248 loadexception : Pman.loadException
252 field: 'name', direction: 'ASC'
257 hiddenName: 'company_id',
259 forceSelection: true,
261 triggerAction: 'all',
262 tpl: new Ext.Template(
263 '<div class="x-grid-cell-text x-btn button">',
264 '<b>{name}</b> {address}',
267 queryParam: 'search[name_starts]',
268 loadingText: "Searching...",
274 adderclick : function()
277 Pman.Dialog.CoreCompanies.show( { id: 0 }, function(data) {
278 cb.setFromData(data);
287 office_id_name_ro : {
288 name : 'office_id_name',
289 fieldLabel : "Office",
298 xtype: 'ComboBoxAdder',
299 fieldLabel: "Office / Department",
300 name : 'office_id_name',
302 qtip : "Select Office",
311 url: baseURL + '/Roo/Office.html',
314 reader: Pman.Readers.Office,
316 beforeload : function(st,o)
318 // compnay myst be set..
319 var coid = _this.form.findField('company_id').getValue();
320 o.params.company_id = coid;
322 loadexception : Pman.loadException
326 field: 'name', direction: 'ASC'
330 adderclick : function()
337 if (_this.type == 'new') {
338 data = _this.form.findField('company_id').lastData;
340 Ext.MessageBox.alert("Error", "Select An Company First");
345 company_id : data.id ,
346 company_id_name: data.name,
347 address: data.address,
353 } else { // all other tyeps have the data in the caller data array.
356 company_id : data.company_id,
357 company_id_name: data.company_id_name,
358 address: data.company_id_address,
359 phone: data.company_id_tel,
360 fax: data.company_id_fax,
361 email: data.company_id_email
368 Pman.Dialog.Office.show(cfg, function(data) {
369 cb.setFromData(data);
372 beforequery : function (qe) {
373 var coid = _this.form.findField('company_id').getValue();
375 Ext.MessageBox.alert("Error", "Select An Company First");
382 hiddenName: 'office_id',
384 forceSelection: true,
386 triggerAction: 'all',
387 tpl: new Ext.Template(
388 '<div class="x-grid-cell-text x-btn button">',
389 '<b>{name}</b> {address}',
392 queryParam: 'query[name]',
393 loadingText: "Searching...",
403 fieldLabel : "Contact Name",
412 fieldLabel : "Role / Position",
415 qtip : "Enter Role / Position",
422 fieldLabel : "Phone",
425 qtip : "Enter phone Number",
441 fieldLabel : "Email",
444 qtip : "Enter email",
450 fieldLabel : "Email address (one per line)",
453 qtip : "Enter email addresse",
462 fieldLabel : "Email",
465 qtip : "Enter email",
470 xtype: 'ComboBoxArray',
472 fieldLabel : 'Country',
473 hiddenName : 'countries',
474 name : 'countries_name',
481 displayField : 'title',
483 emptyText : "Select Country",
484 forceSelection : true,
486 triggerAction : 'all',
491 xtype: 'SimpleStore',
494 return Pman.I18n.simpleStoreData('c');
496 fields : [ 'code', 'title' ]
502 fieldLabel : "New Password ",
504 allowBlank : true, // must be filled in as we rely on it for login details..
505 inputType: 'password', // << if comment out this input type, it should be ok
506 xtype : 'SecurePass',
508 imageRoot : rootURL + '/Pman/templates/images'
513 fieldLabel : "Password (type again to confirm)",
515 allowBlank : true, // must be filled in as we rely on it for login details..
516 inputType: 'password', // << if comment out this input type, it should be ok
521 name : 'secure_passowrd',
522 fieldLabel : "Secure passwords",
530 check : function (_self, checked) {
531 this.form.findField('passwd1').insecure = false;
534 this.form.findField('passwd1').insecure = true;
540 xtype : 'FieldSetEx',
541 name: 'project_id_fs',
545 style: 'width:420px;',
546 legend : "Always File Messages from this Person in Project",
548 Pman.Std.project_id({
550 fieldLabel : "Project",
555 name : 'action_type_str',
557 qtip : "Action Type",
558 fieldLabel : "Action Required",
564 store: new Ext.data.SimpleStore({
566 fields: [ 'code', 'desc' ],
567 data: [[ 'ACTION_REQUIRED', "Yes"] , [ 'NOTIFY', "No"] ]
572 hiddenName: 'action_type',
573 value : 'ACTION_REQUIRED',
574 forceSelection: true,
577 // queryParam: 'query[project]',
578 // loadingText: "Searching...",
587 id : { name : 'id', value : '', xtype : 'Hidden' },
588 save_send : { name : '_save_send', value : 0, xtype : 'Hidden' },
589 active : { name : 'active', value : 1, xtype : 'Hidden' },
590 company_id : { name : 'company_id', value : '', xtype : 'Hidden' },
591 company_id_email : { name : 'company_id_email', value : '', xtype : 'Hidden' },
592 company_id_address : { name : 'company_id_address', value : '', xtype : 'Hidden' },
593 company_id_tel : { name : 'company_id_tel', value : '', xtype : 'Hidden' },
594 company_id_fax : { name : 'company_id_fax', value : '', xtype : 'Hidden' },
595 project_id_addto : { name : 'project_id_addto', value : '', xtype : 'Hidden' }
598 }, //end getItemTypes
600 saveSend : function(bt, e)
605 save : function(bt, e, andsend)
607 // ensure a company has been selected..
608 this.sendAfterSave = andsend || 0;
610 if (this.form.findField('bulklist')) {
615 if (this.form.findField('company_id') && !this.form.findField('company_id').getValue()) {
616 Ext.MessageBox.alert("Error", "Select a Company");
620 if (this.form.findField('passwd1')) {
622 var p1 = this.form.findField('passwd1').getValue();
623 var p2 = this.form.findField('passwd2').getValue();
625 if (this.sendAfterSave && !p1.length) {
626 Ext.MessageBox.alert("Error", "You must create a password to send introduction mail");
630 if (Pman.Login.authUser.id < 0 && !p1.length) {
631 Ext.MessageBox.alert("Error", "You must create a password for the admin account");
636 if (p1.length || p2.length) {
638 Ext.MessageBox.alert("Error", "Passwords do not match");
645 // ensure it's blank!
646 if (this.form.findField('project_id')) {
647 if (!this.form.findbyId('project_id_fs').expanded) {
648 this.form.findField('project_id').setFromData({
654 this.dialog.el.mask("Sending");
655 this.form.doAction('submit', {
656 url: baseURL + '/Roo/core_person',
667 show: function (data, callback)
670 this.callback = callback;
677 this.dialog.el.mask("Loading");
678 this.form.doAction('load', {
679 url: baseURL + '/Roo/core_person',
686 // this.fireEvent('show');
690 this.form.setValues(data);
692 this.form.fireEvent('actioncomplete', this.form,{
698 // no need to load...
702 saveBulk: function() {
703 // similar action to SendIntro
704 // we build a fake list of data..
705 if (!this.form.findField('company_id').getValue()) {
706 Roo.MessageBox.alert("Error", "Select the Company Name");
713 Roo.MessageBox.confirm("Send Welcome", "Send Welcome Messages and Generate Passwords?",
720 Roo.each(_this.form.findField('bulklist').getValue().split("\n"), function(v) {
721 if (!v.length || !v.replace(new RegExp(' ', 'g'), '').length) {
727 company_id : _this.form.findField('company_id').getValue(),
728 office_id : _this.form.findField('office_id').getValue(),
736 Roo.MessageBox.alert("Error", "No addresses found");
740 _this.sendIntro(adr, "Creating Account / Sending Welcome", _this.callback)
752 sendIntro : function(ar, msg, callback) {
753 // can hanlde multiple items -- will be usefull for later usage
754 // when we do list of multiple users..
757 Roo.MessageBox.show({
758 title: "Please wait...",
765 //this.sendData = ar; console.log(ar);
767 var wis = function ()
769 if (i == ar.length) {
770 Roo.MessageBox.hide();
771 Roo.MessageBox.alert("Done", "Done - " + msg);
773 callback.call(this, false);
777 Roo.MessageBox.updateProgress(
778 (i+1)/ar.length, msg + " : " + ar[i].email
785 url : baseURL+'/Core/SendIntro.html',
788 success : function(resp, opts) {
793 Roo.MessageBox.show({
794 title: "Please wait...",
800 // error condition!?!?