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;
144 Roo.log(_this.form.findField('passwd1').allowBlank);
148 if (act.type == 'submit') { // only submitted here if we are
153 if (_this.callback) {
154 _this.callback.call(this, act.result.data);
156 if (_this.sendAfterSave) {
157 act.result.data.rawPasswd = _this.form.findField('passwd1').getValue();
158 _this.sendIntro([ act.result.data ], "Sending Welcome Message");
169 this.loadItemTypes();
170 Roo.each(this.itemList, function(il) {
171 if (typeof(il) != 'object') {
172 _this.form.addxtype(_this.itemTypes[il]);
175 _this.form.addxtype(Roo.apply(il, _this.itemTypes[il.name]));
178 var ef = this.dialog.getLayout().getEl().createChild({tag: 'div'});
179 ef.dom.style.margin = 10;
181 this.form.render(ef.dom);
183 var vp = this.dialog.getLayout().add('center', new Ext.ContentPanel(ef, {
185 //title: 'Org Details',
195 this.layout.endUpdate();
201 loadItemTypes : function()
205 company_id_name_ro : {
206 name : 'company_id_name',
207 fieldLabel : "Company",
216 xtype: 'ComboBoxAdder',
217 fieldLabel: "Company",
218 name : 'company_id_name',
220 qtip : "Select Company",
229 url: baseURL + '/Roo/Companies.html',
232 reader: Pman.Readers.Companies,
234 beforeload : function(st,o)
237 o.params['!comptype'] = 'OWNER';
239 loadexception : Pman.loadException
243 field: 'name', direction: 'ASC'
248 hiddenName: 'company_id',
250 forceSelection: true,
252 triggerAction: 'all',
253 tpl: new Ext.Template(
254 '<div class="x-grid-cell-text x-btn button">',
255 '<b>{name}</b> {address}',
258 queryParam: 'query[name]',
259 loadingText: "Searching...",
265 adderclick : function()
268 Pman.Dialog.CoreCompanies.show( { id: 0 }, function(data) {
269 cb.setFromData(data);
278 office_id_name_ro : {
279 name : 'office_id_name',
280 fieldLabel : "Office",
289 xtype: 'ComboBoxAdder',
290 fieldLabel: "Office / Department",
291 name : 'office_id_name',
293 qtip : "Select Office",
302 url: baseURL + '/Roo/Office.html',
305 reader: Pman.Readers.Office,
307 beforeload : function(st,o)
309 // compnay myst be set..
310 var coid = _this.form.findField('company_id').getValue();
311 o.params.company_id = coid;
313 loadexception : Pman.loadException
317 field: 'name', direction: 'ASC'
321 adderclick : function()
328 if (_this.type == 'new') {
329 data = _this.form.findField('company_id').lastData;
331 Ext.MessageBox.alert("Error", "Select An Company First");
336 company_id : data.id ,
337 company_id_name: data.name,
338 address: data.address,
344 } else { // all other tyeps have the data in the caller data array.
347 company_id : data.company_id,
348 company_id_name: data.company_id_name,
349 address: data.company_id_address,
350 phone: data.company_id_tel,
351 fax: data.company_id_fax,
352 email: data.company_id_email
359 Pman.Dialog.Office.show(cfg, function(data) {
360 cb.setFromData(data);
363 beforequery : function (qe) {
364 var coid = _this.form.findField('company_id').getValue();
366 Ext.MessageBox.alert("Error", "Select An Company First");
373 hiddenName: 'office_id',
375 forceSelection: true,
377 triggerAction: 'all',
378 tpl: new Ext.Template(
379 '<div class="x-grid-cell-text x-btn button">',
380 '<b>{name}</b> {address}',
383 queryParam: 'query[name]',
384 loadingText: "Searching...",
394 fieldLabel : "Contact Name",
403 fieldLabel : "Role / Position",
406 qtip : "Enter Role / Position",
413 fieldLabel : "Phone",
416 qtip : "Enter phone Number",
432 fieldLabel : "Email",
435 qtip : "Enter email",
441 fieldLabel : "Email address (one per line)",
444 qtip : "Enter email addresse",
453 fieldLabel : "Email",
456 qtip : "Enter email",
462 fieldLabel : "New Password ",
464 allowBlank : true, // must be filled in as we rely on it for login details..
465 inputType: 'password',
466 xtype : 'SecurePass',
468 imageRoot : rootURL + '/Pman/templates/images'
473 fieldLabel : "Password (type again to confirm)",
475 allowBlank : true, // must be filled in as we rely on it for login details..
476 inputType: 'password',
481 xtype : 'FieldSetEx',
482 name: 'project_id_fs',
486 style: 'width:420px;',
487 legend : "Always File Messages from this Person in Project",
489 Pman.Std.project_id({
491 fieldLabel : "Project",
496 name : 'action_type_str',
498 qtip : "Action Type",
499 fieldLabel : "Action Required",
505 store: new Ext.data.SimpleStore({
507 fields: [ 'code', 'desc' ],
508 data: [[ 'ACTION_REQUIRED', "Yes"] , [ 'NOTIFY', "No"] ]
513 hiddenName: 'action_type',
514 value : 'ACTION_REQUIRED',
515 forceSelection: true,
518 // queryParam: 'query[project]',
519 // loadingText: "Searching...",
528 id : { name : 'id', value : '', xtype : 'Hidden' },
529 save_send : { name : '_save_send', value : 0, xtype : 'Hidden' },
530 active : { name : 'active', value : 1, xtype : 'Hidden' },
531 company_id : { name : 'company_id', value : '', xtype : 'Hidden' },
532 company_id_email : { name : 'company_id_email', value : '', xtype : 'Hidden' },
533 company_id_address : { name : 'company_id_address', value : '', xtype : 'Hidden' },
534 company_id_tel : { name : 'company_id_tel', value : '', xtype : 'Hidden' },
535 company_id_fax : { name : 'company_id_fax', value : '', xtype : 'Hidden' },
536 project_id_addto : { name : 'project_id_addto', value : '', xtype : 'Hidden' }
539 }, //end getItemTypes
541 saveSend : function(bt, e)
546 save : function(bt, e, andsend)
548 // ensure a company has been selected..
549 this.sendAfterSave = andsend || 0;
551 if (this.form.findField('bulklist')) {
556 if (this.form.findField('company_id') && !this.form.findField('company_id').getValue()) {
557 Ext.MessageBox.alert("Error", "Select a Company");
561 if (this.form.findField('passwd1')) {
563 var p1 = this.form.findField('passwd1').getValue();
564 var p2 = this.form.findField('passwd2').getValue();
566 if (this.sendAfterSave && !p1.length) {
567 Ext.MessageBox.alert("Error", "You must create a password to send introduction mail");
571 if (Pman.Login.authUser.id < 0 && !p1.length) {
572 Ext.MessageBox.alert("Error", "You must create a password for the admin account");
577 if (p1.length || p2.length) {
579 Ext.MessageBox.alert("Error", "Passwords do not match");
586 // ensure it's blank!
587 if (this.form.findField('project_id')) {
588 if (!this.form.findbyId('project_id_fs').expanded) {
589 this.form.findField('project_id').setFromData({
595 this.dialog.el.mask("Sending");
596 this.form.doAction('submit', {
597 url: baseURL + '/Roo/Person.html',
608 show: function (data, callback)
611 this.callback = callback;
618 this.dialog.el.mask("Loading");
619 this.form.doAction('load', {
620 url: baseURL + '/Roo/Person.html',
627 // this.fireEvent('show');
631 this.form.setValues(data);
633 this.form.fireEvent('actioncomplete', this.form,{
639 // no need to load...
643 saveBulk: function() {
644 // similar action to SendIntro
645 // we build a fake list of data..
646 if (!this.form.findField('company_id').getValue()) {
647 Roo.MessageBox.alert("Error", "Select the Company Name");
654 Roo.MessageBox.confirm("Send Welcome", "Send Welcome Messages and Generate Passwords?",
661 Roo.each(_this.form.findField('bulklist').getValue().split("\n"), function(v) {
662 if (!v.length || !v.replace(new RegExp(' ', 'g'), '').length) {
668 company_id : _this.form.findField('company_id').getValue(),
669 office_id : _this.form.findField('office_id').getValue(),
677 Roo.MessageBox.alert("Error", "No addresses found");
681 _this.sendIntro(adr, "Creating Account / Sending Welcome", _this.callback)
693 sendIntro : function(ar, msg, callback) {
694 // can hanlde multiple items -- will be usefull for later usage
695 // when we do list of multiple users..
698 Roo.MessageBox.show({
699 title: "Please wait...",
706 //this.sendData = ar; console.log(ar);
708 var wis = function ()
710 if (i == ar.length) {
711 Roo.MessageBox.hide();
712 Roo.MessageBox.alert("Done", "Done - " + msg);
714 callback.call(this, false);
718 Roo.MessageBox.updateProgress(
719 (i+1)/ar.length, msg + " : " + ar[i].email
726 url : baseURL+'/Core/SendIntro.html',
729 success : function(resp, opts) {
734 Roo.MessageBox.show({
735 title: "Please wait...",
741 // error condition!?!?