UnitExplorer.js 60 KB

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