tmp.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. /**
  2. * Created by hq_19 on 2017/5/31.
  3. */
  4. MWF.xApplication.Org.BaseInfor = new Class({
  5. initialize: function(content){
  6. this.content = content;
  7. this.item = content.item;
  8. this.data = this.item.data;
  9. this.explorer = this.item.explorer;
  10. this.contentNode = this.content.baseContentNode;
  11. this.style = this.item.style.person;
  12. this.attributes = [];
  13. this.mode = "read";
  14. this.load();
  15. },
  16. load: function(){
  17. this.baseBgNode = new Element("div", {"styles": this.style.baseBgNode}).inject(this.contentNode);
  18. this.baseNode = new Element("div", {"styles": this.style.baseNode}).inject(this.baseBgNode);
  19. this.baseInforNode = new Element("div", {"styles": this.style.baseInforNode}).inject(this.baseNode);
  20. this.baseInforLeftNode = new Element("div", {"styles": this.style.baseInforLeftNode}).inject(this.baseInforNode);
  21. this.baseInforRightNode = new Element("div", {"styles": this.style.baseInforRightNode}).inject(this.baseInforNode);
  22. // this.actionEditAreaNode = new Element("div", {"styles": this.style.baseInforRightActionAreaNode}).inject(this.baseInforNode);
  23. // this.actionEditContentNode = new Element("div", {"styles": this.style.baseInforRightActionContentNode}).inject(this.actionEditAreaNode);
  24. this.actionAreaNode = new Element("div", {"styles": this.style.actionAreaNode}).inject(this.baseBgNode);
  25. this.loadLeftInfor();
  26. this.loadRightInfor();
  27. this.loadAction();
  28. },
  29. loadAction: function(){
  30. //this.explorer.app.lp.edit
  31. if (MWF.AC.isPersonEditor({"list": this.data.controllerList})){
  32. this.editNode = new Element("div", {"styles": this.style.actionNode, "text": this.explorer.app.lp.edit}).inject(this.actionAreaNode);
  33. var actionAreas = this.baseInforRightNode.getElements("td");
  34. var actionArea = actionAreas[actionAreas.length-1];
  35. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  36. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.save}).inject(this.baseInforEditActionAreaNode);
  37. this.saveNode.addClass("mainColor_bg");
  38. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  39. this.editNode.setStyle("display", "block");
  40. this.editNode.addEvent("click", this.edit.bind(this));
  41. this.saveNode.addEvent("click", this.save.bind(this));
  42. this.cancelNode.addEvent("click", this.cancel.bind(this));
  43. this.iconNode.setStyle("cursor", "pointer");
  44. this.iconNode.addEvent("click", function(){this.changePersonIcon();}.bind(this));
  45. }
  46. },
  47. edit: function(){
  48. this.nameNode.empty();
  49. this.nameInputNode = new Element("input", {"styles": this.style.nameInputNode}).inject(this.nameNode);
  50. this.nameInputNode.set("value", this.data.name);
  51. this.signatureNode.empty();
  52. this.signatureTextNode = new Element("textarea", {"styles": this.style.signatureTextNode}).inject(this.signatureNode);
  53. this.signatureTextNode.set("value", (this.data.signature));
  54. var tdContents = this.baseInforRightNode.getElements("td.inforContent");
  55. tdContents[0].empty();
  56. this.uniqueInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[0]);
  57. this.uniqueInputNode.set("value", (this.data.unique));
  58. tdContents[1].empty();
  59. this.mobileInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[1]);
  60. this.mobileInputNode.set("value", (this.data.mobile));
  61. tdContents[2].empty();
  62. var html = "<input name=\"personGenderRadioNode\" value=\"m\" type=\"radio\" "+((this.data.genderType==="m") ? "checked" : "")+"/>"+this.explorer.app.lp.man;
  63. html += "<input name=\"personGenderRadioNode\" value=\"f\" type=\"radio\" "+((this.data.genderType==="f") ? "checked" : "")+"/>"+this.explorer.app.lp.female;
  64. html += "<input name=\"personGenderRadioNode\" value=\"o\" type=\"radio\" "+((this.data.genderType==="d") ? "checked" : "")+"/>"+this.explorer.app.lp.other;
  65. tdContents[2].set("html", html);
  66. // this.mobileInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[2]);
  67. // this.mobileInputNode.set("value", (this.data.mobile));
  68. tdContents[3].empty();
  69. this.mailInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[3]);
  70. this.mailInputNode.set("value", (this.data.mail));
  71. tdContents[4].empty();
  72. this.employeeInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[4]);
  73. this.employeeInputNode.set("value", (this.data.employee));
  74. tdContents[5].empty();
  75. this.qqInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[5]);
  76. this.qqInputNode.set("value", (this.data.qq));
  77. tdContents[6].empty();
  78. this.displayInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[6]);
  79. this.displayInputNode.set("value", (this.data.display));
  80. tdContents[7].empty();
  81. this.weiboInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[7]);
  82. this.weiboInputNode.set("value", (this.data.weibo));
  83. var _self = this;
  84. this.baseInforNode.getElements("input").addEvents({
  85. "focus": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_focus);}},
  86. "blur": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_blur);}}
  87. });
  88. this.baseInforNode.getElements("textarea").addEvents({
  89. "focus": function(){this.setStyles(_self.style.inputNode_focus);},
  90. "blur": function(){this.setStyles(_self.style.inputNode_blur);}
  91. });
  92. this.mode = "edit";
  93. this.editNode.setStyle("display", "none");
  94. this.saveNode.setStyle("display", "block");
  95. this.cancelNode.setStyle("display", "block");
  96. },
  97. changePersonIcon: function(){
  98. var options = {};
  99. var width = "668";
  100. var height = "510";
  101. width = width.toInt();
  102. height = height.toInt();
  103. var size = this.explorer.app.content.getSize();
  104. var x = (size.x-width)/2;
  105. var y = (size.y-height)/2;
  106. if (x<0) x = 0;
  107. if (y<0) y = 0;
  108. if (layout.mobile){
  109. x = 20;
  110. y = 0;
  111. }
  112. var _self = this;
  113. MWF.require("MWF.xDesktop.Dialog", function() {
  114. MWF.require("MWF.widget.ImageClipper", function(){
  115. var dlg = new MWF.xDesktop.Dialog({
  116. "title": this.explorer.app.lp.changePersonIcon,
  117. "style": "image",
  118. "top": y,
  119. "left": x - 20,
  120. "fromTop": y,
  121. "fromLeft": x - 20,
  122. "width": width,
  123. "height": height,
  124. "html": "<div></div>",
  125. "maskNode": this.explorer.app.content,
  126. "container": this.explorer.app.content,
  127. "buttonList": [
  128. {
  129. "text": MWF.LP.process.button.ok,
  130. "action": function () {
  131. _self.uploadPersonIcon();
  132. this.close();
  133. }
  134. },
  135. {
  136. "text": MWF.LP.process.button.cancel,
  137. "action": function () {
  138. _self.image = null;
  139. this.close();
  140. }
  141. }
  142. ]
  143. });
  144. dlg.show();
  145. this.image = new MWF.widget.ImageClipper(dlg.content.getFirst(), {
  146. "aspectRatio": 1,
  147. "description" : "",
  148. "imageUrl" : "",
  149. "resetEnable" : false
  150. });
  151. this.image.load(this.data.icon);
  152. }.bind(this));
  153. }.bind(this))
  154. },
  155. uploadPersonIcon: function(){
  156. if (this.image){
  157. if( this.image.getResizedImage() ){
  158. this.explorer.actions.changePersonIcon(this.data.id ,function(){
  159. this.explorer.actions.getPerson(function(json){
  160. if (json.data){
  161. this.data.icon = json.data.icon;
  162. if (this.data.icon){
  163. this.iconNode.set("src", this._getIcon());
  164. this.item.iconNode.getElement("img").set("src", this.item._getIcon());
  165. }
  166. }
  167. }.bind(this), null, this.data.id, false)
  168. }.bind(this), null, this.image.getFormData(), this.image.resizedImage);
  169. }
  170. }
  171. },
  172. save: function(){
  173. var tdContents = this.baseInforRightNode.getElements("td.inforContent");
  174. var gender = "";
  175. var radios = tdContents[2].getElements("input");
  176. for (var i=0; i<radios.length; i++){
  177. if (radios[i].checked){
  178. gender = radios[i].value;
  179. break;
  180. }
  181. }
  182. if (!this.nameInputNode.get("value") || !this.uniqueInputNode.get("value") || !this.employeeInputNode.get("value") || !gender){
  183. this.explorer.app.notice(this.explorer.app.lp.inputPersonInfor, "error", this.explorer.propertyContentNode);
  184. return false;
  185. }
  186. if (!this.displayInputNode.get("value")) this.data.display = this.nameInputNode.get("value");
  187. this.baseBgNode.mask({
  188. "style": {
  189. "opacity": 0.7,
  190. "background-color": "#999"
  191. }
  192. });
  193. this.savePerson(function(){
  194. this.cancel();
  195. this.baseBgNode.unmask();
  196. }.bind(this), function(xhr, text, error){
  197. var errorText = error;
  198. if (xhr) errorText = xhr.responseText;
  199. this.explorer.app.notice("request json error: "+errorText, "error");
  200. this.baseBgNode.unmask();
  201. }.bind(this));
  202. },
  203. savePerson: function(callback, cancel){
  204. this.data.name = this.nameInputNode.get("value");
  205. this.data.employee = this.employeeInputNode.get("value");
  206. this.data.unique = this.uniqueInputNode.get("value");
  207. this.data.display = this.displayInputNode.get("value");
  208. this.data.mobile = this.mobileInputNode.get("value");
  209. this.data.mail = this.mailInputNode.get("value");
  210. this.data.qq = this.qqInputNode.get("value");
  211. //this.data.weixin = this.personWeixinInput.input.get("value");
  212. this.data.weibo = this.weiboInputNode.get("value")
  213. var tdContents = this.baseInforRightNode.getElements("td.inforContent");
  214. var radios = tdContents[2].getElements("input");
  215. for (var i=0; i<radios.length; i++){
  216. if (radios[i].checked){
  217. this.data.genderType = radios[i].value;
  218. break;
  219. }
  220. }
  221. this.explorer.actions.savePerson(this.data, function(json){
  222. this.data.id = json.data.id;
  223. this.iconNode.set("src", this._getIcon());
  224. if (callback) callback();
  225. }.bind(this), function(xhr, text, error){
  226. if (cancel) cancel(xhr, text, error);
  227. }.bind(this));
  228. },
  229. cancel: function(){
  230. this.nameNode.set("html", this.data.name);
  231. this.signatureNode.set("html", this.data.signature || this.explorer.options.lp.noSignature);
  232. var tdContents = this.baseInforRightNode.getElements("td.inforContent");
  233. tdContents[0].set("html", this.data.unique || "");
  234. tdContents[1].set("html", this.data.mobile || "");
  235. tdContents[2].set("html", this.getGenderType());
  236. tdContents[3].set("html", this.data.mail || "");
  237. tdContents[4].set("html", this.data.employee || "");
  238. tdContents[5].set("html", this.data.qq || "");
  239. tdContents[6].set("html", this.data.display || "");
  240. tdContents[7].set("html", this.data.weibo || "");
  241. this.mode = "read";
  242. this.editNode.setStyle("display", "block");
  243. this.saveNode.setStyle("display", "none");
  244. this.cancelNode.setStyle("display", "none");
  245. },
  246. getGenderType: function(){
  247. var text = "";
  248. if (this.data.genderType){
  249. switch (this.data.genderType) {
  250. case "m":
  251. text = this.explorer.app.lp.man;
  252. break;
  253. case "f":
  254. text = this.explorer.app.lp.female;
  255. break;
  256. default:
  257. text = this.explorer.app.lp.other;
  258. }
  259. }
  260. return text;
  261. },
  262. loadLeftInfor: function(){
  263. this.iconAreaNode = new Element("div", {"styles": this.style.baseInforIconAreaNode}).inject(this.baseInforLeftNode);
  264. this.iconNode = new Element("img", {"styles": this.style.baseInforIconNode}).inject(this.iconAreaNode);
  265. this.iconNode.set("src", this._getIcon());
  266. this.nameNode = new Element("div", {"styles": this.style.baseInforNameNode, "text": this.data.name}).inject(this.baseInforLeftNode);
  267. this.signatureNode = new Element("div", {"styles": this.style.baseInforSignatureNode}).inject(this.baseInforLeftNode);
  268. this.signatureNode.set("text", (this.data.signature || this.explorer.options.lp.noSignature ));
  269. },
  270. loadRightInfor: function(){
  271. // var text = "";
  272. // if (this.data.genderType){
  273. // switch (this.data.genderType) {
  274. // case "m":
  275. // text = this.explorer.app.lp.man;
  276. // break;
  277. // case "f":
  278. // text = this.explorer.app.lp.female;
  279. // break;
  280. // default:
  281. // text = this.explorer.app.lp.other;
  282. // }
  283. // }
  284. var html = "<table cellpadding='3px' cellspacing='3px'>";
  285. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personUnique+"</td><td class='inforContent'>"+(this.data.unique || "")+"</td>" +
  286. "<td class='inforTitle'>"+this.explorer.app.lp.personMobile+"</td><td class='inforContent'>"+(this.data.mobile || "")+"</td></tr>";
  287. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personGender+"</td><td class='inforContent'>"+this.getGenderType()+"</td>" +
  288. "<td class='inforTitle'>"+this.explorer.app.lp.personMail+"</td><td class='inforContent'>"+(this.data.mail || "")+"</td></tr>";
  289. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personEmployee+"</td><td class='inforContent'>"+(this.data.employee || "")+"</td>" +
  290. "<td class='inforTitle'>"+this.explorer.app.lp.personQQ+"</td><td class='inforContent'>"+(this.data.qq || "")+"</td></tr>";
  291. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personDisplay+"</td><td class='inforContent'>"+(this.data.display || "")+"</td>" +
  292. "<td class='inforTitle'>"+this.explorer.app.lp.personWeixin+"</td><td class='inforContent'>"+(this.data.weibo || "")+"</td></tr>";
  293. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  294. this.baseInforRightNode.set("html", html);
  295. this.baseInforRightNode.getElements("td.inforTitle").setStyles(this.style.baseInforRightTitleNode);
  296. this.baseInforRightNode.getElements("td.inforContent").setStyles(this.style.baseInforRightContentNode);
  297. this.baseInforRightNode.getElements("td.inforAction").setStyles(this.style.baseInforRightActionNode);
  298. },
  299. destroy: function(){
  300. this.baseBgNode.empty();
  301. this.baseBgNode.destroy();
  302. MWF.release(this);
  303. },
  304. _getIcon: function(){
  305. var src = "data:image/png;base64,"+this.data.icon;
  306. if (!this.data.icon){
  307. if (this.data.genderType==="f"){
  308. src = "../x_component_Org/$Explorer/default/icon/female.png"
  309. }else{
  310. src = "../x_component_Org/$Explorer/default/icon/man.png"
  311. }
  312. }
  313. return src;
  314. }
  315. });
  316. MWF.xApplication.Org.attribute = new Class({
  317. initialize: function(container, data, item, style){
  318. this.container = $(container);
  319. this.data = data;
  320. this.style = style;
  321. this.item = item;
  322. this.selected = false;
  323. this.load();
  324. },
  325. load: function(){
  326. this.node = new Element("tr", {
  327. "styles": this.style.contentTrNode
  328. }).inject(this.container);
  329. this.selectNode = new Element("td", {
  330. "styles": this.style.selectNode
  331. }).inject(this.node);
  332. this.nameNode = new Element("td", {
  333. "styles": this.style.nameNode,
  334. "html": (this.data.name) ? this.data.name : "<input type='text'/>"
  335. }).inject(this.node);
  336. this.input = this.nameNode.getFirst("input");
  337. if (this.input) this.setEditNameInput();
  338. this.valueNode = new Element("td", {
  339. "styles": this.style.valueNode
  340. }).inject(this.node);
  341. // this.createActionNode();
  342. // this.setEvent();
  343. this.loadValue();
  344. },
  345. loadValue: function(){
  346. if (this.data.attributeList) this.valueNode.set("text", this.data.attributeList.join(","));
  347. },
  348. destroy: function(){
  349. this.node.destroy();
  350. MWF.release(this);
  351. },
  352. createActionNode: function(){
  353. this.actionNode = new Element("td", {"styles": this.style.actionAttributeNode}).inject(this.node);
  354. },
  355. selectNodeClick: function(){
  356. if (!this.selected){
  357. this.selected = true;
  358. this.selectNode.setStyles(this.style.selectNode_selected);
  359. this.node.setStyles(this.style.contentNode_selected);
  360. this.item.selectedAttributes.push(this);
  361. this.item.checkDeleteAttributeAction();
  362. }else{
  363. this.selected = false;
  364. this.selectNode.setStyles(this.style.selectNode);
  365. this.node.setStyles(this.style.contentNode);
  366. this.item.selectedAttributes.erase(this);
  367. this.item.checkDeleteAttributeAction();
  368. }
  369. },
  370. valueNodeClick: function(){
  371. this.valueNode.addEvent("click", function(){
  372. if (!this.valueInput){
  373. this.valueNode.empty();
  374. this.valueInput = new Element("input", {"type": "text", "value": (this.data.attributeList) ? this.data.attributeList.join(",") : ""}).inject(this.valueNode);
  375. this.setEditValueInput();
  376. }
  377. }.bind(this));
  378. },
  379. setEditValueInput: function(){
  380. this.valueInput.setStyles(this.style.nameInputNode);
  381. this.valueInput.focus();
  382. this.valueInput.addEvents({
  383. "blur": function(){
  384. var value = this.valueInput.get("value");
  385. if (value){
  386. if (value != this.data.attributeList.join(",")){
  387. this.saveValue(value);
  388. }else{
  389. this.valueNode.empty();
  390. this.valueInput = null;
  391. this.valueNode.set("text", this.data.attributeList.join(","));
  392. }
  393. }else{
  394. if (!this.data.id){
  395. this.node.destroy();
  396. delete this;
  397. }else{
  398. this.valueNode.empty();
  399. this.valueInput = null;
  400. this.valueNode.set("text", this.data.attributeList.join(","));
  401. }
  402. }
  403. }.bind(this)
  404. });
  405. },
  406. saveValue: function(value){
  407. var oldValue = this.data.attributeList;
  408. this.data.attributeList = value.split("/,\s*/");
  409. this.item.explorer.actions.saveCompanyAttribute(this.data, function(json){
  410. this.data.id = json.data.id;
  411. this.valueNode.empty();
  412. this.valueInput = null;
  413. this.valueNode.set("text", this.data.attributeList.join(","));
  414. }.bind(this), function(xhr, text, error){
  415. this.data.attributeList = oldValue;
  416. this.valueInput.focus();
  417. var errorText = error;
  418. if (xhr) errorText = xhr.responseText;
  419. this.item.explorer.app.notice("request json error: "+errorText, "error");
  420. }.bind(this));
  421. },
  422. save: function(name){
  423. var oldName = this.data.name;
  424. this.data.name = name;
  425. this.item.explorer.actions.saveCompanyAttribute(this.data, function(json){
  426. this.data.id = json.data.id;
  427. this.nameNode.empty();
  428. this.input = null;
  429. this.nameNode.set("text", this.data.name);
  430. }.bind(this), function(xhr, text, error){
  431. this.data.name = oldName;
  432. this.input.focus();
  433. var errorText = error;
  434. if (xhr) errorText = xhr.responseText;
  435. this.item.explorer.app.notice("request json error: "+errorText, "error");
  436. }.bind(this));
  437. },
  438. remove: function(){
  439. this.item.explorer.actions.deleteCompanyAttribute(this.data.id, function(){
  440. this.node.destroy();
  441. delete this;
  442. }.bind(this));
  443. }
  444. });
  445. MWF.xApplication.Org.PersonExplorer.PersonAttribute = new Class({
  446. Extends: MWF.xApplication.Org.attribute
  447. });
  448. MWF.xApplication.Org.PersonExplorer.PersonIdentity = new Class({
  449. Extends: MWF.xApplication.Org.attribute,
  450. load: function(){
  451. this.node = new Element("tr", {
  452. "styles": this.style.contentTrNode
  453. }).inject(this.container);
  454. this.selectNode = new Element("td", {
  455. "styles": this.style.selectNode
  456. }).inject(this.node);
  457. this.nameNode = new Element("td", {
  458. "styles": this.style.nameNode,
  459. "html": (this.data.name) ? this.data.name : "<input type='text'/>"
  460. }).inject(this.node);
  461. this.input = this.nameNode.getFirst("input");
  462. if (this.input) this.setEditNameInput();
  463. this.departmentNode = new Element("td", {
  464. "styles": this.style.valueNode,
  465. "text": this.data.departmentName
  466. }).inject(this.node);
  467. this.companyNode = new Element("td", {
  468. "styles": this.style.valueNode,
  469. "text": this.data.companyName
  470. }).inject(this.node);
  471. this.valueNode = new Element("td", {
  472. "styles": this.style.valueNode
  473. }).inject(this.node);
  474. // this.createActionNode();
  475. // this.setEvent();
  476. //this.loadValue();
  477. }
  478. });