UnitExplorer.js 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. MWF.require("MWF.widget.O2Identity", null, false);
  2. MWF.xDesktop.requireApp("Org", "$Explorer", null, false);
  3. MWF.xApplication.Org.UnitExplorer = new Class({
  4. Extends: MWF.xApplication.Org.$Explorer,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "lp": {
  9. },
  10. "creator": false
  11. },
  12. _loadLp: function(){
  13. this.options.lp = {
  14. "search": this.app.lp.search,
  15. "searchText": this.app.lp.searchText,
  16. "elementSave": this.app.lp.organizationSave,
  17. "deleteElements": this.app.lp.deleteOrganization,
  18. "deleteElementsCancel": this.app.lp.deleteElementsCancel,
  19. "deleteElementsTitle": this.app.lp.deleteOrganizationTitle,
  20. "deleteElementsConfirm": this.app.lp.deleteOrganizationSubConfirm,
  21. "noSignature": this.app.lp.noSignature,
  22. "edit": this.app.lp.edit,
  23. "cancel": this.app.lp.cancel,
  24. "save": this.app.lp.save,
  25. "add": this.app.lp.add
  26. }
  27. },
  28. loadElements: function(addToNext){
  29. if (!this.isElementLoaded){
  30. if (!this.loaddingElement){
  31. this.loaddingElement = true;
  32. this._listElementNext(function(json){
  33. if (json.data.length){
  34. this.loadListContent(json.data);
  35. }else{
  36. if (!this.elements.length){
  37. this.setNoGroupNoticeArea();
  38. }
  39. }
  40. this.loadElementQueue = 0;
  41. this.isElementLoaded = true;
  42. this.loaddingElement = false;
  43. }.bind(this));
  44. }else{
  45. if (addToNext) this.loadElementQueue++;
  46. }
  47. }
  48. },
  49. loadListContent: function(data){
  50. data.each(function(itemData, i){
  51. var item = this._newElement(itemData, this, i);
  52. this.elements.push(item);
  53. item.load();
  54. if (this.elements.length===1){
  55. item.selected();
  56. if (!item.isExpand) item.expand();
  57. }
  58. }.bind(this));
  59. },
  60. _listElementNext: function(callback){
  61. this.actions.listTopUnit(function(json){
  62. if (callback) callback.apply(this, [json]);
  63. }.bind(this));
  64. },
  65. _newElement: function(data, explorer){
  66. return new MWF.xApplication.Org.UnitExplorer.Unit(data, explorer, this.isEditor, 0);
  67. },
  68. _listElementByKey: function(callback, failure, key){
  69. this.actions.listUnitByKey(function(json){
  70. if (callback) callback.apply(this, [json]);
  71. }.bind(this), failure, key);
  72. },
  73. _getAddElementData: function(){
  74. return {
  75. "name": "",
  76. "unique": "",
  77. "typeList": ["company"],
  78. "description": "",
  79. "shortName": "",
  80. "superior": "",
  81. "orderNumber": "",
  82. "controllerList": [],
  83. "control": {
  84. "allowEdit": true,
  85. "allowDelete": true
  86. },
  87. "woSubDirectIdentityList": [],
  88. "woUnitAttributeList": [],
  89. "woUnitDutyList": []
  90. };
  91. },
  92. deleteSelectedElements: function(e){
  93. var _self = this;
  94. this.app.confirm("infor", e, this.options.lp.deleteElementsTitle, {"html": this.options.lp.deleteElementsConfirm}, 500, 260, function(){
  95. var deleted = [];
  96. var doCount = 0;
  97. var readyCount = _self.deleteElements.length;
  98. var errorText = "";
  99. var complete;
  100. complete = function () {
  101. if (doCount === readyCount) {
  102. if (errorText) {
  103. _self.app.notice(errorText, "error", _self.propertyContentNode, {x: "left", y: "top"});
  104. }
  105. }
  106. };
  107. _self.deleteElements.each(function(element){
  108. element["delete"](function(){
  109. deleted.push(element);
  110. doCount++;
  111. if (_self.deleteElements.length===doCount){
  112. _self.deleteElements = _self.deleteElements.filter(function (item) {
  113. return !deleted.contains(item);
  114. });
  115. _self.checkDeleteElements();
  116. }
  117. complete();
  118. }, function(error){
  119. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  120. doCount++;
  121. if (_self.deleteElements.length !== doCount) {
  122. } else {
  123. _self.deleteElements = _self.deleteElements.filter(function (item) {
  124. return !deleted.contains(item);
  125. });
  126. _self.checkDeleteElements();
  127. }
  128. complete();
  129. });
  130. });
  131. this.close();
  132. }, function(){
  133. this.close();
  134. });
  135. }
  136. });
  137. MWF.xApplication.Org.UnitExplorer.Unit = new Class({
  138. Extends: MWF.xApplication.Org.$Explorer.Item,
  139. initialize: function(data, explorer, isEditor, i, listNode, parent){
  140. this.i = i;
  141. this.level = i;
  142. this.parent = parent;
  143. this.data = data;
  144. this.explorer = explorer;
  145. this.listNode = listNode || this.explorer.listNode;
  146. this.propertyContentNode = this.explorer.propertyContentNode;
  147. this.initStyle();
  148. this.selectedAttributes = [];
  149. this.isEdit = false;
  150. this.isEditor = isEditor;
  151. this.deleteSelected = false;
  152. this.subUnits = [];
  153. },
  154. refresh: function(){
  155. this._loadTextNode();
  156. if (this.content){
  157. if (this.content.titleInfor) this.content.titleInfor.refresh();
  158. if (this.content.bottomInfor) this.content.bottomInfor.refresh();
  159. }
  160. this.addActions();
  161. },
  162. initStyle: function(){
  163. var css = Object.clone(this.explorer.css.item);
  164. this.style = Object.merge(css, this.explorer.css.unitItem);
  165. },
  166. _loadTextNode: function(){
  167. this.textNode.set({"text": this.data.name+((this.data.subDirectUnitCount) ? " ("+(this.data.subDirectUnitCount)+")" : "")});
  168. },
  169. load: function(){
  170. this.node = new Element("div", {"styles": this.style.node}).inject(this.listNode);
  171. this.contentNode = new Element("div", {"styles": this.style.contentNode}).inject(this.node);
  172. var left = (10*this.level);
  173. this.contentNode.setStyle("padding-left", ""+left+"px");
  174. if ((this.level%2)===1){
  175. this.node.setStyle("background-color", "#ffffff");
  176. this.contentNode.setStyle("background-color", "#ffffff");
  177. }
  178. this.childNode = new Element("div", {"styles": this.style.childNode}).inject(this.node);
  179. this.toggleIconNode = new Element("div", {"styles": this.style.unitToggleIconNode}).inject(this.contentNode);
  180. this.setToggleIconNode();
  181. this.setToggleAction();
  182. this.iconNode = new Element("div", {"styles": this.style.unitIconNode}).inject(this.contentNode);
  183. var src = this._getIcon();
  184. this.iconNode.setStyle("background-image", "url("+src+")");
  185. this.actionNode = new Element("div", {"styles": this.style.actionNode}).inject(this.contentNode);
  186. this.textNode = new Element("div", {"styles": this.style.unitTextNode}).inject(this.contentNode);
  187. this._loadTextNode();
  188. this.setNewItem();
  189. this.node.inject(this.listNode);
  190. this.addActions();
  191. this.setEvent();
  192. },
  193. addActions: function(){
  194. debugger;
  195. //if (this.isEditor){
  196. if (this.data.id){
  197. if (this.data.control.allowDelete){
  198. if (!this.deleteNode){
  199. this.deleteNode = new Element("div", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  200. this.deleteNode.addEvent("click", function(e){
  201. if (!this.notDelete){
  202. if (!this.deleteSelected){
  203. this.setDelete();
  204. }else{
  205. this.setUndelete();
  206. }
  207. }
  208. e.stopPropagation();
  209. }.bind(this));
  210. }
  211. }
  212. if (this.data.control.allowEdit){
  213. if (!this.addNode){
  214. this.addNode = new Element("div", {"styles": this.style.actionAddNode}).inject(this.actionNode);
  215. this.addNode.addEvent("click", function(e){
  216. if (!this.notDelete){
  217. this.addSubUnit();
  218. }
  219. e.stopPropagation();
  220. }.bind(this));
  221. }
  222. }
  223. if (this.explorer.currentItem===this){
  224. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  225. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected);
  226. }
  227. }
  228. // }
  229. },
  230. addSubUnit: function(){
  231. this.expand(function(){
  232. debugger;
  233. var isNewElement = true;
  234. if (this.explorer.currentItem) isNewElement = this.explorer.currentItem.unSelected();
  235. if (isNewElement){
  236. var newElementData = this.explorer._getAddElementData();
  237. newElementData.superior = this.data.id;
  238. var item = new MWF.xApplication.Org.UnitExplorer.Unit(newElementData, this.explorer, this.isEditor, this.level+1, this.childNode, this);
  239. item.load();
  240. item.selected();
  241. item.editBaseInfor();
  242. (new Fx.Scroll(this.explorer.listScrollNode)).toElementCenter(item.node);
  243. }else{
  244. this.app.notice(this.explorer.options.lp.elementSave, "error", this.explorer.propertyContentNode);
  245. }
  246. }.bind(this));
  247. },
  248. setDeleteFromP: function(){
  249. this.notDelete = true;
  250. this.subUnits.each(function(unit){
  251. unit.setDeleteFromP();
  252. });
  253. this.deleteNode.setStyles(this.style.actionDeleteNode_delete);
  254. this.contentNode.setStyles(this.style.contentNode_delete);
  255. this.textNode.setStyles(this.style.unitTextNode);
  256. //this.explorer.deleteElements.push(this);
  257. this.deleteSelected = true;
  258. this.explorer.checkDeleteElements(this);
  259. },
  260. setDelete: function(){
  261. //this.actionNode.fade("in");
  262. this.subUnits.each(function(unit){
  263. unit.setDeleteFromP();
  264. });
  265. this.deleteNode.setStyles(this.style.actionDeleteNode_delete);
  266. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_delete);
  267. this.contentNode.setStyles(this.style.contentNode_delete);
  268. this.textNode.setStyles(this.style.unitTextNode);
  269. this.explorer.deleteElements.push(this);
  270. this.deleteSelected = true;
  271. this.explorer.checkDeleteElements(this);
  272. },
  273. setUndelete: function(){
  274. //this.actionNode.fade("out");
  275. this.notDelete = false;
  276. this.subUnits.each(function(unit){
  277. unit.setUndelete();
  278. });
  279. if (this.explorer.currentItem!==this){
  280. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode);
  281. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode);
  282. this.contentNode.setStyles(this.style.contentNode);
  283. this.textNode.setStyles(this.style.unitTextNode);
  284. }else{
  285. this.contentNode.setStyles(this.style.contentNode_selected);
  286. this.textNode.setStyles(this.style.textNode_selected);
  287. this.actionNode.setStyles(this.style.actionNode_selected);
  288. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  289. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected);
  290. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected);
  291. }
  292. this.explorer.deleteElements.erase(this);
  293. this.deleteSelected = false;
  294. this.explorer.checkDeleteElements(this);
  295. },
  296. setToggleIconNode: function(){
  297. if (this.data.subDirectUnitCount>0){
  298. var toggle_on = (this.explorer.currentItem===this) ? "toggle_current_on" : "toggle_on";
  299. var toggle_off = (this.explorer.currentItem===this) ? "toggle_current_off" : "toggle_off";
  300. if (this.isExpand){
  301. this.toggleIconNode.setStyle("background-image", "url(/x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/"+toggle_on+".png)");
  302. }else{
  303. this.toggleIconNode.setStyle("background-image", "url(/x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/"+toggle_off+".png)");
  304. }
  305. }else{
  306. this.toggleIconNode.setStyle("background-image", "");
  307. }
  308. },
  309. setToggleAction: function(){
  310. debugger;
  311. this.toggleIconNode.addEvent("click", function(e){
  312. this.expandOrCollapse();
  313. e.stopPropagation();
  314. }.bind(this));
  315. },
  316. expandOrCollapse: function(){
  317. debugger;
  318. if (this.isExpand){
  319. this.collapse();
  320. }else{
  321. this.expand();
  322. }
  323. },
  324. listSubUnit: function(callback){
  325. this.node.mask();
  326. this.explorer.actions.listSubUnitDirect(function(json){
  327. if (json.data.length){
  328. json.data.each(function(itemData){
  329. var item = new MWF.xApplication.Org.UnitExplorer.Unit(itemData, this.explorer, this.isEditor, this.level+1, this.childNode, this);
  330. this.explorer.elements.push(item);
  331. item.load();
  332. this.subUnits.push(item);
  333. }.bind(this));
  334. }
  335. this.isLoadSub = true;
  336. this.node.unmask();
  337. if (callback) callback();
  338. }.bind(this), null, this.data.id);
  339. },
  340. expand: function(callback){
  341. this.childNode.setStyle("display", "block");
  342. this.isExpand = true;
  343. this.setToggleIconNode();
  344. if (!this.isLoadSub){
  345. this.listSubUnit(callback);
  346. }else{
  347. if (callback) callback();
  348. }
  349. },
  350. collapse: function(){
  351. this.childNode.setStyle("display", "none");
  352. this.isExpand = false;
  353. this.setToggleIconNode();
  354. },
  355. unSelected: function(){
  356. if (this.content.baseInfor.mode==="edit") return false;
  357. this.explorer.currentItem = null;
  358. this.contentNode.setStyles(this.style.contentNode);
  359. this.textNode.setStyles(this.style.unitTextNode);
  360. this.actionNode.setStyles(this.style.actionNode);
  361. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode);
  362. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode);
  363. this.iconNode.setStyle("background-image", "url("+this._getIcon()+")");
  364. this.setToggleIconNode();
  365. this.clearItemProperty();
  366. return true;
  367. },
  368. selected: function(){
  369. this.explorer.currentItem = this;
  370. this.contentNode.setStyles(this.style.contentNode_selected);
  371. this.textNode.setStyles(this.style.textNode_selected);
  372. this.actionNode.setStyles(this.style.actionNode_selected);
  373. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  374. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected);
  375. this.iconNode.setStyle("background-image", "url("+this._getIcon()+")");
  376. this.setToggleIconNode();
  377. this.showItemProperty();
  378. },
  379. showItemProperty: function(){
  380. this.content = new MWF.xApplication.Org.UnitExplorer.UnitContent(this);
  381. },
  382. "delete": function(success, failure){
  383. this.explorer.actions.deleteUnit(this.data.id, function(){
  384. this.destroy();
  385. if (success) success();
  386. }.bind(this), function(xhr, text, error){
  387. var errorText = error;
  388. if (xhr) errorText = xhr.responseText;
  389. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  390. if (failure) failure();
  391. });
  392. },
  393. _getIcon: function(){
  394. return (this.explorer.currentItem===this) ? "/x_component_Org/$Explorer/default/icon/unit_current.png" : "/x_component_Org/$Explorer/default/icon/unit.png";
  395. },
  396. _isActionManager: function(){
  397. return (MWF.AC.isOrganizationManager() || MWF.AC.isUnitManager());
  398. }
  399. });
  400. MWF.xApplication.Org.UnitExplorer.UnitContent = new Class({
  401. Extends: MWF.xApplication.Org.$Explorer.ItemContent,
  402. _getData: function(callback){
  403. if (this.item.data.id){
  404. this.explorer.actions.getUnit(function(json){
  405. this.data = json.data;
  406. this.item.data = json.data;
  407. if (callback) callback();
  408. }.bind(this), null, this.item.data.id);
  409. }else{
  410. this.data = this.item.data;
  411. if (callback) callback();
  412. }
  413. },
  414. _showItemPropertyTitle: function(){
  415. this.titleInfor = new MWF.xApplication.Org.UnitExplorer.UnitContent.TitleInfor(this);
  416. },
  417. _showItemPropertyBottom: function(){
  418. this.bottomInfor = new MWF.xApplication.Org.UnitExplorer.UnitContent.BottomInfor(this);
  419. },
  420. loadItemPropertyTab: function(callback){
  421. this.propertyTabContainerNode = new Element("div", {"styles": this.item.style.tabTitleNode}).inject(this.propertyContentNode, "top");
  422. MWF.require("MWF.widget.Tab", function(){
  423. this.propertyTab = new MWF.widget.Tab(this.propertyContentNode, {"style": "unit"});
  424. this.propertyTab.load();
  425. this.propertyTab.tabNodeContainer.inject(this.propertyTabContainerNode);
  426. if (callback) callback();
  427. }.bind(this));
  428. },
  429. _loadTabs: function(){
  430. this.baseContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  431. this.basePage = this.propertyTab.addTab(this.baseContentNode, this.explorer.app.lp.unitBaseText);
  432. this.personMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  433. this.personMemberPage = this.propertyTab.addTab(this.personMemberContentNode, this.explorer.app.lp.unitPersonMembers);
  434. this.dutyContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  435. this.dutyPage = this.propertyTab.addTab(this.dutyContentNode, this.explorer.app.lp.unitDutys);
  436. this.attributeContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  437. this.attributePage = this.propertyTab.addTab(this.attributeContentNode, this.explorer.app.lp.unitAttribute);
  438. },
  439. _loadContent: function(){
  440. this._listBaseInfor();
  441. this.loadListCount();
  442. this._listIdentityMembers();
  443. this._listDutys();
  444. this._listAttributes();
  445. //var _self = this;
  446. // this.personMemberList = this._listMembers("personList", "woSubDirectIdentityList", this.personMemberContentNode, [{
  447. // "get": function(){
  448. // var src = _self.explorer.actions.getPersonIcon(this.person);
  449. // return "<div style='width:24px; height:24px;''><img style='width:24px; height:24px; border-radius:12px; border: 0' src='"+src+"'/></div>";
  450. // },
  451. // "set": function(){}
  452. // }, "name", "employee", "mobile", "mail"], [
  453. // {"style": "width: 30px", "text": ""},
  454. // {"style": "width: 20%", "text": this.explorer.app.lp.personName},
  455. // {"style": "", "text": this.explorer.app.lp.personEmployee},
  456. // {"style": "", "text": this.explorer.app.lp.personMobile},
  457. // {"style": "", "text": this.explorer.app.lp.personMail}
  458. // ], this.addPersonMember.bind(this), "personCountNode");
  459. //
  460. // this.groupMemberList = this._listMembers("groupList", "woGroupList", this.groupMemberContentNode, ["name", "distinguishedName", "description"], [
  461. // {"style": "width: 20%", "text": this.explorer.app.lp.groupName},
  462. // {"style": "width: 40%", "text": this.explorer.app.lp.groupDn},
  463. // {"style": "", "text": this.explorer.app.lp.groupDescription}
  464. // ], this.addGroupMember.bind(this), "groupCountNode");
  465. },
  466. loadListCount: function(){
  467. var identityCount = this.data.woSubDirectIdentityList.length;
  468. if (identityCount){
  469. if (this.identityCountNode){
  470. this.identityCountNode.set("text", identityCount);
  471. }else{
  472. this.identityCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": identityCount}).inject(this.personMemberPage.tabNode);
  473. }
  474. }else{
  475. if (this.identityCountNode) this.identityCountNode.destroy();
  476. }
  477. var dutyCount = this.data.woUnitDutyList.length;
  478. if (dutyCount){
  479. if (this.dutyCountNode){
  480. this.dutyCountNode.set("text", dutyCount);
  481. }else{
  482. this.dutyCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": dutyCount}).inject(this.dutyPage.tabNode);
  483. }
  484. }else{
  485. if (this.dutyCountNode) this.dutyCountNode.destroy();
  486. }
  487. var attributeCount = this.data.woUnitAttributeList.length;
  488. if (attributeCount){
  489. if (this.attributeCountNode){
  490. this.attributeCountNode.set("text", attributeCount);
  491. }else{
  492. this.attributeCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": attributeCount}).inject(this.attributePage.tabNode);
  493. }
  494. }else{
  495. if (this.attributeCountNode) this.attributeCountNode.destroy();
  496. }
  497. },
  498. _listBaseInfor: function(){
  499. this.baseInfor = new MWF.xApplication.Org.UnitExplorer.UnitContent.BaseInfor(this);
  500. },
  501. _listDutys: function(){
  502. var _self = this;
  503. this.dutyList = new MWF.xApplication.Org.List(this.dutyContentNode, this, {
  504. "action": this.data.control.allowEdit,
  505. "saveAction": "saveUnitduty",
  506. "deleteAction": "deleteUnitduty",
  507. "data": {
  508. "description":"",
  509. "name": "",
  510. "unique": "",
  511. "unit": this.data.id,
  512. "orderNumber": "",
  513. "identityList": [],
  514. "woIdentityList": []
  515. },
  516. "attr": ["name", "description", {
  517. "get": function(){
  518. //var html = "";
  519. // this.woIdentityList.each(function(identity){
  520. // html+="<div>"+identity.name+"</div>"
  521. // }.bind(this));
  522. return "";
  523. },
  524. "events": {
  525. "init": function(){
  526. //var divs = this.td.getElements("div");
  527. var contentNode = this.td;
  528. if (this.item.list.options.action){
  529. var actionDiv = new Element("div", {"styles": _self.item.style.dutyIdentityAction}).inject(this.td);
  530. contentNode = new Element("div", {"styles": _self.item.style.dutyIdentityContent}).inject(this.td);
  531. actionDiv.addEvent("click", function(){
  532. _self.editDutyIdentity(this.data, contentNode);
  533. }.bind(this));
  534. }
  535. var _dutyData = this.data;
  536. this.data.woIdentityList.each(function(identity, i){
  537. new MWF.widget.O2Identity(identity, contentNode, {
  538. "canRemove": _self.data.control.allowEdit,
  539. "onRemove": function(O2Identity, e){
  540. _self.deleteDutyIdentity(_dutyData, e, O2Identity);
  541. }
  542. })
  543. }.bind(this));
  544. },
  545. "click": function(){
  546. //_self.explorer.openGroup(this.data, this.td);
  547. }
  548. }
  549. }],
  550. "onPostSave": function(item, id){
  551. if (!item.data.id){
  552. item.data.id = id;
  553. this.data.woUnitDutyList.push(item.data);
  554. }
  555. this.loadListCount();
  556. }.bind(this),
  557. "onPostDelete": function(delCount){
  558. if (this.dutyCountNode){
  559. var count = this.dutyCountNode.get("text").toInt()-delCount;
  560. this.dutyCountNode.set("text", count);
  561. }
  562. }.bind(this),
  563. });
  564. //this.dutyList.addItem = function(){this.addDuty();};
  565. this.dutyList.load([
  566. {"style": "width: 20%", "text": this.explorer.app.lp.dutyName},
  567. {"style": "", "text": this.explorer.app.lp.description},
  568. {"style": "width: 50%", "text": this.explorer.app.lp.dutyMembers}
  569. ]);
  570. this.data.woUnitDutyList.each(function(item){
  571. //this.attributes.push(new MWF.xApplication.Org.PersonExplorer.PersonAttribute(this.attributeTabContentNode.getElement("table").getFirst(), item, this, this.explorer.css.list));
  572. this.dutyList.push(item);
  573. }.bind(this));
  574. },
  575. editDutyIdentity: function(dutyData, contentNode){
  576. var _self = this;
  577. MWF.xDesktop.requireApp("Selector", "Identity", function(){
  578. var selector = new MWF.xApplication.Selector.Identity(this.explorer.app.content,{
  579. "values": dutyData.identityList,
  580. "onComplete": function(items){
  581. var woIdentityList = [];
  582. var identityList = [];
  583. contentNode.empty();
  584. items.each(function(item, i){
  585. woIdentityList.push(item.data);
  586. identityList.push(item.data.id);
  587. new MWF.widget.O2Identity(item.data, contentNode, {
  588. "canRemove": true,
  589. "onRemove": function(O2Identity, e){
  590. _self.deleteDutyIdentity(dutyData, e, O2Identity);
  591. }
  592. })
  593. }.bind(this));
  594. dutyData.identityList = identityList;
  595. dutyData.woIdentityList = woIdentityList;
  596. _self.saveDuty(dutyData);
  597. }.bind(this)
  598. });
  599. selector.load();
  600. }.bind(this));
  601. },
  602. deleteDutyIdentity: function(dutyData, e, O2Identity){
  603. var _self = this;
  604. var text = this.explorer.app.lp.deleteDutyIdentity.replace(/{duty}/g, dutyData.name);
  605. text = text.replace(/{identity}/g, O2Identity.data.name);
  606. this.explorer.app.confirm("warn", e, this.explorer.app.lp.deleteDutyIdentityTitle, text, "360", "170", function(){
  607. dutyData.identityList.erase(O2Identity.data.id);
  608. dutyData.woIdentityList = dutyData.woIdentityList.filter(function(a){
  609. return (O2Identity.data.id !== a.id);
  610. });
  611. _self.saveDuty(dutyData, function(){
  612. O2Identity.destroy();
  613. });
  614. this.close();
  615. }, function(){
  616. this.close();
  617. });
  618. },
  619. saveDuty: function(data, callback){
  620. this.propertyContentScrollNode.mask({
  621. "style": {
  622. "opacity": 0.7,
  623. "background-color": "#999"
  624. }
  625. });
  626. this.explorer.actions.saveUnitduty(data, function(){
  627. this.propertyContentScrollNode.unmask();
  628. if (callback) callback();
  629. }.bind(this), function(xhr, text, error){
  630. var errorText = error;
  631. if (xhr) errorText = xhr.responseText;
  632. this.explorer.app.notice("request json error: "+errorText, "error");
  633. this.content.propertyContentScrollNode.unmask();
  634. }.bind(this));
  635. },
  636. _listAttributes: function(){
  637. this.attributeList = new MWF.xApplication.Org.List(this.attributeContentNode, this, {
  638. "action": this.data.control.allowEdit,
  639. "saveAction": "saveUnitattribute",
  640. "deleteAction": "deleteUnitattribute",
  641. "data": {
  642. "description":"",
  643. "name": "",
  644. "unique": "",
  645. "unit": this.data.id,
  646. "orderNumber": "",
  647. "attributeList": []
  648. },
  649. "attr": ["name", {
  650. "get": function(){return this.attributeList.join(",")},
  651. "set": function(value){debugger;this.attributeList = value.split(/,\s*/g)}
  652. }, "description"],
  653. "onPostSave": function(item, id){
  654. if (!item.data.id){
  655. item.data.id = id;
  656. this.data.woUnitAttributeList.push(item.data);
  657. }
  658. this.loadListCount();
  659. }.bind(this),
  660. "onPostDelete": function(delCount){
  661. if (this.attributeCountNode){
  662. var count = this.attributeCountNode.get("text").toInt()-delCount;
  663. this.attributeCountNode.set("text", count);
  664. }
  665. }.bind(this),
  666. });
  667. this.attributeList.load([
  668. {"style": "width: 20%", "text": this.explorer.app.lp.attributeName},
  669. {"style": "width: 45%", "text": this.explorer.app.lp.attributeValue},
  670. {"style": "", "text": this.explorer.app.lp.description}
  671. ]);
  672. this.data.woUnitAttributeList.each(function(item){
  673. //this.attributes.push(new MWF.xApplication.Org.PersonExplorer.PersonAttribute(this.attributeTabContentNode.getElement("table").getFirst(), item, this, this.explorer.css.list));
  674. this.attributeList.push(item);
  675. }.bind(this));
  676. },
  677. _listIdentityMembers: function(){
  678. var _self = this;
  679. this.identityMemberList = new MWF.xApplication.Org.List(this.personMemberContentNode, this, {
  680. "action": this.data.control.allowEdit,
  681. "canEdit": false,
  682. "deleteAction": "deleteIdentity",
  683. "deleteItemTitle": this.explorer.app.lp.deleteIdentityMemeberTitle,
  684. "deleteItemText": this.explorer.app.lp.deleteIdentityMemeber,
  685. "data": {},
  686. "attr": [{
  687. "get": function(){
  688. var src = _self.explorer.actions.getPersonIcon(this.woPerson.id);
  689. return "<div style='width:24px; height:24px;''><img style='width:24px; height:24px; border-radius:12px; border: 0' src='"+src+"'/></div>";
  690. },
  691. "set": function(){}
  692. }, {
  693. "get": function(){return this.woPerson.name}
  694. }, {
  695. "get": function(){return this.woPerson.employee}
  696. }, {
  697. "get": function(){return this.woPerson.mobile}
  698. }, {
  699. "get": function(){return this.woPerson.mail}
  700. }, {
  701. "get": function(){
  702. return "<div style='width:24px; height:24px; background:url(/x_component_Org/$Explorer/"+
  703. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  704. },
  705. "events": {
  706. "click": function(){
  707. _self.explorer.openPerson(this.data.woPerson, this.td);
  708. }
  709. }
  710. }, {
  711. "get": function(){
  712. return "<div style='-webkit-user-select: none; -moz-user-select: none; width:24px; height:24px; cursor: move; background:url(/x_component_Org/$Explorer/"+
  713. _self.explorer.app.options.style+"/icon/move.png) center center no-repeat'></div>";
  714. },
  715. "events": {
  716. "selectstart": function(e){e.stopPropagation(); e.preventDefault();return false;},
  717. "touchstart": function(e){_self.startOrder(this.item, this.td, e)},
  718. "mousedown": function(e){_self.startOrder(this.item, this.td, e)}
  719. }
  720. }],
  721. "onPostDelete": function(delCount){
  722. if (this.identityCountNode){
  723. var count = this.identityCountNode.get("text").toInt()-delCount;
  724. this.identityCountNode.set("text", count);
  725. }
  726. }.bind(this)
  727. });
  728. this.identityMemberList.addItem = this.addPersonMember.bind(this);
  729. this.identityMemberList.load([
  730. {"style": "width: 30px", "text": ""},
  731. {"style": "width: 20%", "text": this.explorer.app.lp.personName},
  732. {"style": "", "text": this.explorer.app.lp.personEmployee},
  733. {"style": "", "text": this.explorer.app.lp.personMobile},
  734. {"style": "", "text": this.explorer.app.lp.personMail},
  735. {"style": "width: 10px", "text": ""},
  736. {"style": "width: 10px", "text": ""}
  737. ]);
  738. this.data.woSubDirectIdentityList.each(function(id){
  739. var item = this.identityMemberList.push(id);
  740. }.bind(this));
  741. },
  742. startOrder: function(item, td, e){
  743. var tr = td.getParent("tr");
  744. var table = tr.getParent("table");
  745. var div = td.getFirst("div");
  746. var size = tr.getSize();
  747. var titleTr = table.getElement("tr");
  748. var moveNode = new Element("table", {"styles": {
  749. "opacity": 0.7,
  750. "border": "1px dashed #999",
  751. "z-index": 10000,
  752. "width": size.x,
  753. "height": size.y,
  754. "background-color": "#CCC",
  755. "position": "absolute"
  756. }}).inject(this.explorer.app.content);
  757. var moveNodeTr = tr.clone().inject(moveNode);
  758. var moveTds = moveNodeTr.getElements("td");
  759. titleTr.getElements("th").each(function(cell, i){
  760. moveTds[i].setStyle("width", ""+cell.getSize().x+"px");
  761. });
  762. moveNode.position({
  763. relativeTo: tr,
  764. position: 'upperLeft',
  765. edge: 'upperLeft'
  766. });
  767. div.setStyle("display", "none");
  768. var nextData = {};
  769. var ntr = tr.getNext("tr");
  770. if (ntr) nextData = ntr.retrieve("data");
  771. if (!nextData) nextData={};
  772. var drag = new Drag.Move(moveNode, {
  773. "container": table,
  774. "droppables": table.getElements("tr").erase(tr),
  775. "preventDefault": true,
  776. "stopPropagation": true,
  777. "onStart": function(){
  778. tr.setStyles({
  779. "display": "none",
  780. "background-color": "#dff3fc"
  781. });
  782. }.bind(this),
  783. "onEnter": function(element, droppable){
  784. tr.inject(droppable, "after");
  785. droppable.setStyles({"background": "#fcf8f1"});
  786. tr.setStyles({"display": "table-row"});
  787. element.setStyles({"display": "none"});
  788. var nextTr = tr.getNext("tr");
  789. if (nextTr){
  790. nextData = nextTr.retrieve("data");
  791. }else{
  792. nextData={};
  793. }
  794. if (!nextData) nextData={};
  795. },
  796. "onLeave": function(element, droppable){
  797. droppable.setStyles({"background": "transparent "});
  798. tr.setStyles({"display": "none"});
  799. element.setStyles({"display": "block"});
  800. },
  801. "onDrop": function(dragging, droppable, e){
  802. var nextTr = tr.getNext("tr");
  803. if (nextTr){
  804. nextData = nextTr.retrieve("data");
  805. }else{
  806. nextData={};
  807. }
  808. if (!nextData) nextData={};
  809. moveNode.destroy();
  810. droppable.setStyles({"background": "transparent "});
  811. tr.setStyles({"background": "transparent "});
  812. this.explorer.actions.orderIdentity(item.data.id, nextData.id || "(0)", function(){});
  813. div.setStyle("display", "block");
  814. }.bind(this),
  815. "onCancel": function(dragging){
  816. dragging.destroy();
  817. drag = null;
  818. div.setStyle("display", "block");
  819. }
  820. });
  821. drag.start(e);
  822. // var moveNode = new Element("div", {"styles": {
  823. // "opacity": 0.7,
  824. // "border": "1px dashed #999",
  825. // "z-index": 10000,
  826. // "width": size.x,
  827. // "height": size.y,
  828. // "background-color": "#CCC",
  829. // "position": "absolute"
  830. // }}).inject(this.explorer.app.content);
  831. // moveNode.setStyles({
  832. // "opacity": 0.7,
  833. // "border": "1px dashed #999",
  834. // "z-index": 10000,
  835. // "width": size.x,
  836. // "height": size.y,
  837. // "background-color": "#CCC",
  838. // "position": "absolute"
  839. // });
  840. },
  841. addPersonMember: function(){
  842. this.checkSaveBaseInfor(function(){
  843. MWF.xDesktop.requireApp("Selector", "Person", function(){
  844. var selector = new MWF.xApplication.Selector.Person(this.explorer.app.content,{
  845. "values": [],
  846. "onComplete": function(items){
  847. debugger;
  848. var data = {
  849. "description": "",
  850. "name": "",
  851. "unique": "",
  852. "person": "",
  853. "department": "",
  854. "unit": this.data.id,
  855. "orderNumber": ""
  856. };
  857. items.each(function(item){
  858. var idData = Object.clone(data);
  859. idData.name = item.data.name;
  860. idData.person = item.data.id;
  861. this.explorer.actions.saveIdentity(idData, function(d){
  862. this.explorer.actions.getIdentity(function(id){
  863. this.data.woSubDirectIdentityList.push(id.data);
  864. this.identityMemberList.push(id.data);
  865. this.loadListCount();
  866. }.bind(this), null, d.data.id);
  867. }.bind(this));
  868. }.bind(this));
  869. }.bind(this)
  870. });
  871. selector.load();
  872. }.bind(this));
  873. }.bind(this));
  874. },
  875. checkSaveBaseInfor: function(callback){
  876. if (!this.data.id){
  877. if (this.baseInfor){
  878. if (this.baseInfor.mode==="edit") this.baseInfor.save(function(){
  879. if (callback) callback();
  880. }.bind(this));
  881. }
  882. }else{
  883. if (callback) callback();
  884. }
  885. }
  886. });
  887. MWF.xApplication.Org.UnitExplorer.UnitContent.TitleInfor = new Class({
  888. Extends: MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor,
  889. _getStyle: function(){
  890. var css = Object.clone(this.item.style.person);
  891. return Object.merge(css, this.item.style.role);
  892. },
  893. _getIcon: function(){
  894. return "/x_component_Org/$Explorer/default/icon/unit70.png";
  895. },
  896. setBackground: function(){
  897. this.titleBgNode.setStyle("background-image", "url(/x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/unit_bg_bg.png)");
  898. this.titleNode.setStyle("background-image", "url(/x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/unit_bg.png)");
  899. },
  900. loadRightInfor: function(){
  901. //var text = this.data.name+((this.data.unique) ? "("+this.data.unique+")" : "");
  902. var text = this.data.name;
  903. if (!this.nameNode) this.nameNode = new Element("div", {"styles": this.style.titleInforNameNode}).inject(this.titleInforRightNode);
  904. if (!this.signatureNode) this.signatureNode = new Element("div", {"styles": this.style.titleInforSignatureNode}).inject(this.titleInforRightNode);
  905. this.nameNode.set("text", text);
  906. this.signatureNode.set("text", (this.data.levelName || "" ));
  907. }
  908. });
  909. MWF.xApplication.Org.UnitExplorer.UnitContent.BottomInfor = new Class({
  910. Extends: MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor,
  911. addInforList: function(){
  912. var text = this.explorer.app.lp.unitReadDn.replace(/{dn}/g, (this.data.distinguishedName || " "));
  913. this.addInfor(text);
  914. text = this.explorer.app.lp.unitReadLevel.replace(/{level}/g, (this.data.level || " "));
  915. text = text.replace(/{levelName}/g, (this.data.levelName || " "));
  916. this.addInfor(text);
  917. text = this.explorer.app.lp.unitReadCreate.replace(/{date}/g, (this.data.createTime || " "));
  918. text = text.replace(/{date2}/g, (this.data.updateTime || " "));
  919. this.addInfor(text);
  920. }
  921. });
  922. MWF.xApplication.Org.UnitExplorer.UnitContent.BaseInfor = new Class({
  923. initialize: function(content){
  924. this.content = content;
  925. this.item = content.item;
  926. this.data = this.item.data;
  927. this.explorer = this.item.explorer;
  928. this.contentNode = this.content.baseContentNode;
  929. this.style = this.item.style.person;
  930. this.attributes = [];
  931. this.mode = "read";
  932. this.load();
  933. },
  934. load: function(){
  935. this.node = new Element("div", {"styles": this.style.baseContentNode}).inject(this.contentNode);
  936. this.editContentNode = new Element("div", {"styles": this.style.baseEditNode}).inject(this.node);
  937. this.editContentNode.set("html", this.getContentHtml());
  938. this.editContentNode.getElements("td.inforTitle").setStyles(this.style.baseInforTitleNode);
  939. this.editContentNode.getElements("td.inforContent").setStyles(this.style.baseInforContentNode);
  940. this.editContentNode.getElements("td.inforAction").setStyles(this.style.baseInforActionNode);
  941. var tdContents = this.editContentNode.getElements("td.inforContent");
  942. if (this.data.controllerList){
  943. this.data.controllerList.each(function(id){
  944. new MWF.widget.O2Person({"name": id}, tdContents[5], {"style": "xform"});
  945. }.bind(this));
  946. }
  947. this.loadAction();
  948. },
  949. getContentHtml: function(){
  950. var html = "<table width='100%' cellpadding='3px' cellspacing='5px'>";
  951. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitName+":</td><td class='inforContent'>"+(this.data.name || "")+"</td>" +
  952. "<td class='inforTitle'>"+this.explorer.app.lp.unitUnique+":</td><td class='inforContent'>"+(this.data.unique || "")+"</td></tr>";
  953. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitTypeList+":</td><td class='inforContent'>"+(this.data.typeList.join(", ") || "")+"</td>" +
  954. "<td class='inforTitle'>"+this.explorer.app.lp.unitShortName+":</td><td class='inforContent'>"+(this.data.shortName || "")+"</td></tr>";
  955. // html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitLevel+":</td><td class='inforContent'>"+this.data.level+"</td>" +
  956. // "<td class='inforTitle'>"+this.explorer.app.lp.unitLevelName+":</td><td class='inforContent'>"+(this.data.levelName || "")+"</td></tr>";
  957. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitDescription+":</td><td colspan='3' class='inforContent'>"+(this.data.description || "")+"</td>";
  958. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitControllerList+":</td><td colspan='3' class='inforContent'></td>";
  959. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.orderNumber+":</td><td colspan='3' class='inforContent'>"+(this.data.orderNumber || "")+"</td>";
  960. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  961. //this.baseInforRightNode.set("html", html);
  962. return html;
  963. },
  964. loadAction: function(){
  965. //this.explorer.app.lp.edit
  966. var actionAreas = this.editContentNode.getElements("td");
  967. var actionArea = actionAreas[actionAreas.length-1];
  968. if (this.data.control.allowEdit){
  969. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  970. this.editNode = new Element("div", {"styles": this.style.actionEditNode, "text": this.explorer.app.lp.editUnit}).inject(this.baseInforEditActionAreaNode);
  971. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.saveUnit}).inject(this.baseInforEditActionAreaNode);
  972. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  973. this.editNode.setStyle("display", "block");
  974. this.editNode.addEvent("click", this.edit.bind(this));
  975. this.saveNode.addEvent("click", this.save.bind(this));
  976. this.cancelNode.addEvent("click", this.cancel.bind(this));
  977. }else{
  978. }
  979. },
  980. edit: function(){
  981. var tdContents = this.editContentNode.getElements("td.inforContent");
  982. tdContents[0].setStyles(this.style.baseInforContentNode_edit).empty();
  983. this.nameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[0]);
  984. this.nameInputNode.set("value", (this.data.name));
  985. tdContents[1].setStyles(this.style.baseInforContentNode_edit).empty();
  986. this.uniqueInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[1]);
  987. this.uniqueInputNode.set("value", (this.data.unique));
  988. tdContents[2].setStyles(this.style.baseInforContentNode_edit).empty();
  989. this.typeListInputNode = new Element("input", {"styles": this.style.inputNode_type}).inject(tdContents[2]);
  990. this.typeListInputNode.set("value", ((this.data.typeList.length) ? this.data.typeList.join(", "): ""));
  991. this.loadUnitTypeSelect();
  992. tdContents[3].setStyles(this.style.baseInforContentNode_edit).empty();
  993. this.shortNameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[3]);
  994. this.shortNameInputNode.set("value", (this.data.shortName || ""));
  995. tdContents[4].setStyles(this.style.baseInforContentNode_edit).empty();
  996. this.descriptionInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[4]);
  997. this.descriptionInputNode.set("value", (this.data.description || ""));
  998. tdContents[5].setStyles(this.style.baseInforContentNode_edit).empty();
  999. this.controllerListInputNode = new Element("div", {"styles": this.style.inputNode_person}).inject(tdContents[5]);
  1000. tdContents[6].setStyles(this.style.baseInforContentNode_edit).empty();
  1001. this.orderNumberInputNode = new Element("input", {"styles": this.style.inputNode, "type":"number"}).inject(tdContents[6]);
  1002. this.orderNumberInputNode.set("value", (this.data.orderNumber || ""));
  1003. //this.controllerListInputNode.set("value", ((this.data.controllerList) ? this.data.controllerList.join(", ") : ""));
  1004. if (this.data.controllerList){
  1005. this.data.controllerList.each(function(id){
  1006. new MWF.widget.O2Person({"name": id}, this.controllerListInputNode, {"style": "xform"});
  1007. }.bind(this));
  1008. }
  1009. this.controllerListInputNode.addEvent("click", function(){
  1010. MWF.xDesktop.requireApp("Selector", "package", function(){
  1011. var options = {
  1012. "type": "person",
  1013. "values": this.data.controllerList || [],
  1014. "count": 0,
  1015. "onComplete": function(items){
  1016. var controllerList = [];
  1017. this.controllerListInputNode.empty();
  1018. items.each(function(item){
  1019. controllerList.push(item.data.id);
  1020. new MWF.widget.O2Person(item.data, this.controllerListInputNode, {"style": "xform"});
  1021. }.bind(this));
  1022. this.data.controllerList = controllerList;
  1023. }.bind(this)
  1024. };
  1025. var selector = new MWF.O2Selector(this.explorer.app.content, options);
  1026. }.bind(this));
  1027. }.bind(this));
  1028. var _self = this;
  1029. this.editContentNode.getElements("input").addEvents({
  1030. "focus": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_focus);}},
  1031. "blur": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_blur);}}
  1032. });
  1033. this.mode = "edit";
  1034. this.editNode.setStyle("display", "none");
  1035. this.saveNode.setStyle("display", "block");
  1036. this.cancelNode.setStyle("display", "block");
  1037. },
  1038. loadUnitTypeSelect: function(){
  1039. if (this.typeListInputNode){
  1040. this.typeListInputNode.addEvents({
  1041. "blur": function(){this.hideTypeSelectNode();}.bind(this),
  1042. "click": function(){this.showTypeSelectNode();}.bind(this),
  1043. "focus": function(){this.showTypeSelectNode();}.bind(this)
  1044. });
  1045. }
  1046. },
  1047. hideTypeSelectNode: function(){
  1048. if (this.typeSelectNode) this.typeSelectNode.destroy();
  1049. this.typeSelectNode = null;
  1050. },
  1051. showTypeSelectNode: function(){
  1052. if (!this.typeSelectNode){
  1053. this.typeSelectNode = new Element("div", {"styles": this.style.typeSelectNode}).inject(this.typeListInputNode, "after");
  1054. var size = this.typeListInputNode.getSize();
  1055. var width = size.x-3;
  1056. this.typeSelectNode.setStyle("width", ""+width+"px");
  1057. this.typeSelectNode.position({
  1058. "relativeTo": this.typeListInputNode,
  1059. "position": 'bottomLeft',
  1060. "edge": 'upperLeft',
  1061. "offset": {"x": 1, "y": -3}
  1062. });
  1063. this.explorer.actions.listUnitType(function(json){
  1064. var count = json.data.valueList.length;
  1065. var height = (count*30);
  1066. this.typeSelectNode.setStyle("height", ""+height+"px");
  1067. json.data.valueList.each(function(t, i){
  1068. this.createTypeSelectItem(t, i);
  1069. }.bind(this));
  1070. }.bind(this));
  1071. }
  1072. },
  1073. createTypeSelectItem: function(text, i){
  1074. var typeSelectItemNode = new Element("div", {"styles": this.style.typeSelectItemNode}).inject(this.typeSelectNode);
  1075. if ((i % 2)===0) typeSelectItemNode.setStyle("background", "#f4f9ff");
  1076. var iconNode = new Element("div", {"styles": this.style.typeSelectItemIconNode}).inject(typeSelectItemNode);
  1077. var textNode = new Element("div", {"styles": this.style.typeSelectItemTextNode}).inject(typeSelectItemNode);
  1078. textNode.set("text", text);
  1079. var _self = this;
  1080. typeSelectItemNode.addEvents({
  1081. "mouseover": function(){this.setStyle("background-color", "#fef5e7");},
  1082. "mouseout": function(){this.setStyle("background", "#ffffff"); if ((i % 2)===0) this.setStyle("background", "#f4f9ff");},
  1083. "mousedown": function(){
  1084. _self.typeListInputNode.set("value", this.get("text"));
  1085. }
  1086. });
  1087. },
  1088. save: function(){
  1089. var tdContents = this.editContentNode.getElements("td.inforContent");
  1090. if (!this.nameInputNode.get("value")){
  1091. this.explorer.app.notice(this.explorer.app.lp.inputUnitInfor, "error", this.explorer.propertyContentNode);
  1092. return false;
  1093. }
  1094. //this.data.genderType = gender;
  1095. //if (!this.uniqueInputNode.get("value")) this.data.unique = this.employeeInputNode.get("value");
  1096. this.content.propertyContentScrollNode.mask({
  1097. "style": {
  1098. "opacity": 0.7,
  1099. "background-color": "#999"
  1100. }
  1101. });
  1102. this.saveUnit(function(){
  1103. this.cancel();
  1104. this.content.propertyContentScrollNode.unmask();
  1105. }.bind(this), function(xhr, text, error){
  1106. var errorText = error;
  1107. if (xhr) errorText = xhr.responseText;
  1108. this.explorer.app.notice("request json error: "+errorText, "error");
  1109. this.content.propertyContentScrollNode.unmask();
  1110. }.bind(this));
  1111. },
  1112. saveUnit: function(callback, cancel){
  1113. var data = Object.clone(this.data);
  1114. data.name = this.nameInputNode.get("value");
  1115. data.unique = this.uniqueInputNode.get("value");
  1116. data.typeList = (this.typeListInputNode.get("value")) ? this.typeListInputNode.get("value").split(/,\s*/g) : [];
  1117. data.shortName = this.shortNameInputNode.get("value");
  1118. data.description = this.descriptionInputNode.get("value");
  1119. data.orderNumber = this.orderNumberInputNode.get("value");
  1120. //data.controllerList = (this.controllerListInputNode.get("value")) ? this.controllerListInputNode.get("value").split(/,\s*/g) : [];
  1121. this.explorer.actions.saveUnit(data, function(json){
  1122. Object.merge(this.data, data);
  1123. if (this.data.id){
  1124. this.data.id = json.data.id;
  1125. this.item.refresh();
  1126. if (callback) callback();
  1127. }else{
  1128. this.explorer.actions.getUnit(function(json){
  1129. this.data = Object.merge(this.data, json.data);
  1130. this.item.data = this.data;
  1131. this.item.refresh();
  1132. if (this.item.parent) this.item.parent.subUnits.push(this.item);
  1133. if (callback) callback();
  1134. }.bind(this), null, json.data.id);
  1135. }
  1136. }.bind(this), function(xhr, text, error){
  1137. if (cancel) cancel(xhr, text, error);
  1138. }.bind(this));
  1139. },
  1140. cancel: function(){
  1141. if (this.data.id){
  1142. var tdContents = this.editContentNode.getElements("td.inforContent");
  1143. tdContents[0].setStyles(this.style.baseInforContentNode).set("html", this.data.name || "");
  1144. tdContents[1].setStyles(this.style.baseInforContentNode).set("html", this.data.unique || "");
  1145. tdContents[2].setStyles(this.style.baseInforContentNode).set("html", ((this.data.typeList.length) ? this.data.typeList.join(", "): ""));
  1146. tdContents[3].setStyles(this.style.baseInforContentNode).set("html", this.data.shortName || "");
  1147. tdContents[4].setStyles(this.style.baseInforContentNode).set("html", this.data.description || "");
  1148. //tdContents[5].setStyles(this.style.baseInforContentNode).set("html", ((this.data.controllerList.length) ? this.data.controllerList.join(", "): ""));
  1149. tdContents[5].setStyles(this.style.baseInforContentNode).empty();
  1150. tdContents[6].setStyles(this.style.baseInforContentNode).set("html", this.data.orderNumber || "");
  1151. if (this.data.controllerList){
  1152. this.data.controllerList.each(function(id){
  1153. new MWF.widget.O2Person({"name": id}, tdContents[5], {"style": "xform"});
  1154. }.bind(this));
  1155. }
  1156. this.mode = "read";
  1157. this.editNode.setStyle("display", "block");
  1158. this.saveNode.setStyle("display", "none");
  1159. this.cancelNode.setStyle("display", "none");
  1160. }else{
  1161. this.item.destroy();
  1162. }
  1163. },
  1164. destroy: function(){
  1165. this.node.empty();
  1166. this.node.destroy();
  1167. MWF.release(this);
  1168. }
  1169. });