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/Companies.html',
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: 'query[name]',
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) {
539 xtype : 'FieldSetEx',
540 name: 'project_id_fs',
544 style: 'width:420px;',
545 legend : "Always File Messages from this Person in Project",
547 Pman.Std.project_id({
549 fieldLabel : "Project",
554 name : 'action_type_str',
556 qtip : "Action Type",
557 fieldLabel : "Action Required",
563 store: new Ext.data.SimpleStore({
565 fields: [ 'code', 'desc' ],
566 data: [[ 'ACTION_REQUIRED', "Yes"] , [ 'NOTIFY', "No"] ]
571 hiddenName: 'action_type',
572 value : 'ACTION_REQUIRED',
573 forceSelection: true,
576 // queryParam: 'query[project]',
577 // loadingText: "Searching...",
586 id : { name : 'id', value : '', xtype : 'Hidden' },
587 save_send : { name : '_save_send', value : 0, xtype : 'Hidden' },
588 active : { name : 'active', value : 1, xtype : 'Hidden' },
589 company_id : { name : 'company_id', value : '', xtype : 'Hidden' },
590 company_id_email : { name : 'company_id_email', value : '', xtype : 'Hidden' },
591 company_id_address : { name : 'company_id_address', value : '', xtype : 'Hidden' },
592 company_id_tel : { name : 'company_id_tel', value : '', xtype : 'Hidden' },
593 company_id_fax : { name : 'company_id_fax', value : '', xtype : 'Hidden' },
594 project_id_addto : { name : 'project_id_addto', value : '', xtype : 'Hidden' }
597 }, //end getItemTypes
599 saveSend : function(bt, e)
604 save : function(bt, e, andsend)
606 // ensure a company has been selected..
607 this.sendAfterSave = andsend || 0;
609 if (this.form.findField('bulklist')) {
614 if (this.form.findField('company_id') && !this.form.findField('company_id').getValue()) {
615 Ext.MessageBox.alert("Error", "Select a Company");
619 if (this.form.findField('passwd1')) {
621 var p1 = this.form.findField('passwd1').getValue();
622 var p2 = this.form.findField('passwd2').getValue();
624 if (this.sendAfterSave && !p1.length) {
625 Ext.MessageBox.alert("Error", "You must create a password to send introduction mail");
629 if (Pman.Login.authUser.id < 0 && !p1.length) {
630 Ext.MessageBox.alert("Error", "You must create a password for the admin account");
635 if (p1.length || p2.length) {
637 Ext.MessageBox.alert("Error", "Passwords do not match");
644 // ensure it's blank!
645 if (this.form.findField('project_id')) {
646 if (!this.form.findbyId('project_id_fs').expanded) {
647 this.form.findField('project_id').setFromData({
653 this.dialog.el.mask("Sending");
654 this.form.doAction('submit', {
655 url: baseURL + '/Roo/Person.html',
666 show: function (data, callback)
669 this.callback = callback;
676 this.dialog.el.mask("Loading");
677 this.form.doAction('load', {
678 url: baseURL + '/Roo/Person.html',
685 // this.fireEvent('show');
689 this.form.setValues(data);
691 this.form.fireEvent('actioncomplete', this.form,{
697 // no need to load...
701 saveBulk: function() {
702 // similar action to SendIntro
703 // we build a fake list of data..
704 if (!this.form.findField('company_id').getValue()) {
705 Roo.MessageBox.alert("Error", "Select the Company Name");
712 Roo.MessageBox.confirm("Send Welcome", "Send Welcome Messages and Generate Passwords?",
719 Roo.each(_this.form.findField('bulklist').getValue().split("\n"), function(v) {
720 if (!v.length || !v.replace(new RegExp(' ', 'g'), '').length) {
726 company_id : _this.form.findField('company_id').getValue(),
727 office_id : _this.form.findField('office_id').getValue(),
735 Roo.MessageBox.alert("Error", "No addresses found");
739 _this.sendIntro(adr, "Creating Account / Sending Welcome", _this.callback)
751 sendIntro : function(ar, msg, callback) {
752 // can hanlde multiple items -- will be usefull for later usage
753 // when we do list of multiple users..
756 Roo.MessageBox.show({
757 title: "Please wait...",
764 //this.sendData = ar; console.log(ar);
766 var wis = function ()
768 if (i == ar.length) {
769 Roo.MessageBox.hide();
770 Roo.MessageBox.alert("Done", "Done - " + msg);
772 callback.call(this, false);
776 Roo.MessageBox.updateProgress(
777 (i+1)/ar.length, msg + " : " + ar[i].email
784 url : baseURL+'/Core/SendIntro.html',
787 success : function(resp, opts) {
792 Roo.MessageBox.show({
793 title: "Please wait...",
799 // error condition!?!?