tmp.js 23 KB

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