PersonExplorer.js 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  1. // MWF.xDesktop.requireApp("Organization", "GroupExplorer", null, false);
  2. // MWF.xDesktop.requireApp("Organization", "OrgExplorer", null, false);
  3. MWF.xDesktop.requireApp("Org", "List", null, false);
  4. MWF.xApplication.Org.PersonExplorer = new Class({
  5. //Extends: MWF.xApplication.Org.GroupExplorer,
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default"
  10. },
  11. _loadPath: function(){
  12. this.path = "/x_component_Org/$Explorer/";
  13. this.cssPath = "/x_component_Org/$Explorer/"+this.options.style+"/css.wcss";
  14. },
  15. initialize: function(node, actions, options){
  16. this.setOptions(options);
  17. this._loadPath();
  18. this._loadCss();
  19. this.actions = actions;
  20. this.node = $(node);
  21. this.loaddingElement = false;
  22. this.elements = [];
  23. this.isElementLoaded = false;
  24. this.loadElementQueue = 0;
  25. this.deleteElements = [];
  26. },
  27. _loadLp: function(){
  28. this.options.lp = {
  29. "elementLoaded": this.app.lp.personLoaded,
  30. "search": this.app.lp.search,
  31. "searchText": this.app.lp.searchText,
  32. "elementSave": this.app.lp.personSave,
  33. "deleteElements": this.app.lp.deletePersons,
  34. "deleteElementsCancel": this.app.lp.deleteElementsCancel,
  35. "deleteElementsTitle": this.app.lp.deletePersonsTitle,
  36. "deleteElementsConfirm": this.app.lp.deletePersonsConfirm,
  37. "elementBaseText": this.app.lp.roleBaseText,
  38. "elementName": this.app.lp.roleName,
  39. "noSignature": this.app.lp.noSignature,
  40. "edit": this.app.lp.edit,
  41. "cancel": this.app.lp.cancel,
  42. "save": this.app.lp.save,
  43. "add": this.app.lp.add
  44. }
  45. },
  46. clear: function(){
  47. this.loaddingElement = false;
  48. this.isElementLoaded = false;
  49. this.loadElementQueue = 0;
  50. this.listNode.empty();
  51. },
  52. load: function(){
  53. this._loadLp();
  54. this.loadLayout();
  55. this.loadList();
  56. },
  57. loadLayout: function(){
  58. this.listAreaNode = new Element("div", {"styles": this.css.listAreaNode}).inject(this.node);
  59. this.propertyAreaNode = new Element("div", {"styles": this.css.propertyAreaNode}).inject(this.node);
  60. this.resizeBarNode = new Element("div", {"styles": this.css.resizeBarNode}).inject(this.propertyAreaNode);
  61. this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.propertyAreaNode);
  62. this.propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  63. this.propertyContentNode = new Element("div", {"styles": this.css.propertyContentNode}).inject(this.propertyNode);
  64. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode}).inject(this.listAreaNode);
  65. this.listScrollNode = new Element("div", {"styles": this.css.listScrollNode}).inject(this.listAreaNode);
  66. this.listNode = new Element("div", {"styles": this.css.listNode}).inject(this.listScrollNode);
  67. this.loadToolbar();
  68. this.resizePropertyContentNode();
  69. this.app.addEvent("resize", function(){this.resizePropertyContentNode();}.bind(this));
  70. this.loadScroll();
  71. this.loadResize();
  72. },
  73. loadToolbar: function(){
  74. if (MWF.AC.isCompanyCreator() || MWF.AC.isPersonManager()) {
  75. this.isEditor = true;
  76. this.addTopElementNode = new Element("div", {"styles": this.css.addTopGroupNode}).inject(this.toolbarNode);
  77. this.addTopElementNode.addEvent("click", function () {
  78. this.addTopElement();
  79. }.bind(this));
  80. }
  81. this.createSearchNode();
  82. this.loadPingyinArea();
  83. },
  84. loadPingyinArea: function(){
  85. this.pingyinAction = new Element("div", {"styles": this.css.pingyinAction}).inject(this.app.pingyinArea);
  86. this.pingyinAction.addEvent("click", function(e){
  87. if (!this.pingyinNode) this.createPingyinNode();
  88. if (this.pingyinMorph){
  89. if (!this.pingyinMorph.isRunning()){
  90. if (this.pingyinNode.getStyle("display")==="none"){
  91. this.showPingyin();
  92. }else{
  93. this.hidePingyin();
  94. }
  95. }
  96. }else{
  97. this.showPingyin();
  98. }
  99. }.bind(this));
  100. this.pingyinAction.addEvent("mousedown", function(e){e.stopPropagation();});
  101. this.hidePingyinFun = this.hidePingyin.bind(this);
  102. this.app.content.addEvent("mousedown", this.hidePingyinFun);
  103. this.app.addEvent("queryClose", function(){
  104. this.app.content.removeEvent("mousedown", this.hidePingyinFun);
  105. }.bind(this));
  106. },
  107. hidePingyin: function(){
  108. if (this.pingyinNode){
  109. if (!this.pingyinMorph){
  110. this.pingyinMorph = new Fx.Morph(this.pingyinNode, {duration: 50, link: "chain"});
  111. }
  112. if (!this.pingyinMorph.isRunning()){
  113. if (this.pingyinNode.getStyle("display")!=="none"){
  114. this.pingyinMorph.start(this.css.pingyinNode).chain(function(){
  115. this.pingyinNode.setStyle("display", "none");
  116. }.bind(this));
  117. }
  118. }
  119. }
  120. },
  121. showPingyin: function(){
  122. this.resizePropertyContentNode();
  123. if (!this.pingyinMorph){
  124. this.pingyinMorph = new Fx.Morph(this.pingyinNode, {duration: 50, link: "chain"});
  125. }
  126. this.pingyinNode.setStyle("display", "block");
  127. this.pingyinMorph.start(this.css.pingyinNode_to).chain(function(){
  128. this.pingyinNode.setStyles(this.css.pingyinNode_to);
  129. }.bind(this));
  130. },
  131. setPingyinNodePosition: function(){
  132. this.pingyinNode.position({
  133. relativeTo: this.node,
  134. position: "leftTop",
  135. edge: "leftTop"
  136. });
  137. },
  138. createPingyinNode: function(){
  139. this.pingyinNode = new Element("div", {"styles": this.css.pingyinNode}).inject(this.node);
  140. this.pingyinNode.addEvent("mousedown", function(e){e.stopPropagation();});
  141. letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
  142. letters.each(function(l){
  143. var letterNode = new Element("div", {"styles": this.css.letterNode,"text": l}).inject(this.pingyinNode);
  144. letterNode.addEvents({
  145. "mouseover": function(e){
  146. e.target.setStyles(this.css.letterNode_over);
  147. }.bind(this),
  148. "mouseout": function(e){
  149. e.target.setStyles(this.css.letterNode);
  150. }.bind(this),
  151. "click": function(e){
  152. this.searchInputNode.set("value", e.target.get("text"));
  153. this.searchOrg();
  154. this.hidePingyin();
  155. }.bind(this)
  156. });
  157. }.bind(this));
  158. },
  159. addTopElement: function(){
  160. var isNewElement = true;
  161. if (this.currentItem) isNewElement = this.currentItem.unSelected();
  162. if (isNewElement){
  163. var newElementData = this._getAddElementData();
  164. var item = this._newElement(newElementData, this);
  165. item.load();
  166. item.selected();
  167. item.editBaseInfor();
  168. (new Fx.Scroll(this.chartScrollNode)).toElementCenter(item.node);
  169. }else{
  170. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  171. }
  172. },
  173. createSearchNode: function(){
  174. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.toolbarNode);
  175. this.searchButtonNode = new Element("div", {"styles": this.css.searchButtonNode,"title": this.options.lp.search}).inject(this.searchNode);
  176. this.searchButtonNode.addEvent("click", function(){this.searchOrg();}.bind(this));
  177. this.searchInputAreaNode = new Element("div", {"styles": this.css.searchInputAreaNode}).inject(this.searchNode);
  178. this.searchInputNode = new Element("input", {
  179. "type": "text",
  180. "value": this.options.lp.searchText,
  181. "styles": this.css.searchInputNode,
  182. "x-webkit-speech": "1"
  183. }).inject(this.searchInputAreaNode);
  184. var _self = this;
  185. this.searchInputNode.addEvents({
  186. "focus": function(){if (this.value ===_self.options.lp.searchText) this.set("value", "");},
  187. "blur": function(){if (!this.value) this.set("value", _self.options.lp.searchText);},
  188. "keydown": function(e){
  189. if (e.code===13){
  190. this.searchOrg();
  191. e.preventDefault();
  192. }
  193. }.bind(this),
  194. "selectstart": function(e){e.preventDefault();},
  195. "change": function(){
  196. var key = this.searchInputNode.get("value");
  197. if (!key || key===this.options.lp.searchText) {
  198. if (this.currentItem){
  199. if (this.currentItem.unSelected()){
  200. this.clear();
  201. this.loadElements();
  202. }else{
  203. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  204. }
  205. }
  206. }
  207. }.bind(this)
  208. });
  209. this.searchButtonNode.addEvent("click", function(){this.searchOrg();}.bind(this));
  210. },
  211. searchOrg: function(){
  212. var key = this.searchInputNode.get("value");
  213. if (key){
  214. if (key!==this.options.lp.searchText){
  215. var isSearchElement = true;
  216. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  217. if (isSearchElement){
  218. this._listElementByKey(function(json){
  219. if (this.currentItem) this.currentItem.unSelected();
  220. this.clear();
  221. json.data.each(function(itemData){
  222. var item = this._newElement(itemData, this);
  223. item.load();
  224. }.bind(this));
  225. }.bind(this), null, key);
  226. }else{
  227. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  228. }
  229. }else{
  230. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  231. if (isSearchElement){
  232. this.clear();
  233. this.loadElements();
  234. }else{
  235. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  236. }
  237. }
  238. }else{
  239. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  240. if (isSearchElement){
  241. this.clear();
  242. this.loadElements();
  243. }else{
  244. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  245. }
  246. }
  247. },
  248. resizePropertyContentNode: function(){
  249. var size = this.node.getSize();
  250. var tSize = this.propertyTitleNode.getSize();
  251. var mtt = this.propertyTitleNode.getStyle("margin-top").toFloat();
  252. var mbt = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  253. var mtc = this.propertyContentNode.getStyle("margin-top").toFloat();
  254. var mbc = this.propertyContentNode.getStyle("margin-bottom").toFloat();
  255. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  256. this.propertyContentNode.setStyle("height", height);
  257. tSize = this.toolbarNode.getSize();
  258. mtt = this.toolbarNode.getStyle("margin-top").toFloat();
  259. mbt = this.toolbarNode.getStyle("margin-bottom").toFloat();
  260. mtc = this.toolbarNode.getStyle("margin-top").toFloat();
  261. mbc = this.toolbarNode.getStyle("margin-bottom").toFloat();
  262. height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  263. this.listScrollNode.setStyle("height", ""+height+"px");
  264. if (this.pingyinNode){
  265. this.setPingyinNodePosition();
  266. this.pingyinNode.setStyle("height", ""+size.y+"px");
  267. }
  268. },
  269. loadScroll: function(){
  270. MWF.require("MWF.widget.ScrollBar", function(){
  271. var _self = this;
  272. new MWF.widget.ScrollBar(this.listScrollNode, {
  273. "style":"xApp_Organization_Explorer",
  274. "where": "before",
  275. "distance": 100,
  276. "friction": 4,
  277. "axis": {"x": false, "y": true},
  278. "onScroll": function(y){
  279. var scrollSize = _self.listScrollNode.getScrollSize();
  280. var clientSize = _self.listScrollNode.getSize();
  281. var scrollHeight = scrollSize.y-clientSize.y;
  282. if (y+200>scrollHeight) {
  283. if (!_self.isElementLoaded) _self.loadElements();
  284. }
  285. }
  286. });
  287. new MWF.widget.ScrollBar(this.propertyContentNode, {
  288. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  289. });
  290. }.bind(this));
  291. },
  292. loadResize: function(){
  293. this.propertyResize = new Drag(this.resizeBarNode,{
  294. "snap": 1,
  295. "onStart": function(el, e){
  296. var x = e.event.clientX;
  297. var y = e.event.clientY;
  298. el.store("position", {"x": x, "y": y});
  299. var size = this.listAreaNode.getSize();
  300. el.store("initialWidth", size.x);
  301. }.bind(this),
  302. "onDrag": function(el, e){
  303. var x = e.event.clientX;
  304. // var y = e.event.y;
  305. var bodySize = this.node.getSize();
  306. var position = el.retrieve("position");
  307. var initialWidth = el.retrieve("initialWidth").toFloat();
  308. var dx = position.x.toFloat()-x.toFloat();
  309. var width = initialWidth-dx;
  310. if (width> bodySize.x/1.5) width = bodySize.x/1.5;
  311. if (width<300) width = 300;
  312. this.listAreaNode.setStyle("width", width+1);
  313. this.propertyAreaNode.setStyle("margin-left", width);
  314. }.bind(this)
  315. });
  316. },
  317. getPageNodeCount: function(){
  318. var size = this.listScrollNode.getSize();
  319. return (size.y / 50).toInt() + 5;
  320. },
  321. loadList: function(){
  322. this.loadElements();
  323. this.app.addEvent("resize", function(){
  324. if (this.elements.length<this.getPageNodeCount()){
  325. this.loadElements(true);
  326. }
  327. }.bind(this));
  328. },
  329. loadElements: function(addToNext){
  330. if (!this.isElementLoaded){
  331. if (!this.loaddingElement){
  332. this.loaddingElement = true;
  333. var count = this.getPageNodeCount();
  334. this._listElementNext(this.getLastLoadedElementId(), count, function(json){
  335. if (json.data.length){
  336. this.loadListContent(json.data);
  337. this.loaddingElement = false;
  338. if (json.data.length<count){
  339. this.isElementLoaded = true;
  340. this.app.notice(this.options.lp.elementLoaded, "ok", this.chartScrollNode, {"x": "center", "y": "bottom"});
  341. }else{
  342. if (this.loadElementQueue>0){
  343. this.loadElementQueue--;
  344. this.loadElements();
  345. }
  346. }
  347. }else{
  348. if (!this.elements.length){
  349. this.setNoGroupNoticeArea();
  350. }else{
  351. this.app.notice(this.options.lp.elementLoaded, "ok", this.chartScrollNode, {"x": "center", "y": "bottom"});
  352. }
  353. this.isElementLoaded = true;
  354. this.loaddingElement = false;
  355. }
  356. }.bind(this));
  357. }else{
  358. if (addToNext) this.loadElementQueue++;
  359. }
  360. }
  361. },
  362. getLastLoadedElementId: function(){
  363. return (this.elements.length) ? this.elements[this.elements.length-1].data.id : "";
  364. },
  365. loadListContent: function(data){
  366. data.each(function(itemData){
  367. var item = this._newElement(itemData, this);
  368. this.elements.push(item);
  369. item.load();
  370. }.bind(this));
  371. },
  372. setNoElementNoticeArea: function(){
  373. //没有数据时的提示
  374. },
  375. checkDeleteElements: function(item){
  376. if (this.deleteElements.length){
  377. if (!this.deleteElementsNode){
  378. this.deleteElementsNode = new Element("div", {"styles": this.css.deleteElementsNode}).inject(this.node);
  379. this.deleteElementsDeleteNode = new Element("div", {"styles": this.css.deleteElementsDeleteNode,"text": this.options.lp.deleteElements}).inject(this.deleteElementsNode);
  380. this.deleteElementsCancelNode = new Element("div", {"styles": this.css.deleteElementsCancelNode,"text": this.options.lp.deleteElementsCancel}).inject(this.deleteElementsNode);
  381. this.deleteElementsDeleteNode.addEvent("click", function(e){this.deleteSelectedElements(e);}.bind(this));
  382. this.deleteElementsCancelNode.addEvent("click", function(e){this.deleteSelectedElementsCancel(e);}.bind(this));
  383. }
  384. this.deleteElementsNode.position({
  385. relativeTo: (item) ? item.node : this.toolbarNode,
  386. position: "centerBottom",
  387. edge: "centerTop"
  388. });
  389. }else{
  390. if (this.deleteElementsNode){
  391. this.deleteElementsNode.destroy();
  392. this.deleteElementsNode = null;
  393. delete this.deleteElementsNode;
  394. }
  395. }
  396. },
  397. deleteSelectedElements: function(e){
  398. var _self = this;
  399. this.app.confirm("infor", e, this.options.lp.deleteElementsTitle, this.options.lp.deleteElementsConfirm, 300, 120, function(){
  400. var deleted = [];
  401. var doCount = 0;
  402. var readyCount = _self.deleteElements.length;
  403. var errorText = "";
  404. var complete;
  405. complete = function () {
  406. if (doCount === readyCount) {
  407. if (errorText) {
  408. _self.app.notice(errorText, "error", _self.propertyContentNode, {x: "left", y: "top"});
  409. }
  410. }
  411. };
  412. _self.deleteElements.each(function(element){
  413. element["delete"](function(){
  414. deleted.push(element);
  415. doCount++;
  416. if (_self.deleteElements.length===doCount){
  417. _self.deleteElements = _self.deleteElements.filter(function (item) {
  418. return !deleted.contains(item);
  419. });
  420. _self.checkDeleteElements();
  421. }
  422. complete();
  423. }, function(error){
  424. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  425. doCount++;
  426. if (_self.deleteElements.length !== doCount) {
  427. } else {
  428. _self.deleteElements = _self.deleteElements.filter(function (item) {
  429. return !deleted.contains(item);
  430. });
  431. _self.checkDeleteElements();
  432. }
  433. complete();
  434. });
  435. });
  436. this.close();
  437. }, function(){
  438. this.close();
  439. });
  440. },
  441. deleteSelectedElementsCancel: function() {
  442. while (this.deleteElements.length){
  443. var element = this.deleteElements[0];
  444. if (element.deleteNode) element.deleteNode.click();
  445. if (this.currentItem!==element){
  446. element.contentNode.setStyles(element.style.contentNode);
  447. if (element.data.id) element.actionNode.fade("out");
  448. }
  449. }
  450. this.checkDeleteElements();
  451. },
  452. destroy: function(){
  453. if (this.hidePingyinFun) this.app.content.removeEvent("mousedown", this.hidePingyinFun);
  454. MWF.release(this);
  455. },
  456. _listElementNext: function(lastid, count, callback){
  457. this.actions.listPersonNext(lastid, count, function(json){
  458. if (callback) {
  459. callback.apply(this, [json]);
  460. }
  461. }.bind(this));
  462. },
  463. _newElement: function(data, explorer){
  464. return new MWF.xApplication.Org.PersonExplorer.Person(data, explorer, this.isEditor);
  465. },
  466. _listElementByKey: function(callback, failure, key){
  467. this.actions.listPersonByKey(function(json){
  468. if (callback) {
  469. callback.apply(this, [json]);
  470. }
  471. }.bind(this), failure, key);
  472. },
  473. _getAddElementData: function(){
  474. return {
  475. "employee": "",
  476. "password": "",
  477. "display": "",
  478. "qq": "",
  479. "mail": "",
  480. "weixin": "",
  481. "weibo": "",
  482. "mobile": "",
  483. "name": "",
  484. "controllerList": []
  485. };
  486. }
  487. });
  488. MWF.xApplication.Org.PersonExplorer.Item = new Class({
  489. //Extends: MWF.xApplication.Organization.GroupExplorer.Group,
  490. initialize: function(data, explorer, isEditor){
  491. this.data = data;
  492. this.explorer = explorer;
  493. this.listNode = this.explorer.listNode;
  494. this.initStyle();
  495. this.selectedAttributes = [];
  496. this.isEdit = false;
  497. this.isEditor = isEditor;
  498. this.deleteSelected = false;
  499. },
  500. initStyle: function(){
  501. this.style = this.explorer.css.item;
  502. },
  503. load: function(){
  504. this.node = new Element("div", {"styles": this.style.node}).inject(this.listNode);
  505. this.contentNode = new Element("div", {"styles": this.style.contentNode}).inject(this.node);
  506. this.iconNode = new Element("div", {"styles": this.style.iconNode}).inject(this.contentNode);
  507. var src = this._getIcon();
  508. var img = new Element("img", {
  509. "styles": this.style.iconImgNode,
  510. "src": src
  511. }).inject(this.iconNode);
  512. this.actionNode = new Element("div", {"styles": this.style.actionNode}).inject(this.contentNode);
  513. this.textNode = new Element("div", {"styles": this.style.textNode}).inject(this.contentNode);
  514. this.textNode.set({"text": this.data.name});
  515. this.setNewItem();
  516. this.node.inject(this.listNode);
  517. this.addActions();
  518. this.setEvent();
  519. },
  520. setNewItem: function(){
  521. if (!this.created){
  522. if (!this.data.id){
  523. this.created = false;
  524. this.contentNode.setStyles(this.style.contentNodeNew);
  525. }else {
  526. this.created = true;
  527. this.contentNode.setStyles(this.style.contentNode);
  528. }
  529. }
  530. },
  531. addActions: function(){
  532. if (this.isEditor){
  533. if (MWF.AC.isPersonEditor({"list": this.data.controllerList})){
  534. this.deleteNode = new Element("div", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  535. // this.addNode = new Element("div", {"styles": this.style.actionAddNode}).inject(this.actionNode);
  536. this.deleteNode.addEvent("click", function(e){
  537. if (!this.deleteSelected){
  538. this.deleteNode.setStyles(this.style.actionDeleteNode_delete);
  539. this.contentNode.setStyles(this.style.contentNode_delete);
  540. this.explorer.deleteElements.push(this);
  541. this.deleteSelected = true;
  542. this.explorer.checkDeleteElements(this);
  543. }else{
  544. if (this.explorer.currentItem!==this){
  545. this.deleteNode.setStyles(this.style.actionDeleteNode);
  546. this.contentNode.setStyles(this.style.contentNode);
  547. }else{
  548. this.contentNode.setStyles(this.style.contentNode_selected);
  549. this.textNode.setStyles(this.style.textNode_selected);
  550. this.actionNode.setStyles(this.style.actionNode_selected);
  551. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  552. }
  553. this.explorer.deleteElements.erase(this);
  554. this.deleteSelected = false;
  555. this.explorer.checkDeleteElements(this);
  556. }
  557. e.stopPropagation();
  558. }.bind(this));
  559. }
  560. }
  561. },
  562. setEvent: function(){
  563. this.contentNode.addEvents({
  564. "mouseover": function(e){
  565. if (this.explorer.currentItem!==this && !this.deleteSelected){
  566. this.contentNode.setStyles(this.style.nodeOver);
  567. if (!this.deleteSelected) if (this.data.id) this.actionNode.fade("in");
  568. }
  569. }.bind(this),
  570. "mouseout": function(e){
  571. if (this.explorer.currentItem!==this && !this.deleteSelected){
  572. this.contentNode.setStyles(this.style.contentNode);
  573. if (!this.deleteSelected) if (this.data.id) this.actionNode.fade("out");
  574. }
  575. }.bind(this),
  576. "click": function(e){
  577. if (this.explorer.currentItem){
  578. if (this.explorer.currentItem.unSelected()){
  579. this.selected();
  580. }else{
  581. this.explorer.app.notice(this.explorer.options.lp.elementSave, "error", this.propertyContentNode);
  582. }
  583. }else{
  584. this.selected();
  585. }
  586. }.bind(this)
  587. });
  588. },
  589. unSelected: function(){
  590. if (this.content.baseInfor.mode==="edit") return false;
  591. this.explorer.currentItem = null;
  592. this.contentNode.setStyles(this.style.contentNode);
  593. this.textNode.setStyles(this.style.textNode);
  594. this.actionNode.setStyles(this.style.actionNode);
  595. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode);
  596. this.clearItemProperty();
  597. return true;
  598. },
  599. clearItemProperty: function(){
  600. this.explorer.propertyTitleNode.empty();
  601. if (this.content) this.content.destroy();
  602. this.explorer.propertyContentNode.empty();
  603. },
  604. selected: function(){
  605. this.explorer.currentItem = this;
  606. this.contentNode.setStyles(this.style.contentNode_selected);
  607. this.textNode.setStyles(this.style.textNode_selected);
  608. this.actionNode.setStyles(this.style.actionNode_selected);
  609. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  610. this.showItemProperty();
  611. },
  612. showItemProperty: function(){
  613. this.content = new MWF.xApplication.Org.PersonExplorer.PersonContent(this);
  614. },
  615. destroy: function(){
  616. if (this.explorer.currentItem===this){
  617. this.explorer.currentItem = null;
  618. this.clearItemProperty();
  619. }
  620. this.node.destroy();
  621. delete this;
  622. },
  623. "delete": function(success, failure){
  624. this.explorer.actions.deletePerson(this.data.id, function(){
  625. this.destroy();
  626. if (success) success();
  627. }.bind(this), function(xhr, text, error){
  628. var errorText = error;
  629. if (xhr) errorText = xhr.responseText;
  630. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  631. if (failure) failure();
  632. });
  633. },
  634. _getIcon: function(){
  635. var src = "data:image/png;base64,"+this.data.icon;
  636. if (!this.data.icon){
  637. if (this.data.genderType==="f"){
  638. src = "/x_component_Org/$Explorer/default/icon/female24.png"
  639. }else{
  640. src = "/x_component_Org/$Explorer/default/icon/man24.png"
  641. }
  642. }
  643. return src;
  644. }
  645. });
  646. MWF.xApplication.Org.PersonExplorer.Person = new Class({
  647. Extends: MWF.xApplication.Org.PersonExplorer.Item
  648. });
  649. MWF.xApplication.Org.PersonExplorer.ItemContent = new Class({
  650. initialize: function(item){
  651. this.item = item;
  652. this.data = this.item.data;
  653. this.explorer = this.item.explorer;
  654. this.contentNode = this.explorer.propertyContentNode;
  655. this.style = this.item.style.person;
  656. this.attributes = [];
  657. this.load();
  658. },
  659. load: function(){
  660. this.explorer.propertyTitleNode.set("text", this.data.name);
  661. this.showItemPropertyBase();
  662. this.showItemPropertyTitle();
  663. this.listAttribute();
  664. this.listIdentity();
  665. this.showAttribute();
  666. //
  667. // if (MWF.AC.isPersonEditor({"list": this.data.controllerList})) this.showItemPropertyAttribute();
  668. // this.showItemPropertyIdentity();
  669. //
  670. // this.showItemcontrollerList();
  671. },
  672. destroy: function(){
  673. if (this.baseInfor) this.baseInfor.destroy();
  674. this.attributes.each(function(attribute){
  675. attribute.destroy();
  676. });
  677. this.contentNode.empty();
  678. MWF.release(this);
  679. },
  680. showItemPropertyBase: function(){
  681. this.baseInfor = new MWF.xApplication.Org.BaseInfor(this);
  682. },
  683. showItemPropertyTitle: function(){
  684. this.propertyTitleNode = new Element("div", {"styles": this.item.style.tabTitleNode}).inject(this.contentNode);
  685. this.propertyTabAreaNode = new Element("div", {"styles": this.item.style.tabAreaNode}).inject(this.propertyTitleNode);
  686. this.attributeTabNode = new Element("div", {"styles": this.item.style.tabNode, "text": this.explorer.app.lp.personAttributeText}).inject(this.propertyTabAreaNode);
  687. this.identityTabNode = new Element("div", {"styles": this.item.style.tabNode, "text": this.explorer.app.lp.personIdentityText}).inject(this.propertyTabAreaNode);
  688. this.managerTabNode = new Element("div", {"styles": this.item.style.tabNode, "text": this.explorer.app.lp.controllerListText}).inject(this.propertyTabAreaNode);
  689. this.attributeTabNode.addEvent("click", this.showAttribute.bind(this));
  690. this.identityTabNode.addEvent("click", this.showIdentity.bind(this));
  691. this.managerTabNode.addEvent("click", this.showManager.bind(this));
  692. },
  693. showAttribute: function(){
  694. this.toggleTab(this.attributeTabNode, this.attributeTabContentNode);
  695. },
  696. showIdentity: function(){
  697. this.toggleTab(this.identityTabNode, this.identityTabContentNode);
  698. },
  699. showManager: function(){
  700. this.toggleTab(this.managerTabNode, this.managerTabContentNode);
  701. },
  702. toggleTab: function(tab, content){
  703. this.attributeTabNode.setStyles(this.item.style.tabNode);
  704. this.identityTabNode.setStyles(this.item.style.tabNode);
  705. this.managerTabNode.setStyles(this.item.style.tabNode);
  706. if (this.attributeTabContentNode) this.attributeTabContentNode.setStyle("display", "none");
  707. if (this.identityTabContentNode) this.identityTabContentNode.setStyle("display", "none");
  708. if (this.managerTabContentNode) this.managerTabContentNode.setStyle("display", "none");
  709. tab.setStyles(this.item.style.tabNode_current);
  710. if (content) content.setStyle("display", "block");
  711. },
  712. listAttribute: function(){
  713. this.attributeTabContentNode = new Element("div", {"styles": this.item.style.tabContentNode}).inject(this.contentNode);
  714. this.attributeList = new MWF.xApplication.Org.List(this.attributeTabContentNode, this, {
  715. "action": MWF.AC.isPersonEditor({"list": this.data.controllerList}),
  716. "data": {
  717. "person": this.data.id,
  718. "name": "",
  719. "attributeList": [""]
  720. },
  721. "attr": ["name", {
  722. "get": function(){return this.attributeList.join(",")},
  723. "set": function(value){debugger;this.attributeList = value.split(/,\s*/g)}
  724. }]
  725. });
  726. this.attributeList.load([
  727. {"style": "width: 20%", "text": this.explorer.app.lp.attributeName},
  728. {"style": "", "text": this.explorer.app.lp.attributeValue}
  729. ]);
  730. if (this.data.id){
  731. this.explorer.actions.listPersonAttribute(function(json){
  732. json.data.each(function(item){
  733. //this.attributes.push(new MWF.xApplication.Org.PersonExplorer.PersonAttribute(this.attributeTabContentNode.getElement("table").getFirst(), item, this, this.explorer.css.list));
  734. this.attributeList.push(item);
  735. }.bind(this));
  736. }.bind(this), null, this.data.id);
  737. }
  738. },
  739. listIdentity: function(){
  740. this.identityTabContentNode = new Element("div", {"styles": this.item.style.tabContentNode}).inject(this.contentNode);
  741. this.identityList = new MWF.xApplication.Org.List(this.identityTabContentNode, this, {
  742. "action": false,
  743. "data": {
  744. "person": this.data.id,
  745. "name": "",
  746. "attributeList": [""]
  747. },
  748. "attr": [
  749. "name", "departmentName", "companyName", "duty"
  750. // {
  751. // "get": function(){return this.attributeList.join(",")},
  752. // "set": function(value){debugger;this.attributeList = value.split(/,\s*/g)}
  753. // }
  754. ]
  755. });
  756. this.identityList.load([
  757. {"style": "width: 20%", "text": this.explorer.app.lp.name},
  758. {"style": "", "text": this.explorer.app.lp.department},
  759. {"style": "", "text": this.explorer.app.lp.company},
  760. {"style": "", "text": this.explorer.app.lp.duty}
  761. ]);
  762. if (this.data.id){
  763. this.explorer.actions.listIdentityByPerson(function(json){
  764. json.data.each(function(item){
  765. debugger;
  766. this.explorer.actions.getDepartment(function(deptJson){
  767. this.explorer.actions.getCompany(function(compJson){
  768. item.companyName = compJson.data.name;
  769. }.bind(this), null, deptJson.data.company);
  770. }.bind(this), null, item.department);
  771. var dutys = [];
  772. this.explorer.actions.listCompanyDutyByIdentity(function(deptDutyJson){
  773. debugger;
  774. deptDutyJson.data.each(function(duty){
  775. duty.name()
  776. var text = this.dutyTextNode.get("text");
  777. if (text){
  778. text = text+", "+duty.name;
  779. }else{
  780. text = duty.name;
  781. }
  782. this.dutyTextNode.set({"text": text, "title": text});
  783. }.bind(this));
  784. }.bind(this), null, item.id);
  785. this.identityList.push(item);
  786. //new MWF.xApplication.Org.PersonExplorer.PersonIdentity(this.propertyIdentityContentNode, item, this, this.style);
  787. }.bind(this));
  788. }.bind(this), null, this.data.id);
  789. }
  790. }
  791. });
  792. MWF.xApplication.Org.PersonExplorer.PersonContent = new Class({
  793. Extends: MWF.xApplication.Org.PersonExplorer.ItemContent
  794. });
  795. MWF.xApplication.Org.BaseInfor = new Class({
  796. initialize: function(content){
  797. this.content = content
  798. this.item = content.item;
  799. this.data = this.item.data;
  800. this.explorer = this.item.explorer;
  801. this.contentNode = this.explorer.propertyContentNode;
  802. this.style = this.item.style.person;
  803. this.attributes = [];
  804. this.mode = "read";
  805. this.load();
  806. },
  807. load: function(){
  808. this.baseBgNode = new Element("div", {"styles": this.style.baseBgNode}).inject(this.contentNode);
  809. this.baseNode = new Element("div", {"styles": this.style.baseNode}).inject(this.baseBgNode);
  810. this.baseInforNode = new Element("div", {"styles": this.style.baseInforNode}).inject(this.baseNode);
  811. this.baseInforLeftNode = new Element("div", {"styles": this.style.baseInforLeftNode}).inject(this.baseInforNode);
  812. this.baseInforRightNode = new Element("div", {"styles": this.style.baseInforRightNode}).inject(this.baseInforNode);
  813. // this.actionEditAreaNode = new Element("div", {"styles": this.style.baseInforRightActionAreaNode}).inject(this.baseInforNode);
  814. // this.actionEditContentNode = new Element("div", {"styles": this.style.baseInforRightActionContentNode}).inject(this.actionEditAreaNode);
  815. this.actionAreaNode = new Element("div", {"styles": this.style.actionAreaNode}).inject(this.baseBgNode);
  816. this.loadLeftInfor();
  817. this.loadRightInfor();
  818. this.loadAction();
  819. },
  820. loadAction: function(){
  821. //this.explorer.app.lp.edit
  822. if (MWF.AC.isPersonEditor({"list": this.data.controllerList})){
  823. this.editNode = new Element("div", {"styles": this.style.actionNode, "text": this.explorer.app.lp.edit}).inject(this.actionAreaNode);
  824. var actionAreas = this.baseInforRightNode.getElements("td");
  825. var actionArea = actionAreas[actionAreas.length-1];
  826. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  827. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.save}).inject(this.baseInforEditActionAreaNode);
  828. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  829. this.editNode.setStyle("display", "block");
  830. this.editNode.addEvent("click", this.edit.bind(this));
  831. this.saveNode.addEvent("click", this.save.bind(this));
  832. this.cancelNode.addEvent("click", this.cancel.bind(this));
  833. this.iconNode.setStyle("cursor", "pointer");
  834. this.iconNode.addEvent("click", function(){this.changePersonIcon();}.bind(this));
  835. }
  836. },
  837. edit: function(){
  838. this.nameNode.empty();
  839. this.nameInputNode = new Element("input", {"styles": this.style.nameInputNode}).inject(this.nameNode);
  840. this.nameInputNode.set("value", this.data.name);
  841. this.signatureNode.empty();
  842. this.signatureTextNode = new Element("textarea", {"styles": this.style.signatureTextNode}).inject(this.signatureNode);
  843. this.signatureTextNode.set("value", (this.data.signature));
  844. var tdContents = this.baseInforRightNode.getElements("td.inforContent");
  845. tdContents[0].empty();
  846. this.uniqueInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[0]);
  847. this.uniqueInputNode.set("value", (this.data.unique));
  848. tdContents[1].empty();
  849. this.mobileInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[1]);
  850. this.mobileInputNode.set("value", (this.data.mobile));
  851. tdContents[2].empty();
  852. var html = "<input name=\"personGenderRadioNode\" value=\"m\" type=\"radio\" "+((this.data.genderType==="m") ? "checked" : "")+"/>"+this.explorer.app.lp.man;
  853. html += "<input name=\"personGenderRadioNode\" value=\"f\" type=\"radio\" "+((this.data.genderType==="f") ? "checked" : "")+"/>"+this.explorer.app.lp.female;
  854. html += "<input name=\"personGenderRadioNode\" value=\"o\" type=\"radio\" "+((this.data.genderType==="d") ? "checked" : "")+"/>"+this.explorer.app.lp.other;
  855. tdContents[2].set("html", html);
  856. // this.mobileInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[2]);
  857. // this.mobileInputNode.set("value", (this.data.mobile));
  858. tdContents[3].empty();
  859. this.mailInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[3]);
  860. this.mailInputNode.set("value", (this.data.mail));
  861. tdContents[4].empty();
  862. this.employeeInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[4]);
  863. this.employeeInputNode.set("value", (this.data.employee));
  864. tdContents[5].empty();
  865. this.qqInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[5]);
  866. this.qqInputNode.set("value", (this.data.qq));
  867. tdContents[6].empty();
  868. this.displayInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[6]);
  869. this.displayInputNode.set("value", (this.data.display));
  870. tdContents[7].empty();
  871. this.weiboInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[7]);
  872. this.weiboInputNode.set("value", (this.data.weibo));
  873. var _self = this;
  874. this.baseInforNode.getElements("input").addEvents({
  875. "focus": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_focus);}},
  876. "blur": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_blur);}}
  877. });
  878. this.baseInforNode.getElements("textarea").addEvents({
  879. "focus": function(){this.setStyles(_self.style.inputNode_focus);},
  880. "blur": function(){this.setStyles(_self.style.inputNode_blur);}
  881. });
  882. this.mode = "edit";
  883. this.editNode.setStyle("display", "none");
  884. this.saveNode.setStyle("display", "block");
  885. this.cancelNode.setStyle("display", "block");
  886. },
  887. changePersonIcon: function(){
  888. var options = {};
  889. var width = "668";
  890. var height = "510";
  891. width = width.toInt();
  892. height = height.toInt();
  893. var size = this.explorer.app.content.getSize();
  894. var x = (size.x-width)/2;
  895. var y = (size.y-height)/2;
  896. if (x<0) x = 0;
  897. if (y<0) y = 0;
  898. if (layout.mobile){
  899. x = 20;
  900. y = 0;
  901. }
  902. var _self = this;
  903. MWF.require("MWF.xDesktop.Dialog", function() {
  904. MWF.require("MWF.widget.ImageClipper", function(){
  905. var dlg = new MWF.xDesktop.Dialog({
  906. "title": this.explorer.app.lp.changePersonIcon,
  907. "style": "image",
  908. "top": y,
  909. "left": x - 20,
  910. "fromTop": y,
  911. "fromLeft": x - 20,
  912. "width": width,
  913. "height": height,
  914. "html": "<div></div>",
  915. "maskNode": this.explorer.app.content,
  916. "container": this.explorer.app.content,
  917. "buttonList": [
  918. {
  919. "text": MWF.LP.process.button.ok,
  920. "action": function () {
  921. _self.uploadPersonIcon();
  922. this.close();
  923. }
  924. },
  925. {
  926. "text": MWF.LP.process.button.cancel,
  927. "action": function () {
  928. _self.image = null;
  929. this.close();
  930. }
  931. }
  932. ]
  933. });
  934. dlg.show();
  935. this.image = new MWF.widget.ImageClipper(dlg.content.getFirst(), {
  936. "aspectRatio": 1,
  937. "description" : "",
  938. "imageUrl" : "",
  939. "resetEnable" : false
  940. });
  941. this.image.load(this.data.icon);
  942. }.bind(this));
  943. }.bind(this))
  944. },
  945. uploadPersonIcon: function(){
  946. if (this.image){
  947. if( this.image.getResizedImage() ){
  948. this.explorer.actions.changePersonIcon(this.data.id ,function(){
  949. this.explorer.actions.getPerson(function(json){
  950. if (json.data){
  951. this.data.icon = json.data.icon;
  952. if (this.data.icon){
  953. this.iconNode.set("src", this._getIcon());
  954. this.item.iconNode.getElement("img").set("src", this.item._getIcon());
  955. }
  956. }
  957. }.bind(this), null, this.data.id, false)
  958. }.bind(this), null, this.image.getFormData(), this.image.resizedImage);
  959. }
  960. }
  961. },
  962. save: function(){
  963. var tdContents = this.baseInforRightNode.getElements("td.inforContent");
  964. var gender = "";
  965. var radios = tdContents[2].getElements("input");
  966. for (var i=0; i<radios.length; i++){
  967. if (radios[i].checked){
  968. gender = radios[i].value;
  969. break;
  970. }
  971. }
  972. if (!this.nameInputNode.get("value") || !this.uniqueInputNode.get("value") || !this.employeeInputNode.get("value") || !gender){
  973. this.explorer.app.notice(this.explorer.app.lp.inputPersonInfor, "error", this.explorer.propertyContentNode);
  974. return false;
  975. }
  976. if (!this.displayInputNode.get("value")) this.data.display = this.nameInputNode.get("value");
  977. this.baseBgNode.mask({
  978. "style": {
  979. "opacity": 0.7,
  980. "background-color": "#999"
  981. }
  982. });
  983. this.savePerson(function(){
  984. this.cancel();
  985. this.baseBgNode.unmask();
  986. }.bind(this), function(xhr, text, error){
  987. var errorText = error;
  988. if (xhr) errorText = xhr.responseText;
  989. this.explorer.app.notice("request json error: "+errorText, "error");
  990. this.baseBgNode.unmask();
  991. }.bind(this));
  992. },
  993. savePerson: function(callback, cancel){
  994. this.data.name = this.nameInputNode.get("value");
  995. this.data.employee = this.employeeInputNode.get("value");
  996. this.data.unique = this.uniqueInputNode.get("value");
  997. this.data.display = this.displayInputNode.get("value");
  998. this.data.mobile = this.mobileInputNode.get("value");
  999. this.data.mail = this.mailInputNode.get("value");
  1000. this.data.qq = this.qqInputNode.get("value");
  1001. //this.data.weixin = this.personWeixinInput.input.get("value");
  1002. this.data.weibo = this.weiboInputNode.get("value")
  1003. var tdContents = this.baseInforRightNode.getElements("td.inforContent");
  1004. var radios = tdContents[2].getElements("input");
  1005. for (var i=0; i<radios.length; i++){
  1006. if (radios[i].checked){
  1007. this.data.genderType = radios[i].value;
  1008. break;
  1009. }
  1010. }
  1011. this.explorer.actions.savePerson(this.data, function(json){
  1012. this.data.id = json.data.id;
  1013. this.iconNode.set("src", this._getIcon());
  1014. if (callback) callback();
  1015. }.bind(this), function(xhr, text, error){
  1016. if (cancel) cancel(xhr, text, error);
  1017. }.bind(this));
  1018. },
  1019. cancel: function(){
  1020. this.nameNode.set("html", this.data.name);
  1021. this.signatureNode.set("html", this.data.signature || this.explorer.options.lp.noSignature);
  1022. var tdContents = this.baseInforRightNode.getElements("td.inforContent");
  1023. tdContents[0].set("html", this.data.unique || "");
  1024. tdContents[1].set("html", this.data.mobile || "");
  1025. tdContents[2].set("html", this.getGenderType());
  1026. tdContents[3].set("html", this.data.mail || "");
  1027. tdContents[4].set("html", this.data.employee || "");
  1028. tdContents[5].set("html", this.data.qq || "");
  1029. tdContents[6].set("html", this.data.display || "");
  1030. tdContents[7].set("html", this.data.weibo || "");
  1031. this.mode = "read";
  1032. this.editNode.setStyle("display", "block");
  1033. this.saveNode.setStyle("display", "none");
  1034. this.cancelNode.setStyle("display", "none");
  1035. },
  1036. getGenderType: function(){
  1037. var text = "";
  1038. if (this.data.genderType){
  1039. switch (this.data.genderType) {
  1040. case "m":
  1041. text = this.explorer.app.lp.man;
  1042. break;
  1043. case "f":
  1044. text = this.explorer.app.lp.female;
  1045. break;
  1046. default:
  1047. text = this.explorer.app.lp.other;
  1048. }
  1049. }
  1050. return text;
  1051. },
  1052. loadLeftInfor: function(){
  1053. this.iconAreaNode = new Element("div", {"styles": this.style.baseInforIconAreaNode}).inject(this.baseInforLeftNode);
  1054. this.iconNode = new Element("img", {"styles": this.style.baseInforIconNode}).inject(this.iconAreaNode);
  1055. this.iconNode.set("src", this._getIcon());
  1056. this.nameNode = new Element("div", {"styles": this.style.baseInforNameNode, "text": this.data.name}).inject(this.baseInforLeftNode);
  1057. this.signatureNode = new Element("div", {"styles": this.style.baseInforSignatureNode}).inject(this.baseInforLeftNode);
  1058. this.signatureNode.set("text", (this.data.signature || this.explorer.options.lp.noSignature ));
  1059. },
  1060. loadRightInfor: function(){
  1061. // var text = "";
  1062. // if (this.data.genderType){
  1063. // switch (this.data.genderType) {
  1064. // case "m":
  1065. // text = this.explorer.app.lp.man;
  1066. // break;
  1067. // case "f":
  1068. // text = this.explorer.app.lp.female;
  1069. // break;
  1070. // default:
  1071. // text = this.explorer.app.lp.other;
  1072. // }
  1073. // }
  1074. var html = "<table cellpadding='3px' cellspacing='3px'>";
  1075. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personUnique+"</td><td class='inforContent'>"+(this.data.unique || "")+"</td>" +
  1076. "<td class='inforTitle'>"+this.explorer.app.lp.personMobile+"</td><td class='inforContent'>"+(this.data.mobile || "")+"</td></tr>";
  1077. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personGender+"</td><td class='inforContent'>"+this.getGenderType()+"</td>" +
  1078. "<td class='inforTitle'>"+this.explorer.app.lp.personMail+"</td><td class='inforContent'>"+(this.data.mail || "")+"</td></tr>";
  1079. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personEmployee+"</td><td class='inforContent'>"+(this.data.employee || "")+"</td>" +
  1080. "<td class='inforTitle'>"+this.explorer.app.lp.personQQ+"</td><td class='inforContent'>"+(this.data.qq || "")+"</td></tr>";
  1081. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.personDisplay+"</td><td class='inforContent'>"+(this.data.display || "")+"</td>" +
  1082. "<td class='inforTitle'>"+this.explorer.app.lp.personWeixin+"</td><td class='inforContent'>"+(this.data.weibo || "")+"</td></tr>";
  1083. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  1084. this.baseInforRightNode.set("html", html);
  1085. this.baseInforRightNode.getElements("td.inforTitle").setStyles(this.style.baseInforRightTitleNode);
  1086. this.baseInforRightNode.getElements("td.inforContent").setStyles(this.style.baseInforRightContentNode);
  1087. this.baseInforRightNode.getElements("td.inforAction").setStyles(this.style.baseInforRightActionNode);
  1088. },
  1089. destroy: function(){
  1090. this.baseBgNode.empty();
  1091. this.baseBgNode.destroy();
  1092. MWF.release(this);
  1093. },
  1094. _getIcon: function(){
  1095. var src = "data:image/png;base64,"+this.data.icon;
  1096. if (!this.data.icon){
  1097. if (this.data.genderType==="f"){
  1098. src = "/x_component_Org/$Explorer/default/icon/female.png"
  1099. }else{
  1100. src = "/x_component_Org/$Explorer/default/icon/man.png"
  1101. }
  1102. }
  1103. return src;
  1104. }
  1105. });
  1106. MWF.xApplication.Org.attribute = new Class({
  1107. initialize: function(container, data, item, style){
  1108. this.container = $(container);
  1109. this.data = data;
  1110. this.style = style;
  1111. this.item = item;
  1112. this.selected = false;
  1113. this.load();
  1114. },
  1115. load: function(){
  1116. this.node = new Element("tr", {
  1117. "styles": this.style.contentTrNode
  1118. }).inject(this.container);
  1119. this.selectNode = new Element("td", {
  1120. "styles": this.style.selectNode
  1121. }).inject(this.node);
  1122. this.nameNode = new Element("td", {
  1123. "styles": this.style.nameNode,
  1124. "html": (this.data.name) ? this.data.name : "<input type='text'/>"
  1125. }).inject(this.node);
  1126. this.input = this.nameNode.getFirst("input");
  1127. if (this.input) this.setEditNameInput();
  1128. this.valueNode = new Element("td", {
  1129. "styles": this.style.valueNode
  1130. }).inject(this.node);
  1131. // this.createActionNode();
  1132. // this.setEvent();
  1133. this.loadValue();
  1134. },
  1135. loadValue: function(){
  1136. if (this.data.attributeList) this.valueNode.set("text", this.data.attributeList.join(","));
  1137. },
  1138. destroy: function(){
  1139. this.node.destroy();
  1140. MWF.release(this);
  1141. },
  1142. createActionNode: function(){
  1143. this.actionNode = new Element("td", {"styles": this.style.actionAttributeNode}).inject(this.node);
  1144. },
  1145. selectNodeClick: function(){
  1146. if (!this.selected){
  1147. this.selected = true;
  1148. this.selectNode.setStyles(this.style.selectNode_selected);
  1149. this.node.setStyles(this.style.contentNode_selected);
  1150. this.item.selectedAttributes.push(this);
  1151. this.item.checkDeleteAttributeAction();
  1152. }else{
  1153. this.selected = false;
  1154. this.selectNode.setStyles(this.style.selectNode);
  1155. this.node.setStyles(this.style.contentNode);
  1156. this.item.selectedAttributes.erase(this);
  1157. this.item.checkDeleteAttributeAction();
  1158. }
  1159. },
  1160. valueNodeClick: function(){
  1161. this.valueNode.addEvent("click", function(){
  1162. if (!this.valueInput){
  1163. this.valueNode.empty();
  1164. this.valueInput = new Element("input", {"type": "text", "value": (this.data.attributeList) ? this.data.attributeList.join(",") : ""}).inject(this.valueNode);
  1165. this.setEditValueInput();
  1166. }
  1167. }.bind(this));
  1168. },
  1169. setEditValueInput: function(){
  1170. this.valueInput.setStyles(this.style.nameInputNode);
  1171. this.valueInput.focus();
  1172. this.valueInput.addEvents({
  1173. "blur": function(){
  1174. var value = this.valueInput.get("value");
  1175. if (value){
  1176. if (value != this.data.attributeList.join(",")){
  1177. this.saveValue(value);
  1178. }else{
  1179. this.valueNode.empty();
  1180. this.valueInput = null;
  1181. this.valueNode.set("text", this.data.attributeList.join(","));
  1182. }
  1183. }else{
  1184. if (!this.data.id){
  1185. this.node.destroy();
  1186. delete this;
  1187. }else{
  1188. this.valueNode.empty();
  1189. this.valueInput = null;
  1190. this.valueNode.set("text", this.data.attributeList.join(","));
  1191. }
  1192. }
  1193. }.bind(this)
  1194. });
  1195. },
  1196. saveValue: function(value){
  1197. var oldValue = this.data.attributeList;
  1198. this.data.attributeList = value.split("/,\s*/");
  1199. this.item.explorer.actions.saveCompanyAttribute(this.data, function(json){
  1200. this.data.id = json.data.id;
  1201. this.valueNode.empty();
  1202. this.valueInput = null;
  1203. this.valueNode.set("text", this.data.attributeList.join(","));
  1204. }.bind(this), function(xhr, text, error){
  1205. this.data.attributeList = oldValue;
  1206. this.valueInput.focus();
  1207. var errorText = error;
  1208. if (xhr) errorText = xhr.responseText;
  1209. this.item.explorer.app.notice("request json error: "+errorText, "error");
  1210. }.bind(this));
  1211. },
  1212. save: function(name){
  1213. var oldName = this.data.name;
  1214. this.data.name = name;
  1215. this.item.explorer.actions.saveCompanyAttribute(this.data, function(json){
  1216. this.data.id = json.data.id;
  1217. this.nameNode.empty();
  1218. this.input = null;
  1219. this.nameNode.set("text", this.data.name);
  1220. }.bind(this), function(xhr, text, error){
  1221. this.data.name = oldName;
  1222. this.input.focus();
  1223. var errorText = error;
  1224. if (xhr) errorText = xhr.responseText;
  1225. this.item.explorer.app.notice("request json error: "+errorText, "error");
  1226. }.bind(this));
  1227. },
  1228. remove: function(){
  1229. this.item.explorer.actions.deleteCompanyAttribute(this.data.id, function(){
  1230. this.node.destroy();
  1231. delete this;
  1232. }.bind(this));
  1233. }
  1234. });
  1235. MWF.xApplication.Org.PersonExplorer.PersonAttribute = new Class({
  1236. Extends: MWF.xApplication.Org.attribute
  1237. });
  1238. MWF.xApplication.Org.PersonExplorer.PersonIdentity = new Class({
  1239. Extends: MWF.xApplication.Org.attribute,
  1240. load: function(){
  1241. this.node = new Element("tr", {
  1242. "styles": this.style.contentTrNode
  1243. }).inject(this.container);
  1244. this.selectNode = new Element("td", {
  1245. "styles": this.style.selectNode
  1246. }).inject(this.node);
  1247. this.nameNode = new Element("td", {
  1248. "styles": this.style.nameNode,
  1249. "html": (this.data.name) ? this.data.name : "<input type='text'/>"
  1250. }).inject(this.node);
  1251. this.input = this.nameNode.getFirst("input");
  1252. if (this.input) this.setEditNameInput();
  1253. this.departmentNode = new Element("td", {
  1254. "styles": this.style.valueNode,
  1255. "text": this.data.departmentName
  1256. }).inject(this.node);
  1257. this.companyNode = new Element("td", {
  1258. "styles": this.style.valueNode,
  1259. "text": this.data.companyName
  1260. }).inject(this.node);
  1261. this.valueNode = new Element("td", {
  1262. "styles": this.style.valueNode
  1263. }).inject(this.node);
  1264. // this.createActionNode();
  1265. // this.setEvent();
  1266. //this.loadValue();
  1267. }
  1268. });