UnitExplorer.js 61 KB

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