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