PersonExplorer.js 40 KB

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