PersonExplorer.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. // MWF.xDesktop.requireApp("Organization", "GroupExplorer", null, false);
  2. // MWF.xDesktop.requireApp("Organization", "OrgExplorer", null, false);
  3. MWF.xDesktop.requireApp("Org", "$Explorer", null, false);
  4. MWF.require("MWF.widget.O2Identity", null, false);
  5. MWF.xApplication.Org.PersonExplorer = new Class({
  6. Extends: MWF.xApplication.Org.$Explorer,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default"
  10. },
  11. _isActionManager: function(){
  12. return (MWF.AC.isOrganizationManager() || MWF.AC.isPersonManager() || MWF.AC.isUnitManager());
  13. },
  14. _listElementNext: function(lastid, count, callback){
  15. this.actions.listPersonNext(lastid||"(0)", count, function(json){
  16. if (callback) {
  17. callback.apply(this, [json]);
  18. }
  19. }.bind(this));
  20. },
  21. _newElement: function(data, explorer, i){
  22. return new MWF.xApplication.Org.PersonExplorer.Person(data, explorer, this.isEditor, i);
  23. },
  24. _listElementByKey: function(callback, failure, key){
  25. //this.actions.listPersonByPinyin(function(json){
  26. this.actions.listPersonByKey(function(json){
  27. if (callback) {
  28. callback.apply(this, [json]);
  29. }
  30. }.bind(this), failure, key);
  31. },
  32. _getAddElementData: function(){
  33. return {
  34. "genderType": "m",
  35. "signature": "",
  36. "description": "",
  37. "unique": "",
  38. "orderNumber": "",
  39. "superior": "",
  40. "officePhone": "",
  41. "boardDate": "",
  42. "birthday": "",
  43. "employee": "",
  44. "password": "",
  45. "display": "",
  46. "qq": "",
  47. "mail": "",
  48. "weixin": "",
  49. "weibo": "",
  50. "mobile": "",
  51. "name": "",
  52. "controllerList": [],
  53. "woPersonAttributeList":[],
  54. "woIdentityList": [],
  55. "control": {
  56. "allowEdit": true,
  57. "allowDelete": true
  58. }
  59. };
  60. }
  61. });
  62. MWF.xApplication.Org.PersonExplorer.Person = new Class({
  63. Extends: MWF.xApplication.Org.$Explorer.Item,
  64. showItemProperty: function(){
  65. this.content = new MWF.xApplication.Org.PersonExplorer.PersonContent(this);
  66. },
  67. _loadTextNode: function(){
  68. var html = "<div style='float:left; height:50px; overflow:hidden'>"+this.data.name+"</div>";
  69. html += "<div style='float: right; overflow:hidden; font-size: 12px; color: #aaaaaa;'>"+(this.data.mobile || "")+"</div>";
  70. this.textNode.set({"html": html});
  71. },
  72. "delete": function(success, failure){
  73. this.explorer.actions.deletePerson(this.data.id, function(){
  74. this.destroy();
  75. if (success) success();
  76. }.bind(this), function(xhr, text, error){
  77. var errorText = error;
  78. if (xhr) errorText = xhr.responseText;
  79. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  80. if (failure) failure();
  81. });
  82. },
  83. _getIcon: function(nocache){
  84. var url = (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "/x_component_Org/$Explorer/default/icon/man.png";
  85. return (nocache) ? url+"?"+(new Date().getTime()) : url;
  86. //return (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "/x_component_Org/$Explorer/default/icon/man.png";
  87. // var src = "data:image/png;base64,"+this.data.icon;
  88. // if (!this.data.icon){
  89. // if (this.data.genderType==="f"){
  90. // src = "/x_component_Org/$Explorer/default/icon/female24.png"
  91. // }else{
  92. // src = "/x_component_Org/$Explorer/default/icon/man24.png"
  93. // }
  94. // }
  95. // return src;
  96. }
  97. });
  98. MWF.xApplication.Org.PersonExplorer.PersonContent = new Class({
  99. Extends: MWF.xApplication.Org.$Explorer.ItemContent,
  100. _getData: function(callback){
  101. if (this.item.data.id){
  102. this.explorer.actions.getPerson(function(json){
  103. this.data = json.data;
  104. this.item.data = json.data;
  105. if (callback) callback();
  106. }.bind(this), null, this.item.data.id);
  107. }else{
  108. this.data = this.item.data;
  109. if (callback) callback();
  110. }
  111. },
  112. edit: function(){
  113. if (this.baseInfor) this.baseInfor.edit();
  114. },
  115. _showItemPropertyTitle: function(){
  116. this.titleInfor = new MWF.xApplication.Org.PersonExplorer.PersonContent.TitleInfor(this);
  117. //this.baseInfor = new MWF.xApplication.Org.BaseInfor(this);
  118. },
  119. _showItemPropertyBottom: function(){
  120. this.bottomInfor = new MWF.xApplication.Org.PersonExplorer.PersonContent.BottomInfor(this);
  121. },
  122. _loadTabs: function(){
  123. this.baseContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  124. this.basePage = this.propertyTab.addTab(this.baseContentNode, this.explorer.app.lp.personBaseText);
  125. this.attributeContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  126. this.attributePage = this.propertyTab.addTab(this.attributeContentNode, this.explorer.app.lp.personAttributeText);
  127. this.identityContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  128. this.identityPage = this.propertyTab.addTab(this.identityContentNode, this.explorer.app.lp.personIdentityText);
  129. // this.managerContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  130. // this.managerPage = this.propertyTab.addTab(this.managerContentNode, this.explorer.app.lp.controllerListText);
  131. },
  132. _loadContent: function(){
  133. this._listBaseInfor();
  134. this._listAttribute();
  135. this._listIdentity();
  136. this.loadListCount();
  137. //
  138. // this.showAttribute();
  139. },
  140. loadListCount: function(){
  141. if (this.data.woIdentityList){
  142. var identityCount = this.data.woIdentityList.length;
  143. if (identityCount){
  144. if (!this.identityCountNode){
  145. this.identityCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": identityCount}).inject(this.identityPage.tabNode);
  146. }else{
  147. this.identityCountNode.set("text", identityCount);
  148. }
  149. }else{
  150. if (this.identityCountNode) this.identityCountNode.destroy();
  151. }
  152. }
  153. if (this.data.woPersonAttributeList){
  154. var attributeCount = this.data.woPersonAttributeList.length;
  155. if (attributeCount){
  156. if (!this.attributeCountNode){
  157. this.attributeCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": attributeCount}).inject(this.attributePage.tabNode);
  158. }else{
  159. this.attributeCountNode.set("text", attributeCount);
  160. }
  161. }else{
  162. if (this.attributeCountNode) this.attributeCountNode.destroy();
  163. }
  164. }
  165. // var groupCount = this.data.groupList.length;
  166. // if (groupCount){
  167. // this.groupCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": groupCount}).inject(this.groupMemberPage.tabNode);
  168. // }
  169. },
  170. _listBaseInfor: function(){
  171. this.baseInfor = new MWF.xApplication.Org.PersonExplorer.PersonContent.BaseInfor(this);
  172. },
  173. _listAttribute: function(){
  174. this.attributeList = new MWF.xApplication.Org.List(this.attributeContentNode, this, {
  175. "action": this.data.control.allowEdit,
  176. "data": {
  177. "person": this.data.id,
  178. "name": "",
  179. "unique": "",
  180. "orderNumber": "",
  181. "attributeList": [],
  182. "description":""
  183. },
  184. "attr": ["name", {
  185. "get": function(){return this.attributeList.join(",")},
  186. "set": function(value){this.attributeList = value.split(/,\s*/g)}
  187. }, "description"],
  188. "onPostSave": function(item, id){
  189. if (!item.data.id){
  190. item.data.id = id;
  191. this.data.woPersonAttributeList.push(item.data);
  192. }
  193. this.loadListCount();
  194. // if (!item.data.id){
  195. // if (this.attributeCountNode){
  196. // var count = this.attributeCountNode.get("text").toInt()+1;
  197. // this.attributeCountNode.set("text", count);
  198. // }
  199. // }
  200. }.bind(this),
  201. "onPostDelete": function(delCount){
  202. if (this.attributeCountNode){
  203. var count = this.attributeCountNode.get("text").toInt()-delCount;
  204. this.attributeCountNode.set("text", count);
  205. }
  206. }.bind(this)
  207. });
  208. this.attributeList.load([
  209. {"style": "width: 20%", "text": this.explorer.app.lp.attributeName},
  210. {"style": "", "text": this.explorer.app.lp.attributeValue},
  211. {"style": "", "text": this.explorer.app.lp.description}
  212. ]);
  213. this.data.woPersonAttributeList.each(function(item){
  214. this.attributeList.push(item);
  215. }.bind(this));
  216. // if (this.data.id){
  217. // this.explorer.actions.listPersonAttribute(function(json){
  218. //
  219. // var attributeCount = json.data.length;
  220. // if (attributeCount){
  221. // this.attributeCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": attributeCount}).inject(this.attributePage.tabNode);
  222. // }
  223. //
  224. // json.data.each(function(item){
  225. // //this.attributes.push(new MWF.xApplication.Org.PersonExplorer.PersonAttribute(this.attributeTabContentNode.getElement("table").getFirst(), item, this, this.explorer.css.list));
  226. // this.attributeList.push(item);
  227. // }.bind(this));
  228. // }.bind(this), null, this.data.id);
  229. // }
  230. },
  231. _listIdentity: function(){
  232. var _self = this;
  233. this.identityList = new MWF.xApplication.Org.List(this.identityContentNode, this, {
  234. "action": false,
  235. "canEdit": false,
  236. "saveAction": "saveIdentity",
  237. "data": {
  238. "person": this.data.id,
  239. "name": "",
  240. "attributeList": []
  241. },
  242. "attr": ["name", {
  243. "get": function(){ return ""; },
  244. "events": {
  245. "init": function(){
  246. var contentNode = this.td;
  247. new MWF.widget.O2Unit(this.data.woUnit, contentNode, {"style": "xform"});
  248. }
  249. }
  250. }, {
  251. "get": function(){ return this.distinguishedName; },
  252. "set": function(value){ this.distinguishedName = value; }
  253. }, {
  254. "get": function(){ return ""; },
  255. "events": {
  256. "init": function(){
  257. var contentNode = this.td;
  258. if (this.data.woUnitDutyList){
  259. this.data.woUnitDutyList.each(function(duty){
  260. new MWF.widget.O2Duty(duty, contentNode, {"style": "xform"});
  261. }.bind(this));
  262. }
  263. }
  264. }
  265. }, {
  266. "getHtml": function(){
  267. if (this.major){
  268. return "<div style='width:24px; height:24px; background:url(/x_component_Org/$Explorer/"+
  269. _self.explorer.app.options.style+"/icon/mainid.png) center center no-repeat'></div>";
  270. }else{
  271. return "<div title='"+_self.explorer.app.lp.setIdentityMain+"' style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  272. _self.explorer.app.options.style+"/icon/select.png) center center no-repeat'></div>";
  273. }
  274. },
  275. "events": {
  276. "click": function(){
  277. if (!this.data.major){
  278. if (_self.data.control.allowEdit){_self.setMainIdentity(this.data, this.td, this.item);}
  279. }
  280. }
  281. }
  282. },{
  283. "getHtml": function(){
  284. if (_self.data.control.allowEdit){
  285. return "<div style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  286. _self.explorer.app.options.style+"/icon/edit.png) center center no-repeat'></div>";
  287. }
  288. return "";
  289. },
  290. "events": {
  291. "click": function(){
  292. debugger;
  293. if (_self.data.control.allowEdit){_self.editIdentity(this.data, this.td, this.item);}
  294. }
  295. }
  296. }]
  297. });
  298. this.identityList.load([
  299. {"style": "width: 12%", "text": this.explorer.app.lp.IdentityName},
  300. {"style": "width: 12%", "text": this.explorer.app.lp.IdentityInUnit},
  301. {"style": "width: 44%", "text": this.explorer.app.lp.personUnique},
  302. {"style": "width: 20%", "text": this.explorer.app.lp.IdentityDuty},
  303. {"style": "width: 10%", "text": this.explorer.app.lp.IdentityMain},
  304. {"style": "width: 30px", "text": ""}
  305. ]);
  306. this.data.woIdentityList.each(function(item){
  307. this.identityList.push(item);
  308. }.bind(this));
  309. },
  310. setMainIdentity: function(data, node, item){
  311. data.major = true;
  312. this.explorer.actions.saveIdentity(data, function(json){
  313. this.explorer.actions.getPerson(function(iJson){
  314. // data = iJson.data;
  315. // item.reload(iJson.data);
  316. this.data.woIdentityList = iJson.data.woIdentityList;
  317. this.identityList.clear();
  318. this.data.woIdentityList.each(function(item){
  319. this.identityList.push(item);
  320. }.bind(this));
  321. }.bind(this), null, this.data.id);
  322. }.bind(this));
  323. },
  324. editIdentity: function(data, node, item){
  325. var _self = this;
  326. var position = node.getPosition(this.explorer.app.content);
  327. var width = 700;
  328. var height = 170;
  329. var size = this.explorer.app.content.getSize();
  330. var x = (size.x-width)/2;
  331. var y = (size.y-height)/2;
  332. if (x<0) x = 0;
  333. if (y<20) y = 20;
  334. MWF.require("MWF.xDesktop.Dialog", function() {
  335. var dlg = new MWF.xDesktop.Dialog({
  336. "title": this.explorer.app.lp.modifyIdentity,
  337. "style": "org",
  338. "top": y - 20,
  339. "left": x,
  340. "fromTop": position.y - 20,
  341. "fromLeft": position.x,
  342. "width": width,
  343. "height": height,
  344. "html": "<div></div>",
  345. "maskNode": this.explorer.app.content,
  346. "container": this.explorer.app.content,
  347. "buttonList": [
  348. {
  349. "text": MWF.LP.process.button.ok,
  350. "action": function () {
  351. _self.saveIdentity(dlg, data, item);
  352. this.close();
  353. }
  354. },
  355. {
  356. "text": MWF.LP.process.button.cancel,
  357. "action": function () {
  358. this.close();
  359. }
  360. }
  361. ]
  362. });
  363. dlg.show();
  364. var node = dlg.content.getFirst();
  365. var html = "<table width='90%' cellpadding='0px' cellspacing='5px' align='center' style='margin-top:10px'>" +
  366. "<tr><th width='30%'>"+this.explorer.app.lp.IdentityName+"</th><th>"+this.explorer.app.lp.personUnique+"</th><th>"+this.explorer.app.lp.IdentityMain+"</th></tr>" +
  367. "<tr><td style='text-align: center'><input value='' type='type' style='padding: 0px 3px; width: 95%; border: 1px solid #cccccc; height: 24px; border-radius: 3px; line-height: 24px;'/></td>" +
  368. "<td style='text-align: center'><input value='' type='type' style='padding: 0px 3px; width: 95%; border: 1px solid #cccccc; height: 24px; border-radius: 3px; line-height: 24px;'/></td>" +
  369. "<td style='text-align: center'><input value='yes' type='checkbox' "+((data.major) ? "checked" : "")+"/></td></tr></table>";
  370. node.set("html", html);
  371. var inputs = node.getElements("input");
  372. if (inputs[0]) inputs[0].set("value", data.name);
  373. if (inputs[1]) inputs[1].set("value", data.unique);
  374. //if (inputs[2]) inputs[2].set("value", data.major)
  375. }.bind(this));
  376. },
  377. saveIdentity: function(dlg, data, item){
  378. var node = dlg.content.getFirst();
  379. var inputs = node.getElements("input");
  380. var name = inputs[0].get("value");
  381. var unique = inputs[1].get("value");
  382. var major = (inputs[2].checked);
  383. if (data.name!==name || data.unique!==unique){
  384. if (name) data.name = name;
  385. data.unique=unique;
  386. data.major = major;
  387. this.explorer.actions.saveIdentity(data, function(json){
  388. this.explorer.actions.getPerson(function(iJson){
  389. // data = iJson.data;
  390. // item.reload(iJson.data);
  391. this.data.woIdentityList = iJson.data.woIdentityList;
  392. this.identityList.clear();
  393. this.data.woIdentityList.each(function(item){
  394. this.identityList.push(item);
  395. }.bind(this));
  396. }.bind(this), null, this.data.id);
  397. }.bind(this));
  398. }
  399. }
  400. });
  401. MWF.xApplication.Org.PersonExplorer.PersonContent.TitleInfor = new Class({
  402. Extends: MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor,
  403. loadAction: function(){
  404. //this.explorer.app.lp.edit
  405. this.nameNode.setStyle("margin-right", "80px");
  406. if (MWF.AC.isOrganizationManager() || MWF.AC.isPersonManager()){
  407. this.resetPasswordAction = new Element("div", {"styles": this.style.titleInforResetPasswordNode, "text": this.item.explorer.app.lp.resetPassword}).inject(this.nameNode, "before");
  408. this.resetPasswordAction.addEvent("click", function(e){this.resetPassword(e);}.bind(this));
  409. }
  410. if (this.data.control.allowEdit){
  411. this.iconNode.setStyle("cursor", "pointer");
  412. this.iconNode.addEvent("click", function(){this.changePersonIcon();}.bind(this));
  413. }
  414. },
  415. resetPassword: function(e){
  416. var _self = this;
  417. var text = this.item.explorer.app.lp.resetPasswordText;
  418. text = text.replace("{name}", this.data.name);
  419. this.item.explorer.app.confirm("info", e, this.item.explorer.app.lp.resetPasswordTitle, text, "360", "120", function(){
  420. _self.doResetPassword();
  421. this.close();
  422. }, function(){
  423. this.close();
  424. });
  425. },
  426. doResetPassword: function(){
  427. var action = MWF.Actions.get("x_organization_assemble_control");
  428. action.resetPassword(this.data.id, function(){
  429. var text = this.item.explorer.app.lp.resetPasswordSuccess;
  430. text = text.replace("{name}", this.data.name);
  431. this.item.explorer.app.notice(text, "success");
  432. }.bind(this));
  433. },
  434. changePersonIcon: function(){
  435. var options = {};
  436. var width = "668";
  437. var height = "510";
  438. width = width.toInt();
  439. height = height.toInt();
  440. var size = this.explorer.app.content.getSize();
  441. var x = (size.x-width)/2;
  442. var y = (size.y-height)/2;
  443. if (x<0) x = 0;
  444. if (y<0) y = 0;
  445. if (layout.mobile){
  446. x = 20;
  447. y = 0;
  448. }
  449. var _self = this;
  450. MWF.require("MWF.xDesktop.Dialog", function() {
  451. MWF.require("MWF.widget.ImageClipper", function(){
  452. var dlg = new MWF.xDesktop.Dialog({
  453. "title": this.explorer.app.lp.changePersonIcon,
  454. "style": "image",
  455. "top": y,
  456. "left": x - 20,
  457. "fromTop": y,
  458. "fromLeft": x - 20,
  459. "width": width,
  460. "height": height,
  461. "html": "<div></div>",
  462. "maskNode": this.explorer.app.content,
  463. "container": this.explorer.app.content,
  464. "buttonList": [
  465. {
  466. "text": MWF.LP.process.button.ok,
  467. "action": function () {
  468. _self.uploadPersonIcon();
  469. this.close();
  470. }
  471. },
  472. {
  473. "text": MWF.LP.process.button.cancel,
  474. "action": function () {
  475. _self.image = null;
  476. this.close();
  477. }
  478. }
  479. ]
  480. });
  481. dlg.show();
  482. this.image = new MWF.widget.ImageClipper(dlg.content.getFirst(), {
  483. "aspectRatio": 1,
  484. "description" : "",
  485. "imageUrl" : this._getIcon(true),
  486. "resetEnable" : false
  487. });
  488. this.image.load();
  489. }.bind(this));
  490. }.bind(this))
  491. },
  492. uploadPersonIcon: function(){
  493. if (this.image){
  494. if( this.image.getResizedImage() ){
  495. this.explorer.actions.changePersonIcon(this.data.id, this.image.getFormData(), this.image.getResizedImage(), function(){
  496. this.iconNode.set("src", "");
  497. if (this.item.iconNode) this.item.iconNode.getElement("img").set("src", "");
  498. window.setTimeout(function(){
  499. this.iconNode.set("src", this._getIcon(true));
  500. if (this.item.iconNode) this.item.iconNode.getElement("img").set("src", this.item._getIcon(true));
  501. }.bind(this), 100);
  502. }.bind(this), null);
  503. }
  504. }
  505. }
  506. });
  507. MWF.xApplication.Org.PersonExplorer.PersonContent.BottomInfor = new Class({
  508. Extends: MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor,
  509. addInforList: function(){
  510. var text = this.explorer.app.lp.personReadDn.replace(/{dn}/g, (this.data.distinguishedName || " "));
  511. this.addInfor(text);
  512. text = this.explorer.app.lp.personReadCreate.replace(/{date}/g, (this.data.createTime || " "));
  513. text = text.replace(/{date2}/g, (this.data.updateTime || " "));
  514. this.addInfor(text);
  515. text = this.explorer.app.lp.personReadLogin.replace(/{date}/g, (this.data.lastLoginTime || " "));
  516. text = text.replace(/{ip}/g, (this.data.lastLoginAddress || " "));
  517. text = text.replace(/{client}/g, (this.data.lastLoginClient || " "));
  518. this.addInfor(text);
  519. text = this.explorer.app.lp.personReadPassword.replace(/{date}/g, (this.data.passwordExpiredTime || " "));
  520. text = text.replace(/{date2}/g, (this.data.changePasswordTime || " "));
  521. this.addInfor(text);
  522. }
  523. });
  524. MWF.xApplication.Org.PersonExplorer.PersonContent.BaseInfor = new Class({
  525. initialize: function(content){
  526. this.content = content;
  527. this.item = content.item;
  528. this.data = this.content.data;
  529. this.explorer = this.item.explorer;
  530. this.contentNode = this.content.baseContentNode;
  531. this.style = this.item.style.person;
  532. this.attributes = [];
  533. this.mode = "read";
  534. this.load();
  535. },
  536. load: function(){
  537. this.node = new Element("div", {"styles": this.style.baseContentNode}).inject(this.contentNode);
  538. this.editContentNode = new Element("div", {"styles": this.style.baseEditNode}).inject(this.node);
  539. this.editContentNode.set("html", this.getContentHtml());
  540. var n = this.editContentNode.getElement(".infor_name");
  541. if (n) n.set("text", this.data.name || "");
  542. var n = this.editContentNode.getElement(".infor_employee");
  543. if (n) n.set("text", this.data.employee || "");
  544. var n = this.editContentNode.getElement(".infor_mobile");
  545. if (n) n.set("text", this.data.mobile || "");
  546. var n = this.editContentNode.getElement(".infor_unique");
  547. if (n) n.set("text", this.data.unique || "");
  548. var n = this.editContentNode.getElement(".infor_gender");
  549. if (n) n.set("text", this.getGenderType());
  550. var n = this.editContentNode.getElement(".infor_mail");
  551. if (n) n.set("text", this.data.mail || "");
  552. var n = this.editContentNode.getElement(".infor_weixin");
  553. if (n) n.set("text", this.data.weixin || "");
  554. var n = this.editContentNode.getElement(".infor_qq");
  555. if (n) n.set("text", this.data.qq || "");
  556. var n = this.editContentNode.getElement(".infor_officePhone");
  557. if (n) n.set("text", this.data.officePhone || "");
  558. var n = this.editContentNode.getElement(".infor_boardDate");
  559. if (n) n.set("text", this.data.boardDate || "");
  560. var n = this.editContentNode.getElement(".infor_birthday");
  561. if (n) n.set("text", this.data.birthday || "");
  562. this.editContentNode.getElements("td.inforTitle").setStyles(this.style.baseInforTitleNode);
  563. this.editContentNode.getElements("td.inforContent").setStyles(this.style.baseInforContentNode);
  564. this.editContentNode.getElements("td.inforAction").setStyles(this.style.baseInforActionNode);
  565. var tdContents = this.editContentNode.getElements("td.inforContent");
  566. if (this.data.superior) new MWF.widget.O2Person({"name": this.data.superior}, tdContents[5], {"style": "xform"});
  567. this.loadAction();
  568. },
  569. getContentHtml: function(){
  570. var html = "<table width='100%' cellpadding='3px' cellspacing='5px'>";
  571. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personName+":</td><td class='inforContent infor_name'>"+(this.data.name || "")+"</td>" +
  572. "<td class='inforTitle'>"+this.explorer.app.lp.personEmployee+":</td><td class='inforContent infor_employee'>"+(this.data.employee || "")+"</td></tr>";
  573. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personMobile+":</td><td class='inforContent infor_mobile'>"+(this.data.mobile || "")+"</td>" +
  574. "<td class='inforTitle'>"+this.explorer.app.lp.personUnique+":</td><td class='inforContent infor_unique'>"+(this.data.unique || "")+"</td></tr>";
  575. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personGender+":</td><td class='inforContent infor_gender'>"+this.getGenderType()+"</td>" +
  576. "<td class='inforTitle'>"+this.explorer.app.lp.personSuperior+":</td><td class='inforContent'>"+"</td></tr>";
  577. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personMail+":</td><td class='inforContent infor_mail'>"+(this.data.mail || "")+"</td>" +
  578. "<td class='inforTitle'>"+this.explorer.app.lp.personWeixin+":</td><td class='inforContent infor_weixin'>"+(this.data.weixin || "")+"</td></tr>";
  579. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personQQ+":</td><td class='inforContent infor_qq'>"+(this.data.qq || "")+"</td>" +
  580. "<td class='inforTitle'>"+this.explorer.app.lp.personOfficePhone+":</td><td class='inforContent infor_officePhone'>"+(this.data.officePhone || "")+"</td></tr>";
  581. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personBoardDate+":</td><td class='inforContent infor_boardDate'>"+(this.data.boardDate || "")+"</td>" +
  582. "<td class='inforTitle'>"+this.explorer.app.lp.personBirthday+":</td><td class='inforContent infor_birthday'>"+(this.data.birthday || "")+"</td></tr>";
  583. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  584. //this.baseInforRightNode.set("html", html);
  585. return html;
  586. },
  587. loadAction: function(){
  588. //this.explorer.app.lp.edit
  589. var actionAreas = this.editContentNode.getElements("td");
  590. var actionArea = actionAreas[actionAreas.length-1];
  591. if (this.data.control.allowEdit){
  592. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  593. this.editNode = new Element("div", {"styles": this.style.actionEditNode, "text": this.explorer.app.lp.editPerson}).inject(this.baseInforEditActionAreaNode);
  594. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.savePerson}).inject(this.baseInforEditActionAreaNode);
  595. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  596. this.editNode.setStyle("display", "block");
  597. this.editNode.addEvent("click", this.edit.bind(this));
  598. this.saveNode.addEvent("click", this.save.bind(this));
  599. this.cancelNode.addEvent("click", this.cancel.bind(this));
  600. }else{
  601. }
  602. },
  603. edit: function(){
  604. var tdContents = this.editContentNode.getElements("td.inforContent");
  605. tdContents[0].setStyles(this.style.baseInforContentNode_edit).empty();
  606. this.nameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[0]);
  607. this.nameInputNode.set("value", (this.data.name));
  608. tdContents[1].setStyles(this.style.baseInforContentNode_edit).empty();
  609. this.employeeInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[1]);
  610. this.employeeInputNode.set("value", (this.data.employee));
  611. tdContents[2].setStyles(this.style.baseInforContentNode_edit).empty();
  612. this.mobileInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[2]);
  613. this.mobileInputNode.set("value", (this.data.mobile));
  614. tdContents[3].setStyles(this.style.baseInforContentNode_edit).empty();
  615. this.uniqueInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[3]);
  616. this.uniqueInputNode.set("value", (this.data.unique));
  617. tdContents[4].setStyles(this.style.baseInforContentNode_edit).empty();
  618. var html = "<input name=\"personGenderRadioNode\" value=\"m\" type=\"radio\" "+((this.data.genderType==="m") ? "checked" : "")+"/>"+this.explorer.app.lp.man;
  619. html += "<input name=\"personGenderRadioNode\" value=\"f\" type=\"radio\" "+((this.data.genderType==="f") ? "checked" : "")+"/>"+this.explorer.app.lp.female;
  620. html += "<input name=\"personGenderRadioNode\" value=\"o\" type=\"radio\" "+((this.data.genderType==="d") ? "checked" : "")+"/>"+this.explorer.app.lp.other;
  621. tdContents[4].set("html", html);
  622. tdContents[5].setStyles(this.style.baseInforContentNode_edit).empty();
  623. this.superiorInputNode = new Element("div", {"styles": this.style.inputNode_person}).inject(tdContents[5]);
  624. //this.superiorInputNode.set("value", (this.data.superior));
  625. if (this.data.superior) new MWF.widget.O2Person({"name": this.data.superior}, this.superiorInputNode, {"style": "xform"});
  626. this.superiorInputNode.addEvent("click", function(){
  627. MWF.xDesktop.requireApp("Selector", "package", function(){
  628. var options = {
  629. "type": "person",
  630. "values": (this.data.superior) ? [this.data.superior] : [],
  631. "count": 1,
  632. "onComplete": function(items){
  633. this.data.superior = items[0].data.distinguishedName;
  634. this.superiorInputNode.empty();
  635. new MWF.widget.O2Person(items[0].data, this.superiorInputNode, {"style": "xform"});
  636. }.bind(this)
  637. };
  638. var selector = new MWF.O2Selector(this.explorer.app.content, options);
  639. }.bind(this));
  640. }.bind(this));
  641. tdContents[6].setStyles(this.style.baseInforContentNode_edit).empty();
  642. this.mailInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[6]);
  643. this.mailInputNode.set("value", (this.data.mail));
  644. tdContents[7].setStyles(this.style.baseInforContentNode_edit).empty();
  645. this.weixinInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[7]);
  646. this.weixinInputNode.set("value", (this.data.weixin));
  647. tdContents[8].setStyles(this.style.baseInforContentNode_edit).empty();
  648. this.qqInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[8]);
  649. this.qqInputNode.set("value", (this.data.qq));
  650. tdContents[9].setStyles(this.style.baseInforContentNode_edit).empty();
  651. this.officePhoneInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[9]);
  652. this.officePhoneInputNode.set("value", (this.data.officePhone));
  653. tdContents[10].setStyles(this.style.baseInforContentNode_edit).empty();
  654. this.boardDateInputNode = new Element("input", {"styles": this.style.inputNode_calendar, "readonly": true}).inject(tdContents[10]);
  655. this.boardDateInputNode.set("value", (this.data.boardDate));
  656. MWF.require("MWF.widget.Calendar", function(){
  657. var boardDateCalendar = new MWF.widget.Calendar(this.boardDateInputNode, {
  658. "style": "xform",
  659. "isTime": false,
  660. "target": this.explorer.app.content,
  661. "format": "%Y-%m-%d"
  662. });
  663. }.bind(this));
  664. tdContents[11].setStyles(this.style.baseInforContentNode_edit).empty();
  665. this.birthdayInputNode = new Element("input", {"styles": this.style.inputNode_calendar, "readonly": true}).inject(tdContents[11]);
  666. this.birthdayInputNode.set("value", (this.data.birthday));
  667. MWF.require("MWF.widget.Calendar", function(){
  668. var birthdayCalendar = new MWF.widget.Calendar(this.birthdayInputNode, {
  669. "style": "xform",
  670. "isTime": false,
  671. "target": this.explorer.app.content,
  672. "format": "%Y-%m-%d"
  673. });
  674. }.bind(this));
  675. var _self = this;
  676. this.editContentNode.getElements("input").addEvents({
  677. "focus": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_focus);}},
  678. "blur": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_blur);}}
  679. });
  680. this.mode = "edit";
  681. this.editNode.setStyle("display", "none");
  682. this.saveNode.setStyle("display", "block");
  683. this.cancelNode.setStyle("display", "block");
  684. },
  685. save: function(){
  686. var tdContents = this.editContentNode.getElements("td.inforContent");
  687. var gender = "";
  688. var radios = tdContents[4].getElements("input");
  689. for (var i=0; i<radios.length; i++){
  690. if (radios[i].checked){
  691. gender = radios[i].value;
  692. break;
  693. }
  694. }
  695. //if (!this.nameInputNode.get("value") || !this.employeeInputNode.get("value") || !this.mobileInputNode.get("value") || !gender){
  696. if (!this.nameInputNode.get("value") || !this.mobileInputNode.get("value") || !gender){
  697. this.explorer.app.notice(this.explorer.app.lp.inputPersonInfor, "error", this.explorer.propertyContentNode);
  698. return false;
  699. }
  700. //this.data.genderType = gender;
  701. if (!this.uniqueInputNode.get("value")) this.data.unique = this.employeeInputNode.get("value");
  702. this.content.propertyContentScrollNode.mask({
  703. "style": {
  704. "opacity": 0.7,
  705. "background-color": "#999"
  706. }
  707. });
  708. this.savePerson(function(){
  709. this.cancel();
  710. this.content.propertyContentScrollNode.unmask();
  711. }.bind(this), function(xhr, text, error){
  712. var errorText = error;
  713. if (xhr){
  714. var json = JSON.decode(xhr.responseText);
  715. if (json){
  716. errorText = json.message.trim() || "request json error";
  717. }else{
  718. errorText = "request json error: "+xhr.responseText;
  719. }
  720. }
  721. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  722. this.content.propertyContentScrollNode.unmask();
  723. }.bind(this));
  724. },
  725. savePerson: function(callback, cancel){
  726. var data = Object.clone(this.data);
  727. data.name = this.nameInputNode.get("value");
  728. data.employee = this.employeeInputNode.get("value");
  729. data.mobile = this.mobileInputNode.get("value");
  730. data.unique = this.uniqueInputNode.get("value");
  731. //data.superior = this.superiorInputNode.get("value");
  732. data.mail = this.mailInputNode.get("value");
  733. data.weixin = this.weixinInputNode.get("value");
  734. data.qq = this.qqInputNode.get("value");
  735. data.officePhone = this.officePhoneInputNode.get("value");
  736. data.boardDate = this.boardDateInputNode.get("value");
  737. data.birthday = this.birthdayInputNode.get("value");
  738. var tdContents = this.editContentNode.getElements("td.inforContent");
  739. var radios = tdContents[4].getElements("input");
  740. for (var i=0; i<radios.length; i++){
  741. if (radios[i].checked){
  742. data.genderType = radios[i].value;
  743. break;
  744. }
  745. }
  746. this.explorer.actions.savePerson(data, function(json){
  747. Object.merge(this.data, data);
  748. if (this.data.id){
  749. this.data.id = json.data.id;
  750. this.item.refresh();
  751. if (callback) callback();
  752. }else{
  753. this.explorer.actions.getPerson(function(json){
  754. this.data = Object.merge(this.data, json.data);
  755. this.item.data = this.data;
  756. this.item.refresh();
  757. if (callback) callback();
  758. }.bind(this), null, json.data.id);
  759. }
  760. }.bind(this), function(xhr, text, error){
  761. if (cancel) cancel(xhr, text, error);
  762. }.bind(this));
  763. // }.bind(this), function(xhr, text, error){
  764. // if (cancel) cancel(xhr, text, error);
  765. // }.bind(this));
  766. },
  767. cancel: function(){
  768. if (this.data.id){
  769. var tdContents = this.editContentNode.getElements("td.inforContent");
  770. tdContents[0].setStyles(this.style.baseInforContentNode).set("text", this.data.name || "");
  771. tdContents[1].setStyles(this.style.baseInforContentNode).set("text", this.data.employee || "");
  772. tdContents[2].setStyles(this.style.baseInforContentNode).set("text", this.data.mobile || "");
  773. tdContents[3].setStyles(this.style.baseInforContentNode).set("text", this.data.unique || "");
  774. tdContents[4].setStyles(this.style.baseInforContentNode).set("text", this.getGenderType());
  775. tdContents[5].setStyles(this.style.baseInforContentNode).set("text", "");
  776. if (this.data.superior) new MWF.widget.O2Person({"name": this.data.superior}, tdContents[5], {"style": "xform"});
  777. tdContents[6].setStyles(this.style.baseInforContentNode).set("text", this.data.mail || "");
  778. tdContents[7].setStyles(this.style.baseInforContentNode).set("text", this.data.weixin || "");
  779. tdContents[8].setStyles(this.style.baseInforContentNode).set("text", this.data.qq || "");
  780. tdContents[9].setStyles(this.style.baseInforContentNode).set("text", this.data.officePhone || "");
  781. tdContents[10].setStyles(this.style.baseInforContentNode).set("text", this.data.boardDate || "");
  782. tdContents[11].setStyles(this.style.baseInforContentNode).set("text", this.data.birthday || "");
  783. this.mode = "read";
  784. this.editNode.setStyle("display", "block");
  785. this.saveNode.setStyle("display", "none");
  786. this.cancelNode.setStyle("display", "none");
  787. }else{
  788. this.item.destroy();
  789. }
  790. },
  791. getGenderType: function(){
  792. var text = "";
  793. if (this.data.genderType){
  794. switch (this.data.genderType) {
  795. case "m":
  796. text = this.explorer.app.lp.man;
  797. break;
  798. case "f":
  799. text = this.explorer.app.lp.female;
  800. break;
  801. default:
  802. text = this.explorer.app.lp.other;
  803. }
  804. }
  805. return text;
  806. },
  807. destroy: function(){
  808. this.node.empty();
  809. this.node.destroy();
  810. MWF.release(this);
  811. },
  812. _getIcon: function(nocache){
  813. var url = (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "/x_component_Org/$Explorer/default/icon/man.png";
  814. return (nocache) ? url+"?"+(new Date().getTime()) : url;
  815. //return (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "/x_component_Org/$Explorer/default/icon/man.png";
  816. // var src = "data:image/png;base64,"+this.data.icon;
  817. // if (!this.data.icon){
  818. // if (this.data.genderType==="f"){
  819. // src = "/x_component_Org/$Explorer/default/icon/female.png"
  820. // }else{
  821. // src = "/x_component_Org/$Explorer/default/icon/man.png"
  822. // }
  823. // }
  824. // return src;
  825. }
  826. });