PersonExplorer.js 45 KB

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