PersonExplorer.js 45 KB

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