PersonExplorer.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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. "get": function(){
  267. if (_self.data.control.allowEdit){
  268. return "<div style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  269. _self.explorer.app.options.style+"/icon/edit.png) center center no-repeat'></div>";
  270. }
  271. return "";
  272. },
  273. "events": {
  274. "click": function(){
  275. if (_self.data.control.allowEdit){_self.editIdentity(this.data, this.td, this.item);}
  276. }
  277. }
  278. }]
  279. });
  280. this.identityList.load([
  281. {"style": "width: 14%", "text": this.explorer.app.lp.IdentityName},
  282. {"style": "width: 14%", "text": this.explorer.app.lp.IdentityInUnit},
  283. {"style": "width: 50%", "text": this.explorer.app.lp.personUnique},
  284. {"style": "width: 20%", "text": this.explorer.app.lp.IdentityDuty},
  285. {"style": "width: 30px", "text": ""}
  286. ]);
  287. this.data.woIdentityList.each(function(item){
  288. this.identityList.push(item);
  289. }.bind(this));
  290. },
  291. editIdentity: function(data, node, item){
  292. var _self = this;
  293. var position = node.getPosition(this.explorer.app.content);
  294. var width = 700;
  295. var height = 170;
  296. var size = this.explorer.app.content.getSize();
  297. var x = (size.x-width)/2;
  298. var y = (size.y-height)/2;
  299. if (x<0) x = 0;
  300. if (y<20) y = 20;
  301. MWF.require("MWF.xDesktop.Dialog", function() {
  302. var dlg = new MWF.xDesktop.Dialog({
  303. "title": this.explorer.app.lp.modifyIdentity,
  304. "style": "org",
  305. "top": y - 20,
  306. "left": x,
  307. "fromTop": position.y - 20,
  308. "fromLeft": position.x,
  309. "width": width,
  310. "height": height,
  311. "html": "<div></div>",
  312. "maskNode": this.explorer.app.content,
  313. "container": this.explorer.app.content,
  314. "buttonList": [
  315. {
  316. "text": MWF.LP.process.button.ok,
  317. "action": function () {
  318. _self.saveIdentity(dlg, data, item);
  319. this.close();
  320. }
  321. },
  322. {
  323. "text": MWF.LP.process.button.cancel,
  324. "action": function () {
  325. this.close();
  326. }
  327. }
  328. ]
  329. });
  330. dlg.show();
  331. var node = dlg.content.getFirst();
  332. var html = "<table width='90%' cellpadding='0px' cellspacing='5px' align='center' style='margin-top:10px'>" +
  333. "<tr><th width='30%'>"+this.explorer.app.lp.IdentityName+"</th><th>"+this.explorer.app.lp.personUnique+"</th></tr>" +
  334. "<tr><td style='text-align: center'><input value='"+data.name+"' type='type' style='padding: 0px 3px; width: 95%; border: 1px solid #cccccc; height: 24px; border-radius: 3px; line-height: 24px;'/></td>" +
  335. "<td style='text-align: center'><input value='"+data.unique+"' type='type' style='padding: 0px 3px; width: 95%; border: 1px solid #cccccc; height: 24px; border-radius: 3px; line-height: 24px;'/></td></tr></table>"
  336. node.set("html", html);
  337. }.bind(this));
  338. },
  339. saveIdentity: function(dlg, data, item){
  340. var node = dlg.content.getFirst();
  341. var inputs = node.getElements("input");
  342. var name = inputs[0].get("value");
  343. var unique = inputs[1].get("value");
  344. debugger;
  345. if (data.name!==name || data.unique!==unique){
  346. if (name) data.name = name;
  347. data.unique=unique;
  348. this.explorer.actions.saveIdentity(data, function(json){
  349. this.explorer.actions.getIdentity(function(iJson){
  350. data = iJson.data;
  351. item.reload(iJson.data);
  352. }.bind(this), null, json.data.id);
  353. }.bind(this));
  354. }
  355. }
  356. });
  357. MWF.xApplication.Org.PersonExplorer.PersonContent.TitleInfor = new Class({
  358. Extends: MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor,
  359. loadAction: function(){
  360. //this.explorer.app.lp.edit
  361. if (this.data.control.allowEdit){
  362. this.iconNode.setStyle("cursor", "pointer");
  363. this.iconNode.addEvent("click", function(){this.changePersonIcon();}.bind(this));
  364. }
  365. },
  366. changePersonIcon: function(){
  367. var options = {};
  368. var width = "668";
  369. var height = "510";
  370. width = width.toInt();
  371. height = height.toInt();
  372. var size = this.explorer.app.content.getSize();
  373. var x = (size.x-width)/2;
  374. var y = (size.y-height)/2;
  375. if (x<0) x = 0;
  376. if (y<0) y = 0;
  377. if (layout.mobile){
  378. x = 20;
  379. y = 0;
  380. }
  381. var _self = this;
  382. MWF.require("MWF.xDesktop.Dialog", function() {
  383. MWF.require("MWF.widget.ImageClipper", function(){
  384. var dlg = new MWF.xDesktop.Dialog({
  385. "title": this.explorer.app.lp.changePersonIcon,
  386. "style": "image",
  387. "top": y,
  388. "left": x - 20,
  389. "fromTop": y,
  390. "fromLeft": x - 20,
  391. "width": width,
  392. "height": height,
  393. "html": "<div></div>",
  394. "maskNode": this.explorer.app.content,
  395. "container": this.explorer.app.content,
  396. "buttonList": [
  397. {
  398. "text": MWF.LP.process.button.ok,
  399. "action": function () {
  400. _self.uploadPersonIcon();
  401. this.close();
  402. }
  403. },
  404. {
  405. "text": MWF.LP.process.button.cancel,
  406. "action": function () {
  407. _self.image = null;
  408. this.close();
  409. }
  410. }
  411. ]
  412. });
  413. dlg.show();
  414. this.image = new MWF.widget.ImageClipper(dlg.content.getFirst(), {
  415. "aspectRatio": 1,
  416. "description" : "",
  417. "imageUrl" : this._getIcon(true),
  418. "resetEnable" : false
  419. });
  420. this.image.load();
  421. }.bind(this));
  422. }.bind(this))
  423. },
  424. uploadPersonIcon: function(){
  425. if (this.image){
  426. if( this.image.getResizedImage() ){
  427. this.explorer.actions.changePersonIcon(this.data.id, this.image.getFormData(), this.image.getResizedImage(), function(){
  428. this.iconNode.set("src", "");
  429. if (this.item.iconNode) this.item.iconNode.getElement("img").set("src", "");
  430. window.setTimeout(function(){
  431. this.iconNode.set("src", this._getIcon(true));
  432. if (this.item.iconNode) this.item.iconNode.getElement("img").set("src", this.item._getIcon(true));
  433. }.bind(this), 100);
  434. }.bind(this), null);
  435. }
  436. }
  437. }
  438. });
  439. MWF.xApplication.Org.PersonExplorer.PersonContent.BottomInfor = new Class({
  440. Extends: MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor,
  441. addInforList: function(){
  442. var text = this.explorer.app.lp.personReadDn.replace(/{dn}/g, (this.data.distinguishedName || " "));
  443. this.addInfor(text);
  444. text = this.explorer.app.lp.personReadCreate.replace(/{date}/g, (this.data.createTime || " "));
  445. text = text.replace(/{date2}/g, (this.data.updateTime || " "));
  446. this.addInfor(text);
  447. text = this.explorer.app.lp.personReadLogin.replace(/{date}/g, (this.data.lastLoginTime || " "));
  448. text = text.replace(/{ip}/g, (this.data.lastLoginAddress || " "));
  449. text = text.replace(/{client}/g, (this.data.lastLoginClient || " "));
  450. this.addInfor(text);
  451. text = this.explorer.app.lp.personReadPassword.replace(/{date}/g, (this.data.passwordExpiredTime || " "));
  452. text = text.replace(/{date2}/g, (this.data.changePasswordTime || " "));
  453. this.addInfor(text);
  454. }
  455. });
  456. MWF.xApplication.Org.PersonExplorer.PersonContent.BaseInfor = new Class({
  457. initialize: function(content){
  458. this.content = content;
  459. this.item = content.item;
  460. this.data = this.content.data;
  461. this.explorer = this.item.explorer;
  462. this.contentNode = this.content.baseContentNode;
  463. this.style = this.item.style.person;
  464. this.attributes = [];
  465. this.mode = "read";
  466. this.load();
  467. },
  468. load: function(){
  469. this.node = new Element("div", {"styles": this.style.baseContentNode}).inject(this.contentNode);
  470. this.editContentNode = new Element("div", {"styles": this.style.baseEditNode}).inject(this.node);
  471. this.editContentNode.set("html", this.getContentHtml());
  472. this.editContentNode.getElements("td.inforTitle").setStyles(this.style.baseInforTitleNode);
  473. this.editContentNode.getElements("td.inforContent").setStyles(this.style.baseInforContentNode);
  474. this.editContentNode.getElements("td.inforAction").setStyles(this.style.baseInforActionNode);
  475. var tdContents = this.editContentNode.getElements("td.inforContent");
  476. if (this.data.superior) new MWF.widget.O2Person({"name": this.data.superior}, tdContents[5], {"style": "xform"});
  477. this.loadAction();
  478. },
  479. getContentHtml: function(){
  480. var html = "<table width='100%' cellpadding='3px' cellspacing='5px'>";
  481. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personName+":</td><td class='inforContent'>"+(this.data.name || "")+"</td>" +
  482. "<td class='inforTitle'>"+this.explorer.app.lp.personEmployee+":</td><td class='inforContent'>"+(this.data.employee || "")+"</td></tr>";
  483. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personMobile+":</td><td class='inforContent'>"+(this.data.mobile || "")+"</td>" +
  484. "<td class='inforTitle'>"+this.explorer.app.lp.personUnique+":</td><td class='inforContent'>"+(this.data.unique || "")+"</td></tr>";
  485. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personGender+":</td><td class='inforContent'>"+this.getGenderType()+"</td>" +
  486. "<td class='inforTitle'>"+this.explorer.app.lp.personSuperior+":</td><td class='inforContent'>"+"</td></tr>";
  487. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personMail+":</td><td class='inforContent'>"+(this.data.mail || "")+"</td>" +
  488. "<td class='inforTitle'>"+this.explorer.app.lp.personWeixin+":</td><td class='inforContent'>"+(this.data.weixin || "")+"</td></tr>";
  489. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personQQ+":</td><td class='inforContent'>"+(this.data.qq || "")+"</td>" +
  490. "<td class='inforTitle'>"+this.explorer.app.lp.personOfficePhone+":</td><td class='inforContent'>"+(this.data.officePhone || "")+"</td></tr>";
  491. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personBoardDate+":</td><td class='inforContent'>"+(this.data.boardDate || "")+"</td>" +
  492. "<td class='inforTitle'>"+this.explorer.app.lp.personBirthday+":</td><td class='inforContent'>"+(this.data.birthday || "")+"</td></tr>";
  493. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  494. //this.baseInforRightNode.set("html", html);
  495. return html;
  496. },
  497. loadAction: function(){
  498. //this.explorer.app.lp.edit
  499. var actionAreas = this.editContentNode.getElements("td");
  500. var actionArea = actionAreas[actionAreas.length-1];
  501. if (this.data.control.allowEdit){
  502. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  503. this.editNode = new Element("div", {"styles": this.style.actionEditNode, "text": this.explorer.app.lp.editPerson}).inject(this.baseInforEditActionAreaNode);
  504. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.savePerson}).inject(this.baseInforEditActionAreaNode);
  505. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  506. this.editNode.setStyle("display", "block");
  507. this.editNode.addEvent("click", this.edit.bind(this));
  508. this.saveNode.addEvent("click", this.save.bind(this));
  509. this.cancelNode.addEvent("click", this.cancel.bind(this));
  510. }else{
  511. }
  512. },
  513. edit: function(){
  514. var tdContents = this.editContentNode.getElements("td.inforContent");
  515. tdContents[0].setStyles(this.style.baseInforContentNode_edit).empty();
  516. this.nameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[0]);
  517. this.nameInputNode.set("value", (this.data.name));
  518. tdContents[1].setStyles(this.style.baseInforContentNode_edit).empty();
  519. this.employeeInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[1]);
  520. this.employeeInputNode.set("value", (this.data.employee));
  521. tdContents[2].setStyles(this.style.baseInforContentNode_edit).empty();
  522. this.mobileInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[2]);
  523. this.mobileInputNode.set("value", (this.data.mobile));
  524. tdContents[3].setStyles(this.style.baseInforContentNode_edit).empty();
  525. this.uniqueInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[3]);
  526. this.uniqueInputNode.set("value", (this.data.unique));
  527. tdContents[4].setStyles(this.style.baseInforContentNode_edit).empty();
  528. var html = "<input name=\"personGenderRadioNode\" value=\"m\" type=\"radio\" "+((this.data.genderType==="m") ? "checked" : "")+"/>"+this.explorer.app.lp.man;
  529. html += "<input name=\"personGenderRadioNode\" value=\"f\" type=\"radio\" "+((this.data.genderType==="f") ? "checked" : "")+"/>"+this.explorer.app.lp.female;
  530. html += "<input name=\"personGenderRadioNode\" value=\"o\" type=\"radio\" "+((this.data.genderType==="d") ? "checked" : "")+"/>"+this.explorer.app.lp.other;
  531. tdContents[4].set("html", html);
  532. tdContents[5].setStyles(this.style.baseInforContentNode_edit).empty();
  533. this.superiorInputNode = new Element("div", {"styles": this.style.inputNode_person}).inject(tdContents[5]);
  534. //this.superiorInputNode.set("value", (this.data.superior));
  535. if (this.data.superior) new MWF.widget.O2Person({"name": this.data.superior}, this.superiorInputNode, {"style": "xform"});
  536. this.superiorInputNode.addEvent("click", function(){
  537. MWF.xDesktop.requireApp("Selector", "package", function(){
  538. var options = {
  539. "type": "person",
  540. "values": [this.data.superior],
  541. "count": 1,
  542. "onComplete": function(items){
  543. this.data.superior = items[0].data.distinguishedName;
  544. this.superiorInputNode.empty();
  545. new MWF.widget.O2Person(items[0].data, this.superiorInputNode, {"style": "xform"});
  546. }.bind(this)
  547. };
  548. var selector = new MWF.O2Selector(this.explorer.app.content, options);
  549. }.bind(this));
  550. }.bind(this));
  551. tdContents[6].setStyles(this.style.baseInforContentNode_edit).empty();
  552. this.mailInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[6]);
  553. this.mailInputNode.set("value", (this.data.mail));
  554. tdContents[7].setStyles(this.style.baseInforContentNode_edit).empty();
  555. this.weixinInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[7]);
  556. this.weixinInputNode.set("value", (this.data.weixin));
  557. tdContents[8].setStyles(this.style.baseInforContentNode_edit).empty();
  558. this.qqInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[8]);
  559. this.qqInputNode.set("value", (this.data.qq));
  560. tdContents[9].setStyles(this.style.baseInforContentNode_edit).empty();
  561. this.officePhoneInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[9]);
  562. this.officePhoneInputNode.set("value", (this.data.officePhone));
  563. tdContents[10].setStyles(this.style.baseInforContentNode_edit).empty();
  564. this.boardDateInputNode = new Element("input", {"styles": this.style.inputNode_calendar, "readonly": true}).inject(tdContents[10]);
  565. this.boardDateInputNode.set("value", (this.data.boardDate));
  566. MWF.require("MWF.widget.Calendar", function(){
  567. var boardDateCalendar = new MWF.widget.Calendar(this.boardDateInputNode, {
  568. "style": "xform",
  569. "isTime": false,
  570. "target": this.explorer.app.content,
  571. "format": "%Y-%m-%d"
  572. });
  573. }.bind(this));
  574. tdContents[11].setStyles(this.style.baseInforContentNode_edit).empty();
  575. this.birthdayInputNode = new Element("input", {"styles": this.style.inputNode_calendar, "readonly": true}).inject(tdContents[11]);
  576. this.birthdayInputNode.set("value", (this.data.birthday));
  577. MWF.require("MWF.widget.Calendar", function(){
  578. var birthdayCalendar = new MWF.widget.Calendar(this.birthdayInputNode, {
  579. "style": "xform",
  580. "isTime": false,
  581. "target": this.explorer.app.content,
  582. "format": "%Y-%m-%d"
  583. });
  584. }.bind(this));
  585. var _self = this;
  586. this.editContentNode.getElements("input").addEvents({
  587. "focus": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_focus);}},
  588. "blur": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_blur);}}
  589. });
  590. this.mode = "edit";
  591. this.editNode.setStyle("display", "none");
  592. this.saveNode.setStyle("display", "block");
  593. this.cancelNode.setStyle("display", "block");
  594. },
  595. save: function(){
  596. var tdContents = this.editContentNode.getElements("td.inforContent");
  597. var gender = "";
  598. var radios = tdContents[4].getElements("input");
  599. for (var i=0; i<radios.length; i++){
  600. if (radios[i].checked){
  601. gender = radios[i].value;
  602. break;
  603. }
  604. }
  605. //if (!this.nameInputNode.get("value") || !this.employeeInputNode.get("value") || !this.mobileInputNode.get("value") || !gender){
  606. if (!this.nameInputNode.get("value") || !this.mobileInputNode.get("value") || !gender){
  607. this.explorer.app.notice(this.explorer.app.lp.inputPersonInfor, "error", this.explorer.propertyContentNode);
  608. return false;
  609. }
  610. //this.data.genderType = gender;
  611. if (!this.uniqueInputNode.get("value")) this.data.unique = this.employeeInputNode.get("value");
  612. this.content.propertyContentScrollNode.mask({
  613. "style": {
  614. "opacity": 0.7,
  615. "background-color": "#999"
  616. }
  617. });
  618. this.savePerson(function(){
  619. this.cancel();
  620. this.content.propertyContentScrollNode.unmask();
  621. }.bind(this), function(xhr, text, error){
  622. var errorText = error;
  623. if (xhr){
  624. var json = JSON.decode(xhr.responseText);
  625. if (json){
  626. errorText = json.message.trim() || "request json error";
  627. }else{
  628. errorText = "request json error: "+xhr.responseText;
  629. }
  630. }
  631. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  632. this.content.propertyContentScrollNode.unmask();
  633. }.bind(this));
  634. },
  635. savePerson: function(callback, cancel){
  636. var data = Object.clone(this.data);
  637. data.name = this.nameInputNode.get("value");
  638. data.employee = this.employeeInputNode.get("value");
  639. data.mobile = this.mobileInputNode.get("value");
  640. data.unique = this.uniqueInputNode.get("value");
  641. //data.superior = this.superiorInputNode.get("value");
  642. data.mail = this.mailInputNode.get("value");
  643. data.weixin = this.weixinInputNode.get("value");
  644. data.qq = this.qqInputNode.get("value");
  645. data.officePhone = this.officePhoneInputNode.get("value");
  646. data.boardDate = this.boardDateInputNode.get("value");
  647. data.birthday = this.birthdayInputNode.get("value");
  648. var tdContents = this.editContentNode.getElements("td.inforContent");
  649. var radios = tdContents[4].getElements("input");
  650. for (var i=0; i<radios.length; i++){
  651. if (radios[i].checked){
  652. data.genderType = radios[i].value;
  653. break;
  654. }
  655. }
  656. this.explorer.actions.savePerson(data, function(json){
  657. Object.merge(this.data, data);
  658. if (this.data.id){
  659. this.data.id = json.data.id;
  660. this.item.refresh();
  661. if (callback) callback();
  662. }else{
  663. this.explorer.actions.getPerson(function(json){
  664. this.data = Object.merge(this.data, json.data);
  665. this.item.data = this.data;
  666. this.item.refresh();
  667. if (callback) callback();
  668. }.bind(this), null, json.data.id);
  669. }
  670. }.bind(this), function(xhr, text, error){
  671. if (cancel) cancel(xhr, text, error);
  672. }.bind(this));
  673. // }.bind(this), function(xhr, text, error){
  674. // if (cancel) cancel(xhr, text, error);
  675. // }.bind(this));
  676. },
  677. cancel: function(){
  678. if (this.data.id){
  679. var tdContents = this.editContentNode.getElements("td.inforContent");
  680. tdContents[0].setStyles(this.style.baseInforContentNode).set("html", this.data.name || "");
  681. tdContents[1].setStyles(this.style.baseInforContentNode).set("html", this.data.employee || "");
  682. tdContents[2].setStyles(this.style.baseInforContentNode).set("html", this.data.mobile || "");
  683. tdContents[3].setStyles(this.style.baseInforContentNode).set("html", this.data.unique || "");
  684. tdContents[4].setStyles(this.style.baseInforContentNode).set("html", this.getGenderType());
  685. tdContents[5].setStyles(this.style.baseInforContentNode).set("html", "");
  686. if (this.data.superior) new MWF.widget.O2Person({"name": this.data.superior}, tdContents[5], {"style": "xform"});
  687. tdContents[6].setStyles(this.style.baseInforContentNode).set("html", this.data.mail || "");
  688. tdContents[7].setStyles(this.style.baseInforContentNode).set("html", this.data.weixin || "");
  689. tdContents[8].setStyles(this.style.baseInforContentNode).set("html", this.data.qq || "");
  690. tdContents[9].setStyles(this.style.baseInforContentNode).set("html", this.data.officePhone || "");
  691. tdContents[10].setStyles(this.style.baseInforContentNode).set("html", this.data.boardDate || "");
  692. tdContents[11].setStyles(this.style.baseInforContentNode).set("html", this.data.birthday || "");
  693. this.mode = "read";
  694. this.editNode.setStyle("display", "block");
  695. this.saveNode.setStyle("display", "none");
  696. this.cancelNode.setStyle("display", "none");
  697. }else{
  698. this.item.destroy();
  699. }
  700. },
  701. getGenderType: function(){
  702. var text = "";
  703. if (this.data.genderType){
  704. switch (this.data.genderType) {
  705. case "m":
  706. text = this.explorer.app.lp.man;
  707. break;
  708. case "f":
  709. text = this.explorer.app.lp.female;
  710. break;
  711. default:
  712. text = this.explorer.app.lp.other;
  713. }
  714. }
  715. return text;
  716. },
  717. destroy: function(){
  718. this.node.empty();
  719. this.node.destroy();
  720. MWF.release(this);
  721. },
  722. _getIcon: function(nocache){
  723. var url = (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "/x_component_Org/$Explorer/default/icon/man.png";
  724. return (nocache) ? url+"?"+(new Date().getTime()) : url;
  725. //return (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "/x_component_Org/$Explorer/default/icon/man.png";
  726. // var src = "data:image/png;base64,"+this.data.icon;
  727. // if (!this.data.icon){
  728. // if (this.data.genderType==="f"){
  729. // src = "/x_component_Org/$Explorer/default/icon/female.png"
  730. // }else{
  731. // src = "/x_component_Org/$Explorer/default/icon/man.png"
  732. // }
  733. // }
  734. // return src;
  735. }
  736. });