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;
90 if ((act.type == 'load') || (act.type == 'setdata')) {
91 var data = _this.data;
92 // we dont have a form where company name is sent in - and is editable..
93 //this.form.findField('office_id')
95 if (_this.form.findField('company_id') && _this.form.findField('company_id').setFromData) {
96 _this.form.findField('company_id').setFromData( data.company_id ? {
98 name : data.company_id_name,
99 remarks: data.company_id_remarks,
100 address: data.company_id_address,
101 tel: data.company_id_tel,
102 fax: data.company_id_fax,
103 email: data.company_id_email
104 } : { id: 0, name : '' });
108 if (_this.form.findField('office_id') && _this.form.findField('office_id').setFromData) {
109 // set up the office details.. new, edit, staff
111 _this.form.findField('office_id').setFromData(data.office_id ? {
113 name: data.office_id_name,
114 remarks: data.office_id_remarks,
115 address: data.office_id_address,
116 tel: data.office_id_tel,
117 fax: data.office_id_fax,
118 email: data.office_id_email
119 // should we add in company_name etc. ????
121 } : { id: 0, name: '' });
124 if (_this.form.findField('project_id')) {
125 _this.form.findbyId('project_id_fs').setExpand(data.project_id ? true: false);
128 _this.form.findField('project_id').setFromData(data.project_id ?{
129 id : data.project_id,
130 code : data.project_id_code
131 } : { id: 0, code :'' } );
135 if (this.type == 'staff') {
136 _this.form.findField('passwd1').allowBlank = false;
137 _this.form.findField('passwd2').allowBlank = false;
139 _this.form.findField('passwd1').allowBlank = true;
140 _this.form.findField('passwd2').allowBlank = true;
147 if (act.type == 'submit') { // only submitted here if we are
152 if (_this.callback) {
153 _this.callback.call(this, act.result.data);
155 if (_this.sendAfterSave) {
156 act.result.data.rawPasswd = _this.form.findField('passwd1').getValue();
157 _this.sendIntro([ act.result.data ], "Sending Welcome Message");
168 this.loadItemTypes();
169 Roo.each(this.itemList, function(il) {
170 if (typeof(il) != 'object') {
171 _this.form.addxtype(_this.itemTypes[il]);
174 _this.form.addxtype(Roo.apply(il, _this.itemTypes[il.name]));
177 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
178 ef.dom.style.margin = 10;
180 this.form.render(ef.dom);
182 var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
184 //title: 'Org Details',
194 this.layout.endUpdate();
200 loadItemTypes : function()
204 company_id_name_ro : {
205 name : 'company_id_name',
206 fieldLabel : "Company",
215 xtype: 'ComboBoxAdder',
216 fieldLabel: "Company",
217 name : 'company_id_name',
219 qtip : "Select Company",
228 url: baseURL + '/Roo/Companies.html',
231 reader: Pman.Readers.Companies,
233 beforeload : function(st,o)
236 o.params['!comptype'] = 'OWNER';
238 loadexception : Pman.loadException
242 field: 'name', direction: 'ASC'
247 hiddenName: 'company_id',
249 forceSelection: true,
251 triggerAction: 'all',
252 tpl: new Ext.Template(
253 '<div class="x-grid-cell-text x-btn button">',
254 '<b>{name}</b> {address}',
257 queryParam: 'query[name]',
258 loadingText: "Searching...",
264 adderclick : function()
267 Pman.Dialog.CoreCompanies.show( { id: 0 }, function(data) {
268 cb.setFromData(data);
277 office_id_name_ro : {
278 name : 'office_id_name',
279 fieldLabel : "Office",
288 xtype: 'ComboBoxAdder',
289 fieldLabel: "Office / Department",
290 name : 'office_id_name',
292 qtip : "Select Office",
301 url: baseURL + '/Roo/Office.html',
304 reader: Pman.Readers.Office,
306 beforeload : function(st,o)
308 // compnay myst be set..
309 var coid = _this.form.findField('company_id').getValue();
310 o.params.company_id = coid;
312 loadexception : Pman.loadException
316 field: 'name', direction: 'ASC'
320 adderclick : function()
327 if (_this.type == 'new') {
328 data = _this.form.findField('company_id').lastData;
330 Ext.MessageBox.alert("Error", "Select An Company First");
335 company_id : data.id ,
336 company_id_name: data.name,
337 address: data.address,
343 } else { // all other tyeps have the data in the caller data array.
346 company_id : data.company_id,
347 company_id_name: data.company_id_name,
348 address: data.company_id_address,
349 phone: data.company_id_tel,
350 fax: data.company_id_fax,
351 email: data.company_id_email
358 Pman.Dialog.Office.show(cfg, function(data) {
359 cb.setFromData(data);
362 beforequery : function (qe) {
363 var coid = _this.form.findField('company_id').getValue();
365 Ext.MessageBox.alert("Error", "Select An Company First");
372 hiddenName: 'office_id',
374 forceSelection: true,
376 triggerAction: 'all',
377 tpl: new Ext.Template(
378 '<div class="x-grid-cell-text x-btn button">',
379 '<b>{name}</b> {address}',
382 queryParam: 'query[name]',
383 loadingText: "Searching...",
393 fieldLabel : "Contact Name",
402 fieldLabel : "Role / Position",
405 qtip : "Enter Role / Position",
412 fieldLabel : "Phone",
415 qtip : "Enter phone Number",
431 fieldLabel : "Email",
434 qtip : "Enter email",
440 fieldLabel : "Email address (one per line)",
443 qtip : "Enter email addresse",
452 fieldLabel : "Email",
455 qtip : "Enter email",
461 fieldLabel : "New Password ",
463 allowBlank : true, // must be filled in as we rely on it for login details..
464 inputType: 'password',
465 xtype : 'SecurePass',
467 imageRoot : rootURL + '/Pman/templates/images'
472 fieldLabel : "Password (type again to confirm)",
474 allowBlank : true, // must be filled in as we rely on it for login details..
475 inputType: 'password',
480 xtype : 'FieldSetEx',
481 name: 'project_id_fs',
485 style: 'width:420px;',
486 legend : "Always File Messages from this Person in Project",
488 Pman.Std.project_id({
490 fieldLabel : "Project",
495 name : 'action_type_str',
497 qtip : "Action Type",
498 fieldLabel : "Action Required",
504 store: new Ext.data.SimpleStore({
506 fields: [ 'code', 'desc' ],
507 data: [[ 'ACTION_REQUIRED', "Yes"] , [ 'NOTIFY', "No"] ]
512 hiddenName: 'action_type',
513 value : 'ACTION_REQUIRED',
514 forceSelection: true,
517 // queryParam: 'query[project]',
518 // loadingText: "Searching...",
527 id : { name : 'id', value : '', xtype : 'Hidden' },
528 save_send : { name : '_save_send', value : 0, xtype : 'Hidden' },
529 active : { name : 'active', value : 1, xtype : 'Hidden' },
530 company_id : { name : 'company_id', value : '', xtype : 'Hidden' },
531 company_id_email : { name : 'company_id_email', value : '', xtype : 'Hidden' },
532 company_id_address : { name : 'company_id_address', value : '', xtype : 'Hidden' },
533 company_id_tel : { name : 'company_id_tel', value : '', xtype : 'Hidden' },
534 company_id_fax : { name : 'company_id_fax', value : '', xtype : 'Hidden' },
535 project_id_addto : { name : 'project_id_addto', value : '', xtype : 'Hidden' }
538 }, //end getItemTypes
540 saveSend : function(bt, e)
545 save : function(bt, e, andsend)
547 // ensure a company has been selected..
548 this.sendAfterSave = andsend || 0;
550 if (this.form.findField('bulklist')) {
555 if (this.form.findField('company_id') && !this.form.findField('company_id').getValue()) {
556 Ext.MessageBox.alert("Error", "Select a Company");
560 if (this.form.findField('passwd1')) {
562 var p1 = this.form.findField('passwd1').getValue();
563 var p2 = this.form.findField('passwd2').getValue();
565 if (this.sendAfterSave && !p1.length) {
566 Ext.MessageBox.alert("Error", "You must create a password to send introduction mail");
570 if (Pman.Login.authUser.id < 0 && !p1.length) {
571 Ext.MessageBox.alert("Error", "You must create a password for the admin account");
576 if (p1.length || p2.length) {
578 Ext.MessageBox.alert("Error", "Passwords do not match");
585 // ensure it's blank!
586 if (this.form.findField('project_id')) {
587 if (!this.form.findbyId('project_id_fs').expanded) {
588 this.form.findField('project_id').setFromData({
594 this.dialog.el.mask("Sending");
595 this.form.doAction('submit', {
596 url: baseURL + '/Roo/Person.html',
607 show: function (data, callback)
610 this.callback = callback;
617 this.dialog.el.mask("Loading");
618 this.form.doAction('load', {
619 url: baseURL + '/Roo/Person.html',
626 // this.fireEvent('show');
630 this.form.setValues(data);
632 this.form.fireEvent('actioncomplete', this.form,{
638 // no need to load...
642 saveBulk: function() {
643 // similar action to SendIntro
644 // we build a fake list of data..
645 if (!this.form.findField('company_id').getValue()) {
646 Roo.MessageBox.alert("Error", "Select the Company Name");
653 Roo.MessageBox.confirm("Send Welcome", "Send Welcome Messages and Generate Passwords?",
660 Roo.each(_this.form.findField('bulklist').getValue().split("\n"), function(v) {
661 if (!v.length || !v.replace(new RegExp(' ', 'g'), '').length) {
667 company_id : _this.form.findField('company_id').getValue(),
668 office_id : _this.form.findField('office_id').getValue(),
676 Roo.MessageBox.alert("Error", "No addresses found");
680 _this.sendIntro(adr, "Creating Account / Sending Welcome", _this.callback)
692 sendIntro : function(ar, msg, callback) {
693 // can hanlde multiple items -- will be usefull for later usage
694 // when we do list of multiple users..
697 Roo.MessageBox.show({
698 title: "Please wait...",
705 //this.sendData = ar; console.log(ar);
707 var wis = function ()
709 if (i == ar.length) {
710 Roo.MessageBox.hide();
711 Roo.MessageBox.alert("Done", "Done - " + msg);
713 callback.call(this, false);
717 Roo.MessageBox.updateProgress(
718 (i+1)/ar.length, msg + " : " + ar[i].email
725 url : baseURL+'/Core/SendIntro.html',
728 success : function(resp, opts) {
733 Roo.MessageBox.show({
734 title: "Please wait...",
740 // error condition!?!?