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') {
84 _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')
94 if (_this.form.findField('company_id') && _this.form.findField('company_id').setFromData) {
95 _this.form.findField('company_id').setFromData( data.company_id ? {
97 name : data.company_id_name,
98 remarks: data.company_id_remarks,
99 address: data.company_id_address,
100 tel: data.company_id_tel,
101 fax: data.company_id_fax,
102 email: data.company_id_email
103 } : { id: 0, name : '' });
107 if (_this.form.findField('office_id') && _this.form.findField('office_id').setFromData) {
108 // set up the office details.. new, edit, staff
110 _this.form.findField('office_id').setFromData(data.office_id ? {
112 name: data.office_id_name,
113 remarks: data.office_id_remarks,
114 address: data.office_id_address,
115 tel: data.office_id_tel,
116 fax: data.office_id_fax,
117 email: data.office_id_email
118 // should we add in company_name etc. ????
120 } : { id: 0, name: '' });
123 if (_this.form.findField('project_id')) {
124 _this.form.findbyId('project_id_fs').setExpand(data.project_id ? true: false);
127 _this.form.findField('project_id').setFromData(data.project_id ?{
128 id : data.project_id,
129 code : data.project_id_code
130 } : { id: 0, code :'' } );
134 if (this.type == 'staff') {
135 _this.form.findField('passwd1').allowBlank = false;
136 _this.form.findField('passwd2').allowBlank = false;
138 _this.form.findField('passwd1').allowBlank = true;
139 _this.form.findField('passwd2').allowBlank = true;
146 if (act.type == 'submit') { // only submitted here if we are
151 if (_this.callback) {
152 _this.callback.call(this, act.result.data);
154 if (_this.sendAfterSave) {
155 act.result.data.rawPasswd = _this.form.findField('passwd1').getValue();
156 _this.sendIntro([ act.result.data ], "Sending Welcome Message");
167 this.loadItemTypes();
168 Roo.each(this.itemList, function(il) {
169 if (typeof(il) != 'object') {
170 _this.form.addxtype(_this.itemTypes[il]);
173 _this.form.addxtype(Roo.apply(il, _this.itemTypes[il.name]));
176 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
177 ef.dom.style.margin = 10;
179 this.form.render(ef.dom);
181 var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
183 //title: 'Org Details',
193 this.layout.endUpdate();
199 loadItemTypes : function()
203 company_id_name_ro : {
204 name : 'company_id_name',
205 fieldLabel : "Company",
214 xtype: 'ComboBoxAdder',
215 fieldLabel: "Company",
216 name : 'company_id_name',
218 qtip : "Select Company",
227 url: baseURL + '/Roo/Companies.html',
230 reader: Pman.Readers.Companies,
232 beforeload : function(st,o)
235 o.params['!comptype'] = 'OWNER';
237 loadexception : Pman.loadException
241 field: 'name', direction: 'ASC'
246 hiddenName: 'company_id',
248 forceSelection: true,
250 triggerAction: 'all',
251 tpl: new Ext.Template(
252 '<div class="x-grid-cell-text x-btn button">',
253 '<b>{name}</b> {address}',
256 queryParam: 'query[name]',
257 loadingText: "Searching...",
263 adderclick : function()
266 Pman.Dialog.CoreCompanies.show( { id: 0 }, function(data) {
267 cb.setFromData(data);
276 office_id_name_ro : {
277 name : 'office_id_name',
278 fieldLabel : "Office",
287 xtype: 'ComboBoxAdder',
288 fieldLabel: "Office / Department",
289 name : 'office_id_name',
291 qtip : "Select Office",
300 url: baseURL + '/Roo/Office.html',
303 reader: Pman.Readers.Office,
305 beforeload : function(st,o)
307 // compnay myst be set..
308 var coid = _this.form.findField('company_id').getValue();
309 o.params.company_id = coid;
311 loadexception : Pman.loadException
315 field: 'name', direction: 'ASC'
319 adderclick : function()
326 if (_this.type == 'new') {
327 data = _this.form.findField('company_id').lastData;
329 Ext.MessageBox.alert("Error", "Select An Company First");
334 company_id : data.id ,
335 company_id_name: data.name,
336 address: data.address,
342 } else { // all other tyeps have the data in the caller data array.
345 company_id : data.company_id,
346 company_id_name: data.company_id_name,
347 address: data.company_id_address,
348 phone: data.company_id_tel,
349 fax: data.company_id_fax,
350 email: data.company_id_email
357 Pman.Dialog.Office.show(cfg, function(data) {
358 cb.setFromData(data);
361 beforequery : function (qe) {
362 var coid = _this.form.findField('company_id').getValue();
364 Ext.MessageBox.alert("Error", "Select An Company First");
371 hiddenName: 'office_id',
373 forceSelection: true,
375 triggerAction: 'all',
376 tpl: new Ext.Template(
377 '<div class="x-grid-cell-text x-btn button">',
378 '<b>{name}</b> {address}',
381 queryParam: 'query[name]',
382 loadingText: "Searching...",
392 fieldLabel : "Contact Name",
401 fieldLabel : "Role / Position",
404 qtip : "Enter Role / Position",
411 fieldLabel : "Phone",
414 qtip : "Enter phone Number",
430 fieldLabel : "Email",
433 qtip : "Enter email",
439 fieldLabel : "Email address (one per line)",
442 qtip : "Enter email addresse",
451 fieldLabel : "Email",
454 qtip : "Enter email",
459 xtype: 'ComboBoxArray',
461 fieldLabel : 'Country',
462 hiddenName : 'country',
463 name : 'country_name',
470 displayField : 'title',
472 emptyText : "Select Country",
473 fieldLabel : 'Journalist',
474 forceSelection : true,
476 triggerAction : 'all',
481 xtype: 'SimpleStore',
484 return Pman.I18n.simpleStoreData('c');
486 fields : [ 'code', 'title' ]
492 fieldLabel : "New Password ",
494 allowBlank : true, // must be filled in as we rely on it for login details..
495 inputType: 'password', // << if comment out this input type, it should be ok
496 xtype : 'SecurePass',
498 imageRoot : rootURL + '/Pman/templates/images'
503 fieldLabel : "Password (type again to confirm)",
505 allowBlank : true, // must be filled in as we rely on it for login details..
506 inputType: 'password', // << if comment out this input type, it should be ok
511 xtype : 'FieldSetEx',
512 name: 'project_id_fs',
516 style: 'width:420px;',
517 legend : "Always File Messages from this Person in Project",
519 Pman.Std.project_id({
521 fieldLabel : "Project",
526 name : 'action_type_str',
528 qtip : "Action Type",
529 fieldLabel : "Action Required",
535 store: new Ext.data.SimpleStore({
537 fields: [ 'code', 'desc' ],
538 data: [[ 'ACTION_REQUIRED', "Yes"] , [ 'NOTIFY', "No"] ]
543 hiddenName: 'action_type',
544 value : 'ACTION_REQUIRED',
545 forceSelection: true,
548 // queryParam: 'query[project]',
549 // loadingText: "Searching...",
558 id : { name : 'id', value : '', xtype : 'Hidden' },
559 save_send : { name : '_save_send', value : 0, xtype : 'Hidden' },
560 active : { name : 'active', value : 1, xtype : 'Hidden' },
561 company_id : { name : 'company_id', value : '', xtype : 'Hidden' },
562 company_id_email : { name : 'company_id_email', value : '', xtype : 'Hidden' },
563 company_id_address : { name : 'company_id_address', value : '', xtype : 'Hidden' },
564 company_id_tel : { name : 'company_id_tel', value : '', xtype : 'Hidden' },
565 company_id_fax : { name : 'company_id_fax', value : '', xtype : 'Hidden' },
566 project_id_addto : { name : 'project_id_addto', value : '', xtype : 'Hidden' }
569 }, //end getItemTypes
571 saveSend : function(bt, e)
576 save : function(bt, e, andsend)
578 // ensure a company has been selected..
579 this.sendAfterSave = andsend || 0;
581 if (this.form.findField('bulklist')) {
586 if (this.form.findField('company_id') && !this.form.findField('company_id').getValue()) {
587 Ext.MessageBox.alert("Error", "Select a Company");
591 if (this.form.findField('passwd1')) {
593 var p1 = this.form.findField('passwd1').getValue();
594 var p2 = this.form.findField('passwd2').getValue();
596 if (this.sendAfterSave && !p1.length) {
597 Ext.MessageBox.alert("Error", "You must create a password to send introduction mail");
601 if (Pman.Login.authUser.id < 0 && !p1.length) {
602 Ext.MessageBox.alert("Error", "You must create a password for the admin account");
607 if (p1.length || p2.length) {
609 Ext.MessageBox.alert("Error", "Passwords do not match");
616 // ensure it's blank!
617 if (this.form.findField('project_id')) {
618 if (!this.form.findbyId('project_id_fs').expanded) {
619 this.form.findField('project_id').setFromData({
625 this.dialog.el.mask("Sending");
626 this.form.doAction('submit', {
627 url: baseURL + '/Roo/Person.html',
638 show: function (data, callback)
641 this.callback = callback;
648 this.dialog.el.mask("Loading");
649 this.form.doAction('load', {
650 url: baseURL + '/Roo/Person.html',
657 // this.fireEvent('show');
661 this.form.setValues(data);
663 this.form.fireEvent('actioncomplete', this.form,{
669 // no need to load...
673 saveBulk: function() {
674 // similar action to SendIntro
675 // we build a fake list of data..
676 if (!this.form.findField('company_id').getValue()) {
677 Roo.MessageBox.alert("Error", "Select the Company Name");
684 Roo.MessageBox.confirm("Send Welcome", "Send Welcome Messages and Generate Passwords?",
691 Roo.each(_this.form.findField('bulklist').getValue().split("\n"), function(v) {
692 if (!v.length || !v.replace(new RegExp(' ', 'g'), '').length) {
698 company_id : _this.form.findField('company_id').getValue(),
699 office_id : _this.form.findField('office_id').getValue(),
707 Roo.MessageBox.alert("Error", "No addresses found");
711 _this.sendIntro(adr, "Creating Account / Sending Welcome", _this.callback)
723 sendIntro : function(ar, msg, callback) {
724 // can hanlde multiple items -- will be usefull for later usage
725 // when we do list of multiple users..
728 Roo.MessageBox.show({
729 title: "Please wait...",
736 //this.sendData = ar; console.log(ar);
738 var wis = function ()
740 if (i == ar.length) {
741 Roo.MessageBox.hide();
742 Roo.MessageBox.alert("Done", "Done - " + msg);
744 callback.call(this, false);
748 Roo.MessageBox.updateProgress(
749 (i+1)/ar.length, msg + " : " + ar[i].email
756 url : baseURL+'/Core/SendIntro.html',
759 success : function(resp, opts) {
764 Roo.MessageBox.show({
765 title: "Please wait...",
771 // error condition!?!?