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 _this.form.addxtype(_this.itemTypes[il]);
178 _this.form.addxtype(Roo.apply(il, _this.itemTypes[il.name]));
181 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
182 ef.dom.style.margin = 10;
184 this.form.render(ef.dom);
186 var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
188 //title: 'Org Details',
198 this.layout.endUpdate();
204 loadItemTypes : function()
208 company_id_name_ro : {
209 name : 'company_id_name',
210 fieldLabel : "Company",
219 xtype: 'ComboBoxAdder',
220 fieldLabel: "Company",
221 name : 'company_id_name',
223 qtip : "Select Company",
232 url: baseURL + '/Roo/Companies.html',
235 reader: Pman.Readers.Companies,
237 beforeload : function(st,o)
240 o.params['!comptype'] = 'OWNER';
242 loadexception : Pman.loadException
246 field: 'name', direction: 'ASC'
251 hiddenName: 'company_id',
253 forceSelection: true,
255 triggerAction: 'all',
256 tpl: new Ext.Template(
257 '<div class="x-grid-cell-text x-btn button">',
258 '<b>{name}</b> {address}',
261 queryParam: 'query[name]',
262 loadingText: "Searching...",
268 adderclick : function()
271 Pman.Dialog.CoreCompanies.show( { id: 0 }, function(data) {
272 cb.setFromData(data);
281 office_id_name_ro : {
282 name : 'office_id_name',
283 fieldLabel : "Office",
292 xtype: 'ComboBoxAdder',
293 fieldLabel: "Office / Department",
294 name : 'office_id_name',
296 qtip : "Select Office",
305 url: baseURL + '/Roo/Office.html',
308 reader: Pman.Readers.Office,
310 beforeload : function(st,o)
312 // compnay myst be set..
313 var coid = _this.form.findField('company_id').getValue();
314 o.params.company_id = coid;
316 loadexception : Pman.loadException
320 field: 'name', direction: 'ASC'
324 adderclick : function()
331 if (_this.type == 'new') {
332 data = _this.form.findField('company_id').lastData;
334 Ext.MessageBox.alert("Error", "Select An Company First");
339 company_id : data.id ,
340 company_id_name: data.name,
341 address: data.address,
347 } else { // all other tyeps have the data in the caller data array.
350 company_id : data.company_id,
351 company_id_name: data.company_id_name,
352 address: data.company_id_address,
353 phone: data.company_id_tel,
354 fax: data.company_id_fax,
355 email: data.company_id_email
362 Pman.Dialog.Office.show(cfg, function(data) {
363 cb.setFromData(data);
366 beforequery : function (qe) {
367 var coid = _this.form.findField('company_id').getValue();
369 Ext.MessageBox.alert("Error", "Select An Company First");
376 hiddenName: 'office_id',
378 forceSelection: true,
380 triggerAction: 'all',
381 tpl: new Ext.Template(
382 '<div class="x-grid-cell-text x-btn button">',
383 '<b>{name}</b> {address}',
386 queryParam: 'query[name]',
387 loadingText: "Searching...",
397 fieldLabel : "Contact Name",
406 fieldLabel : "Role / Position",
409 qtip : "Enter Role / Position",
416 fieldLabel : "Phone",
419 qtip : "Enter phone Number",
435 fieldLabel : "Email",
438 qtip : "Enter email",
444 fieldLabel : "Email address (one per line)",
447 qtip : "Enter email addresse",
456 fieldLabel : "Email",
459 qtip : "Enter email",
464 xtype: 'ComboBoxArray',
466 fieldLabel : 'Country',
467 hiddenName : 'countries',
468 name : 'countries_name',
475 displayField : 'title',
477 emptyText : "Select Country",
478 forceSelection : true,
480 triggerAction : 'all',
485 xtype: 'SimpleStore',
488 return Pman.I18n.simpleStoreData('c');
490 fields : [ 'code', 'title' ]
496 fieldLabel : "New Password ",
498 allowBlank : true, // must be filled in as we rely on it for login details..
499 inputType: 'password', // << if comment out this input type, it should be ok
500 xtype : 'SecurePass',
502 imageRoot : rootURL + '/Pman/templates/images'
507 fieldLabel : "Password (type again to confirm)",
509 allowBlank : true, // must be filled in as we rely on it for login details..
510 inputType: 'password', // << if comment out this input type, it should be ok
515 xtype : 'FieldSetEx',
516 name: 'project_id_fs',
520 style: 'width:420px;',
521 legend : "Always File Messages from this Person in Project",
523 Pman.Std.project_id({
525 fieldLabel : "Project",
530 name : 'action_type_str',
532 qtip : "Action Type",
533 fieldLabel : "Action Required",
539 store: new Ext.data.SimpleStore({
541 fields: [ 'code', 'desc' ],
542 data: [[ 'ACTION_REQUIRED', "Yes"] , [ 'NOTIFY', "No"] ]
547 hiddenName: 'action_type',
548 value : 'ACTION_REQUIRED',
549 forceSelection: true,
552 // queryParam: 'query[project]',
553 // loadingText: "Searching...",
562 id : { name : 'id', value : '', xtype : 'Hidden' },
563 save_send : { name : '_save_send', value : 0, xtype : 'Hidden' },
564 active : { name : 'active', value : 1, xtype : 'Hidden' },
565 company_id : { name : 'company_id', value : '', xtype : 'Hidden' },
566 company_id_email : { name : 'company_id_email', value : '', xtype : 'Hidden' },
567 company_id_address : { name : 'company_id_address', value : '', xtype : 'Hidden' },
568 company_id_tel : { name : 'company_id_tel', value : '', xtype : 'Hidden' },
569 company_id_fax : { name : 'company_id_fax', value : '', xtype : 'Hidden' },
570 project_id_addto : { name : 'project_id_addto', value : '', xtype : 'Hidden' }
573 }, //end getItemTypes
575 saveSend : function(bt, e)
580 save : function(bt, e, andsend)
582 // ensure a company has been selected..
583 this.sendAfterSave = andsend || 0;
585 if (this.form.findField('bulklist')) {
590 if (this.form.findField('company_id') && !this.form.findField('company_id').getValue()) {
591 Ext.MessageBox.alert("Error", "Select a Company");
595 if (this.form.findField('passwd1')) {
597 var p1 = this.form.findField('passwd1').getValue();
598 var p2 = this.form.findField('passwd2').getValue();
600 if (this.sendAfterSave && !p1.length) {
601 Ext.MessageBox.alert("Error", "You must create a password to send introduction mail");
605 if (Pman.Login.authUser.id < 0 && !p1.length) {
606 Ext.MessageBox.alert("Error", "You must create a password for the admin account");
611 if (p1.length || p2.length) {
613 Ext.MessageBox.alert("Error", "Passwords do not match");
620 // ensure it's blank!
621 if (this.form.findField('project_id')) {
622 if (!this.form.findbyId('project_id_fs').expanded) {
623 this.form.findField('project_id').setFromData({
629 this.dialog.el.mask("Sending");
630 this.form.doAction('submit', {
631 url: baseURL + '/Roo/Person.html',
642 show: function (data, callback)
645 this.callback = callback;
652 this.dialog.el.mask("Loading");
653 this.form.doAction('load', {
654 url: baseURL + '/Roo/Person.html',
661 // this.fireEvent('show');
665 this.form.setValues(data);
667 this.form.fireEvent('actioncomplete', this.form,{
673 // no need to load...
677 saveBulk: function() {
678 // similar action to SendIntro
679 // we build a fake list of data..
680 if (!this.form.findField('company_id').getValue()) {
681 Roo.MessageBox.alert("Error", "Select the Company Name");
688 Roo.MessageBox.confirm("Send Welcome", "Send Welcome Messages and Generate Passwords?",
695 Roo.each(_this.form.findField('bulklist').getValue().split("\n"), function(v) {
696 if (!v.length || !v.replace(new RegExp(' ', 'g'), '').length) {
702 company_id : _this.form.findField('company_id').getValue(),
703 office_id : _this.form.findField('office_id').getValue(),
711 Roo.MessageBox.alert("Error", "No addresses found");
715 _this.sendIntro(adr, "Creating Account / Sending Welcome", _this.callback)
727 sendIntro : function(ar, msg, callback) {
728 // can hanlde multiple items -- will be usefull for later usage
729 // when we do list of multiple users..
732 Roo.MessageBox.show({
733 title: "Please wait...",
740 //this.sendData = ar; console.log(ar);
742 var wis = function ()
744 if (i == ar.length) {
745 Roo.MessageBox.hide();
746 Roo.MessageBox.alert("Done", "Done - " + msg);
748 callback.call(this, false);
752 Roo.MessageBox.updateProgress(
753 (i+1)/ar.length, msg + " : " + ar[i].email
760 url : baseURL+'/Core/SendIntro.html',
763 success : function(resp, opts) {
768 Roo.MessageBox.show({
769 title: "Please wait...",
775 // error condition!?!?