PersonExplorer.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. MWF.xDesktop.requireApp("Organization", "GroupExplorer", null, false);
  2. MWF.xDesktop.requireApp("Organization", "OrgExplorer", null, false);
  3. MWF.xApplication.Organization.PersonExplorer = new Class({
  4. Extends: MWF.xApplication.Organization.GroupExplorer,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default"
  8. },
  9. _loadPath: function(){
  10. this.path = "/x_component_Organization/$PersonExplorer/";
  11. this.cssPath = "/x_component_Organization/$PersonExplorer/"+this.options.style+"/css.wcss";
  12. },
  13. _loadLp: function(){
  14. this.options.lp = {
  15. "elementLoaded": this.app.lp.personLoaded,
  16. "search": this.app.lp.search,
  17. "searchText": this.app.lp.searchText,
  18. "elementSave": this.app.lp.personSave,
  19. "deleteElements": this.app.lp.deletePersons,
  20. "deleteElementsTitle": this.app.lp.deletePersonsTitle,
  21. "deleteElementsConfirm": this.app.lp.deletePersonsConfirm,
  22. "elementBaseText": this.app.lp.roleBaseText,
  23. "elementName": this.app.lp.roleName,
  24. "edit": this.app.lp.edit,
  25. "cancel": this.app.lp.cancel,
  26. "save": this.app.lp.save,
  27. "add": this.app.lp.add
  28. }
  29. },
  30. _listElementNext: function(lastid, count, callback){
  31. this.actions.listPersonNext(lastid, count, function(json){
  32. if (callback) callback.apply(this, [json]);
  33. }.bind(this));
  34. },
  35. _newElement: function(data, explorer){
  36. return new MWF.xApplication.Organization.PersonExplorer.Person(data, explorer, this.isEditor);
  37. },
  38. _listElementByKey: function(callback, failure, key){
  39. this.actions.listPersonByKey(function(json){
  40. if (callback) callback.apply(this, [json]);
  41. }.bind(this), failure, key);
  42. },
  43. _getAddElementData: function(){
  44. return {
  45. "employee": "",
  46. "password": "",
  47. "display": "",
  48. "qq": "",
  49. "mail": "",
  50. "weixin": "",
  51. "weibo": "",
  52. "mobile": "",
  53. "name": "",
  54. "controllerList": []
  55. };
  56. },
  57. loadToolbar: function(){
  58. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode}).inject(this.chartAreaNode);
  59. if (MWF.AC.isCompanyCreator() || MWF.AC.isPersonManager()) {
  60. // "yes": function(){
  61. this.isEditor = true;
  62. this.addTopElementNode = new Element("div", {"styles": this.css.addTopGroupNode}).inject(this.toolbarNode);
  63. this.addTopElementNode.addEvent("click", function () {
  64. this.addTopElement();
  65. }.bind(this));
  66. // }.bind(this)
  67. }
  68. this.createSearchNode();
  69. }
  70. });
  71. MWF.xApplication.Organization.PersonExplorer.Person = new Class({
  72. Extends: MWF.xApplication.Organization.GroupExplorer.Group,
  73. initialize: function(data, explorer, isEditor){
  74. this.data = data;
  75. this.explorer = explorer;
  76. this.chartNode = this.explorer.chartNode;
  77. this.initStyle();
  78. this.selectedAttributes = [];
  79. this.isEdit = false;
  80. this.isEditor = isEditor;
  81. this.deleteSelected = false;
  82. },
  83. load: function(){
  84. this.node = new Element("div", {"styles": this.style.node}).inject(this.chartNode);
  85. this.contentNode = new Element("div", {"styles": this.style.contentNode}).inject(this.node);
  86. this.childNode = new Element("div", {"styles": this.style.childNode}).inject(this.node);
  87. this.flagNode = new Element("div", {"styles": this.style.flagNode}).inject(this.contentNode);
  88. this.iconNode = new Element("div", {"styles": this.style.iconNode}).inject(this.contentNode);
  89. if (this.data.icon){
  90. this.iconNode.setStyle("background-image", "");
  91. var img = new Element("img", {
  92. "styles": {
  93. "margin-top": "6px",
  94. "margin-left": "13px",
  95. "width": "24px",
  96. "height": "24px",
  97. "border": "0"
  98. },
  99. "src": "data:image/png;base64,"+this.data.icon
  100. }).inject(this.iconNode);
  101. }else{
  102. if (this.data.genderType=="f"){
  103. this.iconNode.setStyle("background", "url("+"/x_component_Organization/$PersonExplorer/default/icon/female24.png) center center no-repeat");
  104. }else{
  105. this.iconNode.setStyle("background", "url("+"/x_component_Organization/$PersonExplorer/default/icon/man24.png) center center no-repeat");
  106. }
  107. }
  108. this.actionNode = new Element("div", {"styles": this.style.actionNode}).inject(this.contentNode);
  109. this.textNode = new Element("div", {"styles": this.style.textNode}).inject(this.contentNode);
  110. this.textNode.set({
  111. "text": this.data.name
  112. });
  113. this.setNewItem();
  114. this.node.inject(this.chartNode);
  115. this.addActions();
  116. this.setEvent();
  117. },
  118. addActions: function(){
  119. if (this.isEditor){
  120. if (MWF.AC.isPersonEditor({"list": this.data.controllerList})){
  121. this.deleteNode = new Element("div", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  122. // this.addNode = new Element("div", {"styles": this.style.actionAddNode}).inject(this.actionNode);
  123. this.deleteNode.addEvent("click", function(e){
  124. if (!this.deleteSelected){
  125. this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  126. this.contentNode.setStyles(this.style.contentNode_selected);
  127. this.explorer.deleteElements.push(this);
  128. this.deleteSelected = true;
  129. this.explorer.checkDeleteElements();
  130. }else{
  131. this.deleteNode.setStyles(this.style.actionDeleteNode);
  132. this.contentNode.setStyles(this.style.contentNode);
  133. this.explorer.deleteElements.erase(this);
  134. this.deleteSelected = false;
  135. this.explorer.checkDeleteElements();
  136. }
  137. e.stopPropagation();
  138. }.bind(this));
  139. }
  140. }
  141. },
  142. showItemProperty: function(){
  143. this.explorer.propertyTitleNode.set("text", this.data.name);
  144. this.showItemPropertyBase();
  145. if (MWF.AC.isPersonEditor({"list": this.data.controllerList})) this.showItemPropertyAttribute();
  146. this.showItemPropertyIdentity();
  147. this.showItemcontrollerList();
  148. },
  149. showItemPropertyBase: function(){
  150. this.propertyBaseNode = new Element("div", {
  151. "styles": this.style.propertyInforNode
  152. }).inject(this.explorer.propertyContentNode);
  153. this.baseActionNode = new Element("div", {
  154. "styles": this.style.propertyInforActionNode
  155. }).inject(this.propertyBaseNode);
  156. this.propertyBaseTextNode = new Element("div", {
  157. "styles": this.style.propertyInforTextNode,
  158. "text": this.explorer.app.lp.personBaseText
  159. }).inject(this.propertyBaseNode);
  160. this.createEditBaseNode();
  161. this.propertyBaseContentNode = new Element("div", {
  162. "styles": this.style.propertyInforContentNode
  163. }).inject(this.propertyBaseNode);
  164. var html = "<table cellspacing='0' cellpadding='0' border='0' width='95%' align='center'>";
  165. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.personImage+"</td><td id='formPersonImage'></td></tr>";
  166. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.personName+"</td><td id='formPersonName'></td></tr>";
  167. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.personUnique+"</td><td id='formPersonUnique'></td></tr>";
  168. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.personGender+"</td><td id='formPersonGender'></td></tr>";
  169. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.personEmployee+"</td><td id='formPersonEmployee'></td></tr>";
  170. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.personDisplay+"</td><td id='formPersonDisplay'></td></tr>";
  171. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.personMobile+"</td><td id='formPersonMobile'></td></tr>";
  172. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.personMail+"</td><td id='formPersonMail'></td></tr>";
  173. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.personQQ+"</td><td id='formPersonQQ'></td></tr>";
  174. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.personWeixin+"</td><td id='formPersonWeixin'></td></tr>";
  175. html += "<tr><td class='formTitle' style='display:none'>"+this.explorer.app.lp.personWeibo+"</td><td id='formPersonWeibo' style='display:none'></td></tr>";
  176. html += "</table>";
  177. this.propertyBaseContentNode.set("html", html);
  178. this.propertyBaseContentNode.getElements("td.formTitle").setStyles(this.style.propertyBaseContentTdTitle);
  179. this.personImageNode = this.propertyBaseContentNode.getElement("#formPersonImage");
  180. this.personImageAreaNode = new Element("div", {"styles": this.style.personImageAreaNode}).inject(this.personImageNode);
  181. if (this.data.icon){
  182. this.personImageAreaNode.setStyle("background", "url(data:image/png;base64,"+this.data.icon+") center center no-repeat");
  183. }else{
  184. if (this.data.genderType=="f"){
  185. this.personImageAreaNode.setStyle("background", "url("+"/x_component_Organization/$PersonExplorer/default/icon/female.png) center center no-repeat");
  186. }else{
  187. this.personImageAreaNode.setStyle("background", "url("+"/x_component_Organization/$PersonExplorer/default/icon/man.png) center center no-repeat");
  188. }
  189. }
  190. if (MWF.AC.isPersonEditor({"list": this.data.controllerList})){
  191. this.personImageActionNode = new Element("div", {"styles": this.style.personImageActionNode, "text": this.explorer.app.lp.uploadImage}).inject(this.personImageNode);
  192. this.personImageActionNode.addEvent("click", function(){
  193. this.changePersonIcon();
  194. }.bind(this));
  195. }
  196. this.personGenderNode = this.propertyBaseContentNode.getElement("#formPersonGender");
  197. this.personGenderNode.setStyle("padding-left", "20px");
  198. if (this.data.genderType){
  199. var text = "";
  200. switch (this.data.genderType) {
  201. case "m":
  202. text = this.explorer.app.lp.man;
  203. break;
  204. case "f":
  205. text = this.explorer.app.lp.female;
  206. break;
  207. default:
  208. text = this.explorer.app.lp.other;
  209. }
  210. this.personGenderNode.set("text", text);
  211. }
  212. this.personNameInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formPersonName"), this.data.name, this.explorer.css.formInput);
  213. this.personEmployeeInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formPersonEmployee"), this.data.employee, this.explorer.css.formInput, "none");
  214. this.personUniqueInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formPersonUnique"), this.data.unique, this.explorer.css.formInput, "none");
  215. //this.personGenderInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formPersonGender"), this.data.gender, this.explorer.css.formInput);
  216. this.personDisplayInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formPersonDisplay"), this.data.display, this.explorer.css.formInput);
  217. this.personMobileInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formPersonMobile"), this.data.mobile, this.explorer.css.formInput);
  218. this.personMailInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formPersonMail"), this.data.mail, this.explorer.css.formInput);
  219. this.personQQInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formPersonQQ"), this.data.qq, this.explorer.css.formInput);
  220. this.personWeixinInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formPersonWeixin"), this.data.weixin, this.explorer.css.formInput);
  221. this.personWeiboInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formPersonWeibo"), this.data.weibo, this.explorer.css.formInput);
  222. },
  223. createEditBaseNode: function(){
  224. if (MWF.AC.isPersonEditor({"list": this.data.controllerList})){
  225. this.editBaseNode = new Element("button", {
  226. "styles": this.style.editBaseNode,
  227. "text": this.explorer.options.lp.edit,
  228. "events": {"click": this.editBaseInfor.bind(this)}
  229. }).inject(this.baseActionNode);
  230. //this.editBaseNode = new Element("button", {
  231. // "styles": this.style.editBaseNode,
  232. // "text": this.explorer.options.lp.edit,
  233. // "events": {"click": this.editBaseInfor.bind(this)}
  234. //}).inject(this.baseActionNode);
  235. }
  236. },
  237. changePersonIcon: function(){
  238. if (!this.uploadFileAreaNode){
  239. this.uploadFileAreaNode = new Element("div");
  240. var html = "<input name=\"file\" type=\"file\"/>";
  241. this.uploadFileAreaNode.set("html", html);
  242. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  243. this.fileUploadNode.addEvent("change", function(){
  244. var files = fileNode.files;
  245. if (files.length){
  246. for (var i = 0; i < files.length; i++) {
  247. var file = files.item(i);
  248. var formData = new FormData();
  249. formData.append('file', file);
  250. //formData.append('name', file.name);
  251. //formData.append('folder', folderId);
  252. this.explorer.actions.changePersonIcon(this.data.id ,function(){
  253. this.explorer.actions.getPerson(function(json){
  254. if (json.data){
  255. this.data = json.data;
  256. if (this.data.icon){
  257. this.personImageAreaNode.setStyle("background", "url(data:image/png;base64,"+this.data.icon+") center center no-repeat");
  258. this.iconNode.setStyle("background-image", "");
  259. this.iconNode.empty();
  260. var img = new Element("img", {
  261. "styles": {
  262. "margin-top": "6px",
  263. "margin-left": "13px",
  264. "width": "24px",
  265. "height": "24px",
  266. "border": "0"
  267. },
  268. "src": "data:image/png;base64,"+this.data.icon
  269. }).inject(this.iconNode);
  270. }
  271. }
  272. }.bind(this), null, this.data.id, false)
  273. }.bind(this), null, formData, file);
  274. }
  275. }
  276. }.bind(this));
  277. }
  278. var fileNode = this.uploadFileAreaNode.getFirst();
  279. fileNode.click();
  280. },
  281. editMode: function(){
  282. this.personNameInput.editMode();
  283. this.personEmployeeInput.editMode();
  284. this.personUniqueInput.editMode();
  285. this.personDisplayInput.editMode();
  286. this.personMobileInput.editMode();
  287. this.personMailInput.editMode();
  288. this.personQQInput.editMode();
  289. this.personWeixinInput.editMode();
  290. this.personWeiboInput.editMode();
  291. var html = "<input name=\"personGenderRadioNode\" value=\"m\" type=\"radio\" "+((this.data.genderType=="m") ? "checked" : "")+"/>"+this.explorer.app.lp.man;
  292. html += "<input name=\"personGenderRadioNode\" value=\"f\" type=\"radio\" "+((this.data.genderType=="f") ? "checked" : "")+"/>"+this.explorer.app.lp.female;
  293. html += "<input name=\"personGenderRadioNode\" value=\"o\" type=\"radio\" "+((this.data.genderType=="d") ? "checked" : "")+"/>"+this.explorer.app.lp.other;
  294. this.personGenderNode.set("html", html);
  295. this.isEdit = true;
  296. },
  297. readMode: function(){
  298. this.personNameInput.readMode();
  299. this.personEmployeeInput.readMode();
  300. this.personUniqueInput.readMode();
  301. this.personDisplayInput.readMode();
  302. this.personMobileInput.readMode();
  303. this.personMailInput.readMode();
  304. this.personQQInput.readMode();
  305. this.personWeixinInput.readMode();
  306. this.personWeiboInput.readMode();
  307. this.personGenderNode.empty();
  308. if (this.data.genderType){
  309. var text = "";
  310. switch (this.data.genderType) {
  311. case "m":
  312. text = this.explorer.app.lp.man;
  313. break;
  314. case "f":
  315. text = this.explorer.app.lp.female;
  316. break;
  317. default:
  318. text = this.explorer.app.lp.other;
  319. }
  320. this.personGenderNode.set("text", text);
  321. }
  322. this.isEdit = false;
  323. },
  324. saveBaseInfor: function(){
  325. var radios = this.personGenderNode.getElements("input");
  326. var gender = "";
  327. for (var i=0; i<radios.length; i++){
  328. if (radios[i].checked){
  329. gender = radios[i].value;
  330. break;
  331. }
  332. }
  333. if (!this.personNameInput.input.get("value") || !this.personUniqueInput.input.get("value") || !this.personEmployeeInput.input.get("value") || !gender){
  334. this.explorer.app.notice(this.explorer.app.lp.inputPersonInfor, "error", this.explorer.propertyContentNode);
  335. return false;
  336. }
  337. if (this.personDisplayInput.input.get("value")) this.data.display = this.personNameInput.input.get("value");
  338. this.propertyBaseNode.mask({
  339. "style": {
  340. "opacity": 0.7,
  341. "background-color": "#999"
  342. }
  343. });
  344. this.save(function(){
  345. this.baseActionNode.empty();
  346. this.cancelBaseNode = null;
  347. this.saveBaseNode = null;
  348. this.createEditBaseNode();
  349. this.readMode();
  350. this.propertyBaseNode.unmask();
  351. }.bind(this), function(xhr, text, error){
  352. var errorText = error;
  353. if (xhr) errorText = xhr.responseText;
  354. this.explorer.app.notice("request json error: "+errorText, "error");
  355. this.propertyBaseNode.unmask();
  356. }.bind(this));
  357. },
  358. save: function(callback, cancel){
  359. this.data.name = this.personNameInput.input.get("value");
  360. this.data.employee = this.personEmployeeInput.input.get("value");
  361. this.data.unique = this.personUniqueInput.input.get("value");
  362. this.data.display = this.personDisplayInput.input.get("value");
  363. this.data.mobile = this.personMobileInput.input.get("value");
  364. this.data.mail = this.personMailInput.input.get("value");
  365. this.data.qq = this.personQQInput.input.get("value");
  366. this.data.weixin = this.personWeixinInput.input.get("value");
  367. this.data.weibo = this.personWeiboInput.input.get("value")
  368. var radios = this.personGenderNode.getElements("input");
  369. for (var i=0; i<radios.length; i++){
  370. if (radios[i].checked){
  371. this.data.genderType = radios[i].value;
  372. break;
  373. }
  374. }
  375. this.explorer.actions.savePerson(this.data, function(json){
  376. this.textNode.set("text", this.data.name);
  377. this.data.id = json.data.id;
  378. this.personNameInput.save();
  379. this.personEmployeeInput.save();
  380. this.personUniqueInput.save();
  381. this.personDisplayInput.save();
  382. this.personMobileInput.save();
  383. this.personMailInput.save();
  384. this.personQQInput.save();
  385. this.personWeixinInput.save();
  386. this.personWeiboInput.save();
  387. if (this.data.icon){
  388. this.iconNode.setStyle("background-image", "");
  389. var img = new Element("img", {
  390. "styles": {
  391. "margin-top": "6px",
  392. "margin-left": "13px",
  393. "width": "24px",
  394. "height": "24px",
  395. "border": "0"
  396. },
  397. "src": "data:image/png;base64,"+this.data.icon
  398. }).inject(this.iconNode);
  399. this.personImageAreaNode.setStyle("background", "url(data:image/png;base64,"+this.data.icon+") center center no-repeat");
  400. }else{
  401. if (this.data.genderType=="f"){
  402. this.iconNode.setStyle("background", "url("+"/x_component_Organization/$PersonExplorer/default/icon/female24.png) center center no-repeat");
  403. this.personImageAreaNode.setStyle("background", "url("+"/x_component_Organization/$PersonExplorer/default/icon/female.png) center center no-repeat");
  404. }else{
  405. this.iconNode.setStyle("background", "url("+"/x_component_Organization/$PersonExplorer/default/icon/man24.png) center center no-repeat");
  406. this.personImageAreaNode.setStyle("background", "url("+"/x_component_Organization/$PersonExplorer/default/icon/man.png) center center no-repeat");
  407. }
  408. }
  409. if (callback) callback();
  410. }.bind(this), function(xhr, text, error){
  411. if (cancel) cancel(xhr, text, error);
  412. }.bind(this));
  413. },
  414. showItemPropertyAttribute: function(){
  415. this.propertyAttributeNode = new Element("div", {
  416. "styles": this.style.propertyInforNode
  417. }).inject(this.explorer.propertyContentNode);
  418. this.attributeActionNode = new Element("div", {
  419. "styles": this.style.propertyInforActionNode
  420. }).inject(this.propertyAttributeNode);
  421. this.propertyAttributeTextNode = new Element("div", {
  422. "styles": this.style.propertyInforTextNode,
  423. "text": this.explorer.app.lp.personAttributeText
  424. }).inject(this.propertyAttributeNode);
  425. // this.createEditBaseNode();
  426. this.propertyAttributeContentNode = new Element("div", {
  427. "styles": this.style.propertyInforContentNode
  428. }).inject(this.propertyAttributeNode);
  429. if (MWF.AC.isPersonEditor({"list": this.data.controllerList})) {
  430. this.createDeleteAttributeNode();
  431. this.createAddAttributeNode();
  432. }
  433. this.listAttribute();
  434. },
  435. createAddAttributeNode: function(){
  436. this.addAttributeNode = new Element("button", {
  437. "styles": this.style.addDutyNode,
  438. "text": this.explorer.app.lp.add,
  439. "events": {"click": this.addAttribute.bind(this)}
  440. }).inject(this.attributeActionNode);
  441. },
  442. createDeleteAttributeNode: function(){
  443. this.deleteAttributeNode = new Element("button", {
  444. "styles": this.style.deleteDutyNode_desable,
  445. "text": this.explorer.app.lp["delete"],
  446. "disable": true
  447. }).inject(this.attributeActionNode);
  448. },
  449. addAttribute: function(){
  450. var data = this.getNewAttributeData();
  451. new MWF.xApplication.Organization.PersonAttribute(this.propertyAttributeContentNode.getElement("table").getFirst(), data, this, this.explorer.css.map);
  452. },
  453. getNewAttributeData: function(){
  454. return {
  455. "person": this.data.id,
  456. "name": "",
  457. "attributeList":[]
  458. };
  459. },
  460. checkDeleteAttributeAction: function(){
  461. if (this.selectedAttributes.length){
  462. if (this.deleteAttributeNode.get("disable")){
  463. this.deleteAttributeNode.set({
  464. "styles": this.style.deleteDutyNode
  465. });
  466. this.deleteAttributeNode.removeProperty("disable");
  467. this.deleteAttributeNode.addEvent("click", function(e){this.deleteAttribute(e);}.bind(this));
  468. }
  469. }else{
  470. if (!this.deleteAttributeNode.get("disable")){
  471. this.deleteAttributeNode.set({
  472. "styles": this.style.deleteDutyNode_desable,
  473. "disable": true
  474. });
  475. this.deleteAttributeNode.removeEvents("click");
  476. }
  477. }
  478. },
  479. deleteAttribute: function(e){
  480. var _self = this;
  481. this.explorer.app.confirm("infor", e, this.explorer.app.lp.deleteAttributeTitle, this.explorer.app.lp.deleteAttribute, 300, 120, function(){
  482. this.close();
  483. _self.selectedAttributes.each(function(attribute){
  484. attribute.remove();
  485. });
  486. delete _self.selectedAttributes;
  487. _self.selectedAttribute = [];
  488. _self.checkDeleteAttributeAction();
  489. }, function(){this.close();});
  490. },
  491. listAttribute: function(){
  492. var html = "<table cellspacing='0' cellpadding='5' border='0' width='95%' align='center' style='line-height:normal'>";
  493. html += "<tr><th style='width:20px'></th>";
  494. html += "<th style='width: 30%; border-right: 1px solid #FFF'>"+this.explorer.app.lp.attributeName+"</th>";
  495. html += "<th>"+this.explorer.app.lp.attributeValue+"</th><th style='width:20px'></th></tr>";
  496. html += "</table>";
  497. this.propertyAttributeContentNode.set("html", html);
  498. this.propertyAttributeContentNode.getElements("th").setStyles(this.style.propertyDutyContentTdTitle);
  499. if (this.data.id){
  500. this.explorer.actions.listPersonAttribute(function(json){
  501. json.data.each(function(item){
  502. new MWF.xApplication.Organization.PersonAttribute(this.propertyAttributeContentNode.getElement("table").getFirst(), item, this, this.explorer.css.map);
  503. }.bind(this));
  504. }.bind(this), null, this.data.id);
  505. }
  506. },
  507. showItemPropertyIdentity:function(){
  508. MWF.AC.isCompanyEditor({
  509. "yes": function(){
  510. this.propertyIdentityNode = new Element("div", {
  511. "styles": this.style.propertyInforNode
  512. }).inject(this.explorer.propertyContentNode);
  513. this.identityActionNode = new Element("div", {
  514. "styles": this.style.propertyInforActionNode
  515. }).inject(this.propertyIdentityNode);
  516. this.propertyIdentityTextNode = new Element("div", {
  517. "styles": this.style.propertyInforTextNode,
  518. "text": this.explorer.app.lp.personIdentityText
  519. }).inject(this.propertyIdentityNode);
  520. // this.createEditBaseNode();
  521. this.propertyIdentityContentNode = new Element("div", {
  522. "styles": this.style.propertyInforContentNode
  523. }).inject(this.propertyIdentityNode);
  524. this.listIdentity();
  525. }.bind(this)
  526. });
  527. },
  528. listIdentity: function(){
  529. if (this.data.id){
  530. this.explorer.actions.listIdentityByPerson(function(json){
  531. json.data.each(function(item){
  532. new MWF.xApplication.Organization.PersonExplorer.Identity(this.propertyIdentityContentNode, item, this, this.style);
  533. }.bind(this));
  534. }.bind(this), null, this.data.id);
  535. }
  536. },
  537. showItemcontrollerList: function(){
  538. this.controllerListNode = new Element("div", {
  539. "styles": this.style.propertyInforNode
  540. }).inject(this.explorer.propertyContentNode);
  541. this.controllerListActionNode = new Element("div", {
  542. "styles": this.style.propertyInforActionNode
  543. }).inject(this.controllerListNode);
  544. if (MWF.AC.isPersonEditor({"list": this.data.controllerList})){
  545. this.addAttributeNode = new Element("button", {
  546. "styles": this.style.addDutyNode,
  547. "text": this.explorer.app.lp.manager,
  548. "events": {"click": this.changeControllerList.bind(this)}
  549. }).inject(this.controllerListActionNode);
  550. }
  551. this.controllerListTextNode = new Element("div", {
  552. "styles": this.style.propertyInforTextNode,
  553. "text": this.explorer.app.lp.controllerListText
  554. }).inject(this.controllerListNode);
  555. this.controllerListContentNode = new Element("div", {
  556. "styles": this.style.propertyInforContentNode
  557. }).inject(this.controllerListNode);
  558. this.listController();
  559. },
  560. listController: function(){
  561. this.controllerListContentNode.empty();
  562. MWF.require("MWF.widget.Identity", function(){
  563. this.data.controllerList.each(function(id){
  564. this.explorer.actions.getPerson(function(json){
  565. new MWF.widget.Person(json.data, this.controllerListContentNode, this.explorer)
  566. }.bind(this), null, id)
  567. }.bind(this));
  568. }.bind(this));
  569. },
  570. changeControllerList: function(){
  571. var selector = new MWF.OrgSelector(this.explorer.app.content, {
  572. "type": "person",
  573. "values": this.data.controllerList || [],
  574. "onComplete": function(items){
  575. var ids = [];
  576. items.each(function(item){ids.push(item.data.id);});
  577. this.data.controllerList = ids;
  578. this.explorer.actions.savePerson(this.data);
  579. this.listController();
  580. }.bind(this)
  581. });
  582. },
  583. destroy: function(){
  584. this.explorer.currentItem = null;
  585. this.clearItemProperty();
  586. this.node.destroy();
  587. delete this;
  588. },
  589. "delete": function(success, failure){
  590. this.explorer.actions.deletePerson(this.data.id, function(){
  591. this.destroy();
  592. if (success) success();
  593. }.bind(this), function(xhr, text, error){
  594. var errorText = error;
  595. if (xhr) errorText = xhr.responseText;
  596. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  597. if (failure) failure();
  598. });
  599. }
  600. });
  601. MWF.xApplication.Organization.PersonAttribute = new Class({
  602. Extends: MWF.xApplication.Organization.CompanyAttribute,
  603. saveValue: function(value){
  604. var oldValue = this.data.attributeList;
  605. this.data.attributeList = value.split("/,\s*/");
  606. this.item.explorer.actions.savePersonAttribute(this.data, function(json){
  607. this.data.id = json.data.id;
  608. this.valueNode.empty();
  609. this.valueInput = null;
  610. this.valueNode.set("text", this.data.attributeList.join(","));
  611. }.bind(this), function(xhr, text, error){
  612. this.data.attributeList = oldValue;
  613. this.valueInput.focus();
  614. var errorText = error;
  615. if (xhr) errorText = xhr.responseText;
  616. this.item.explorer.app.notice("request json error: "+errorText, "error");
  617. }.bind(this));
  618. },
  619. save: function(name){
  620. var oldName = this.data.name;
  621. this.data.name = name;
  622. this.item.explorer.actions.savePersonAttribute(this.data, function(json){
  623. this.data.id = json.data.id;
  624. this.nameNode.empty();
  625. this.input = null;
  626. this.nameNode.set("text", this.data.name);
  627. }.bind(this), function(xhr, text, error){
  628. this.data.name = oldName;
  629. this.input.focus();
  630. var errorText = error;
  631. if (xhr) errorText = xhr.responseText;
  632. this.item.explorer.app.notice("request json error: "+errorText, "error");
  633. }.bind(this));
  634. },
  635. remove: function(){
  636. this.item.explorer.actions.deletePersonAttribute(this.data.id, function(){
  637. this.node.destroy();
  638. delete this;
  639. }.bind(this));
  640. }
  641. });
  642. MWF.xApplication.Organization.PersonExplorer.Identity = new Class({
  643. initialize: function(container, data, item, style){
  644. this.container = $(container);
  645. this.data = data;
  646. this.style = style;
  647. this.item = item;
  648. this.load();
  649. },
  650. load: function(){
  651. this.node = new Element("div", {
  652. "styles": this.style.identityNode
  653. }).inject(this.container);
  654. var nameNode = new Element("div", {
  655. "styles": this.style.identityInforNameNode
  656. }).inject(this.node);
  657. var img = ""
  658. if (this.item.data.icon){
  659. img = "<img width='50' height='50' border='0' src='data:image/png;base64,"+this.item.data.icon+"'></img>"
  660. }else{
  661. if (this.item.data.genderType=="f"){
  662. img = "<img width='50' height='50' border='0' src='"+"/x_component_Organization/$PersonExplorer/default/icon/female.png'></img>";
  663. }else{
  664. img = "<img width='50' height='50' border='0' src='"+"/x_component_Organization/$PersonExplorer/default/icon/man.png'></img>";
  665. }
  666. }
  667. var picNode = new Element("div", {
  668. "styles": this.style.identityInforPicNode,
  669. "html": img
  670. }).inject(nameNode);
  671. var nameTextNode = new Element("div", {
  672. "styles": this.style.identityInforNameTextNode,
  673. "text": this.data.name
  674. }).inject(nameNode);
  675. var departmentNode = new Element("div", {"styles": this.style.identityDepartmentNode}).inject(this.node);
  676. var departmentTitleNode = new Element("div", {
  677. "styles": this.style.identityTitleNode,
  678. "text": this.item.explorer.app.lp.department
  679. }).inject(departmentNode);
  680. this.departmentTextNode = new Element("div", {"styles": this.style.identityTextNode}).inject(departmentNode);
  681. var companyNode = new Element("div", {"styles": this.style.identityCompanyNode}).inject(this.node);
  682. var companyTitleNode = new Element("div", {
  683. "styles": this.style.identityTitleNode,
  684. "text": this.item.explorer.app.lp.company
  685. }).inject(companyNode);
  686. this.companyTextNode = new Element("div", {"styles": this.style.identityTextNode}).inject(companyNode);
  687. var dutyNode = new Element("div", {"styles": this.style.identityDutyNode}).inject(this.node);
  688. var dutyTitleNode = new Element("div", {
  689. "styles": this.style.identityTitleNode,
  690. "text": this.item.explorer.app.lp.duty
  691. }).inject(dutyNode);
  692. this.dutyTextNode = new Element("div", {"styles": this.style.identityTextNode}).inject(dutyNode);
  693. this.item.explorer.actions.getDepartment(function(json){
  694. this.department = json.data;
  695. this.departmentTextNode.set({"text": this.department.name, "title": this.department.name});
  696. this.item.explorer.actions.getCompany(function(json){
  697. this.company = json.data;
  698. this.companyTextNode.set({"text": this.company.name, "title": this.company.name});
  699. }.bind(this), null, this.department.company);
  700. }.bind(this), null, this.data.department);
  701. this.item.explorer.actions.listCompanyDutyByIdentity(function(json){
  702. json.data.each(function(duty){
  703. var text = this.dutyTextNode.get("text");
  704. if (text){
  705. text = text+", "+duty.name;
  706. }else{
  707. text = duty.name;
  708. }
  709. this.dutyTextNode.set({"text": text, "title": text});
  710. }.bind(this));
  711. }.bind(this), null, this.data.id);
  712. this.item.explorer.actions.listDepartmentDutyByIdentity(function(json){
  713. json.data.each(function(duty){
  714. var text = this.dutyTextNode.get("text");
  715. if (text){
  716. text = text+", "+duty.name;
  717. }else{
  718. text = duty.name;
  719. }
  720. this.dutyTextNode.set({"text": text, "title": text});
  721. }.bind(this));
  722. }.bind(this), null, this.data.id);
  723. }
  724. });