OrgExplorer.js 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920
  1. MWF.require("MWF.widget.Tree", null, false);
  2. MWF.xApplication.Organization.OrgExplorer = new Class({
  3. Extends: MWF.widget.Common,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default"
  7. },
  8. initialize: function(node, actions, options){
  9. this.setOptions(options);
  10. this.path = "/x_component_Organization/$OrgExplorer/";
  11. this.cssPath = "/x_component_Organization/$OrgExplorer/"+this.options.style+"/css.wcss";
  12. this._loadCss();
  13. this.deleteElements = [];
  14. this.actions = actions;
  15. this.node = $(node);
  16. },
  17. load: function(){
  18. MWF.AC.getCompanyList();
  19. this.loadLayout();
  20. this.loadChart();
  21. },
  22. loadLayout: function(){
  23. this.chartAreaNode = new Element("div", {"styles": this.css.chartAreaNode}).inject(this.node);
  24. this.propertyAreaNode = new Element("div", {"styles": this.css.propertyAreaNode}).inject(this.node);
  25. this.resizeBarNode = new Element("div", {"styles": this.css.resizeBarNode}).inject(this.propertyAreaNode);
  26. this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.propertyAreaNode);
  27. this.propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  28. this.propertyContentNode = new Element("div", {"styles": this.css.propertyContentNode}).inject(this.propertyNode);
  29. this.loadToolbar();
  30. this.chartScrollNode = new Element("div", {"styles": this.css.chartScrollNode}).inject(this.chartAreaNode);
  31. this.chartNode = new Element("div", {"styles": this.css.chartNode}).inject(this.chartScrollNode);
  32. this.resizePropertyContentNode();
  33. this.app.addEvent("resize", function(){this.resizePropertyContentNode();}.bind(this));
  34. MWF.require("MWF.widget.ScrollBar", function(){
  35. new MWF.widget.ScrollBar(this.chartScrollNode, {
  36. "style":"xApp_Organization_Explorer", "where": "before", "distance": 20, "friction": 4, "axis": {"x": false, "y": true},
  37. "onScroll": function(y){this.checkDeleteMasks();}.bind(this)
  38. });
  39. new MWF.widget.ScrollBar(this.propertyContentNode, {
  40. "style":"xApp_Organization_Explorer", "where": "before", "distance": 20, "friction": 4, "axis": {"x": false, "y": true}
  41. });
  42. }.bind(this));
  43. this.propertyResize = new Drag(this.resizeBarNode,{
  44. "snap": 1,
  45. "onStart": function(el, e){
  46. var x = e.event.clientX;
  47. var y = e.event.clientY;
  48. el.store("position", {"x": x, "y": y});
  49. var size = this.chartAreaNode.getSize();
  50. el.store("initialWidth", size.x);
  51. }.bind(this),
  52. "onDrag": function(el, e){
  53. var x = e.event.clientX;
  54. // var y = e.event.y;
  55. var bodySize = this.node.getSize();
  56. var position = el.retrieve("position");
  57. var initialWidth = el.retrieve("initialWidth").toFloat();
  58. var dx = position.x.toFloat()-x.toFloat();
  59. var width = initialWidth-dx;
  60. if (width> bodySize.x/1.5) width = bodySize.x/1.5;
  61. if (width<400) width = 400;
  62. this.chartAreaNode.setStyle("width", width+1);
  63. this.propertyAreaNode.setStyle("margin-left", width);
  64. }.bind(this)
  65. });
  66. },
  67. resizePropertyContentNode: function(){
  68. var size = this.node.getSize();
  69. var tSize = this.propertyTitleNode.getSize();
  70. var mtt = this.propertyTitleNode.getStyle("margin-top").toFloat();
  71. var mbt = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  72. var mtc = this.propertyContentNode.getStyle("margin-top").toFloat();
  73. var mbc = this.propertyContentNode.getStyle("margin-bottom").toFloat();
  74. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  75. this.propertyContentNode.setStyle("height", height);
  76. tSize = this.toolbarNode.getSize();
  77. mtt = this.toolbarNode.getStyle("margin-top").toFloat();
  78. mbt = this.toolbarNode.getStyle("margin-bottom").toFloat();
  79. mtc = this.toolbarNode.getStyle("margin-top").toFloat();
  80. mbc = this.toolbarNode.getStyle("margin-bottom").toFloat();
  81. height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  82. this.chartScrollNode.setStyle("height", height);
  83. },
  84. loadToolbar: function(){
  85. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode}).inject(this.chartAreaNode);
  86. if (MWF.AC.isCompanyCreator()){
  87. this.addTopCompanyNode = new Element("div", {"styles": this.css.addTopCompanyNode}).inject(this.toolbarNode);
  88. this.addTopCompanyNode.addEvent("click", function(){
  89. this.addTopCompany();
  90. }.bind(this));
  91. }
  92. //this.createSearchNode();
  93. },
  94. createSearchNode: function(){
  95. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.toolbarNode);
  96. this.searchButtonNode = new Element("div", {
  97. "styles": this.css.searchButtonNode,
  98. "title": this.app.lp.search
  99. }).inject(this.searchNode);
  100. this.searchInputAreaNode = new Element("div", {
  101. "styles": this.css.searchInputAreaNode
  102. }).inject(this.searchNode);
  103. this.searchInputBoxNode = new Element("div", {
  104. "styles": this.css.searchInputBoxNode
  105. }).inject(this.searchInputAreaNode);
  106. this.searchInputNode = new Element("input", {
  107. "type": "text",
  108. "value": this.app.lp.searchText,
  109. "styles": this.css.searchInputNode,
  110. "x-webkit-speech": "1"
  111. }).inject(this.searchInputBoxNode);
  112. var _self = this;
  113. this.searchInputNode.addEvents({
  114. "focus": function(){
  115. if (this.value==_self.app.lp.searchText) this.set("value", "");
  116. },
  117. "blur": function(){if (!this.value) this.set("value", _self.app.lp.searchText);},
  118. "keydown": function(e){
  119. if (e.code==13){
  120. this.searchOrg();
  121. e.preventDefault();
  122. }
  123. }.bind(this),
  124. "selectstart": function(e){
  125. e.preventDefault();
  126. }
  127. });
  128. this.searchButtonNode.addEvent("click", function(){this.searchOrg();}.bind(this));
  129. },
  130. addTopCompany: function(){
  131. var isNewElement = true;
  132. if (this.currentItem) isNewElement = this.currentItem.unSelected();
  133. if (isNewElement){
  134. var newElementData = this._getAddCompanyData();
  135. var item = this._newElement(newElementData, this);
  136. item.load();
  137. item.selected();
  138. item.editBaseInfor();
  139. (new Fx.Scroll(this.chartScrollNode)).toElementCenter(item.node);
  140. }else{
  141. this.app.notice(this.app.lp.organizationSave, "error", this.propertyContentNode);
  142. }
  143. },
  144. _newElement: function(data, explorer){
  145. return new MWF.xApplication.Organization.OrgExplorer.Company(data, explorer);
  146. },
  147. _getAddCompanyData: function(){
  148. return {
  149. "name": "",
  150. "superior": ""
  151. };
  152. },
  153. _getAddDepartmentData: function(){
  154. return {
  155. "name": "",
  156. "superior": "",
  157. "company": ""
  158. };
  159. },
  160. searchOrg: function(){
  161. alert("--- search ---");
  162. },
  163. loadChart: function(){
  164. this.actions.listTopCompany(function(json){
  165. this.loadChartContent(json.data, "Company", null);
  166. }.bind(this));
  167. },
  168. loadChartContent: function(data, type, pitem){
  169. data.each(function(itemData){
  170. var item = new MWF.xApplication.Organization.OrgExplorer[type](itemData, this);
  171. if (pitem) item.parentItem = pitem;
  172. item.load();
  173. if (type=="Company"){
  174. this.loadChildCompanyNodes(item);
  175. this.loadChildDepartmentNodes(item);
  176. }else{
  177. this.loadChildSubDepartmentNodes(item);
  178. }
  179. }.bind(this));
  180. },
  181. loadChildCompanyNodes: function(item, callback){
  182. this.actions.listSubCompany(function(json){
  183. this.loadChartContent(json.data, "Company", item);
  184. }.bind(this), null, item.data.id);
  185. },
  186. loadChildDepartmentNodes: function(item){
  187. this.actions.listDepartment(function(json){
  188. this.loadChartContent(json.data, "Department", item);
  189. }.bind(this), null, item.data.id);
  190. },
  191. loadChildSubDepartmentNodes: function(item){
  192. this.actions.listSubDepartment(function(json){
  193. this.loadChartContent(json.data, "Department", item);
  194. }.bind(this), null, item.data.id);
  195. },
  196. checkDeleteMasks: function(y) {
  197. this.deleteElements.each(function(item){
  198. var maskNode = this.chartScrollNode.getElementById("mask"+item.data.id);
  199. if (maskNode){
  200. maskNode.position({
  201. relativeTo: item.childNode,
  202. position: 'upperLeft',
  203. edge: 'upperLeft'
  204. });
  205. }
  206. }.bind(this));
  207. },
  208. checkDeleteElements: function(){
  209. if (this.deleteElements.length){
  210. if (!this.deleteElementsNode){
  211. this.deleteElementsNode = new Element("div", {
  212. "styles": this.css.deleteGroupsNode,
  213. "text": this.app.lp.deleteOrganization
  214. }).inject(this.node);
  215. this.deleteElementsNode.position({
  216. relativeTo: this.chartScrollNode,
  217. position: "centerTop",
  218. edge: "centerTop"
  219. });
  220. this.deleteElementsNode.addEvent("click", function(e){
  221. this.deleteSelectedElements(e);
  222. }.bind(this));
  223. }
  224. }else{
  225. if (this.deleteElementsNode){
  226. this.deleteElementsNode.destroy();
  227. this.deleteElementsNode = null;
  228. delete this.deleteElementsNode;
  229. }
  230. }
  231. },
  232. checkDeleteElementsConfirm: function(){
  233. var confirmText = this.app.lp.deleteOrganizationConfirm;
  234. var size = {"x": 300, "y": 120};
  235. for (var i=0; i<this.deleteElements.length; i++){
  236. var item = this.deleteElements[i];
  237. if (item.childNode.getFirst()){
  238. confirmText = this.app.lp.deleteOrganizationSubConfirm;
  239. size = {"x": 450, "y": 230};
  240. break;
  241. }
  242. if (item.getDutyCount()>0){
  243. confirmText = this.app.lp.deleteOrganizationAllConfirm;
  244. size = {"x": 450, "y": 180};
  245. break;
  246. }
  247. if (item.getAttributeCount()>0){
  248. confirmText = this.app.lp.deleteOrganizationAllConfirm;
  249. size = {"x": 450, "y": 180};
  250. break;
  251. }
  252. if (item.getMemberCount()>0){
  253. confirmText = this.app.lp.deleteOrganizationAllConfirm;
  254. size = {"x": 450, "y": 180};
  255. break;
  256. }
  257. }
  258. return {"text": confirmText, "size": size};
  259. },
  260. deleteSelectedElements: function(e){
  261. var _self = this;
  262. confirm = this.checkDeleteElementsConfirm();
  263. this.app.confirm("infor", e, this.app.lp.deleteOrganizationTitle, {"html": confirm.text}, confirm.size.x, confirm.size.y, function(){
  264. var deleted = [];
  265. var doCount = 0;
  266. var readyCount = _self.deleteElements.length;
  267. var errorText = "";
  268. var complete = function(){
  269. if (doCount == readyCount){
  270. if (errorText){
  271. _self.app.notice(errorText, "error", _self.propertyContentNode, {x: "left", y:"top"});
  272. }
  273. }
  274. }
  275. _self.deleteElements.each(function(item){
  276. item["delete"](function(){
  277. deleted.push(item);
  278. doCount++;
  279. if (_self.deleteElements.length==doCount){
  280. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  281. return !deleted.contains(item);
  282. });
  283. _self.checkDeleteElements();
  284. }
  285. complete();
  286. }, function(error){
  287. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  288. doCount++;
  289. if (_self.deleteElements.length==doCount){
  290. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  291. return !deleted.contains(item);
  292. });
  293. _self.checkDeleteElements();
  294. }
  295. complete();
  296. });
  297. });
  298. this.close();
  299. }, function(){
  300. this.close();
  301. });
  302. },
  303. });
  304. MWF.xApplication.Organization.OrgExplorer.Item = new Class({
  305. initialize: function(data, explorer){
  306. this.data = data;
  307. this.explorer = explorer;
  308. this.chartNode = this.explorer.chartNode;
  309. this.prevItem = null;
  310. this.nextItem = null;
  311. this.parentItem = null;
  312. this.children = [];
  313. this.selectedDutys = [];
  314. this.selectedAttributes = [];
  315. this.isEdit = false;
  316. this.isEditor = false;
  317. this.deleteSelected = false;
  318. this.initStyle();
  319. }, initStyle: function(){
  320. this.style = this.explorer.css.companyItem;
  321. },
  322. load: function(){
  323. this.node = new Element("div", {"styles": this.style.node}).inject(this.chartNode);
  324. this.contentNode = new Element("div", {"styles": this.style.contentNode}).inject(this.node);
  325. this.childNode = new Element("div", {"styles": this.style.childNode}).inject(this.node);
  326. this.childTween = new Fx.Tween(this.childNode, {
  327. "duration": 200,
  328. "transition": Fx.Transitions.Quint.easeOut,
  329. "onComplete": function(){
  330. var y = this.childNode.getSize().y;
  331. if (y>0)this.childNode.setStyle("height", "auto");
  332. }.bind(this)
  333. });
  334. this.flagNode = new Element("div", {"styles": this.style.flagNode}).inject(this.contentNode);
  335. this.flagIconNode = new Element("div", {"styles": this.style.flagIconNode}).inject(this.flagNode);
  336. this.iconNode = new Element("div", {"styles": this.style.iconNode}).inject(this.contentNode);
  337. this.actionNode = new Element("div", {"styles": this.style.actionNode}).inject(this.contentNode);
  338. this.textNode = new Element("div", {"styles": this.style.textNode}).inject(this.contentNode);
  339. this.textNode.set({
  340. "text": this.data.name
  341. });
  342. // var indent = this.getIndent();
  343. // this.indentNode.setStyle("width", ""+indent+"px");
  344. this.setNewItem();
  345. if (this.parentItem){
  346. this.parentItem.children.push(this);
  347. this.parentItem.flagIconNode.setStyles(this.style.flagIconNode_e);
  348. this.node.inject(this.parentItem.childNode);
  349. }else{
  350. this.node.inject(this.chartNode);
  351. }
  352. this.addActions();
  353. this.setEvent();
  354. },
  355. setNewItem: function(){
  356. if (!this.created){
  357. if (!this.data.id){
  358. this.created = false;
  359. this.contentNode.setStyles(this.style.contentNodeNew);
  360. }else {
  361. this.created = true;
  362. this.contentNode.setStyles(this.style.contentNode);
  363. }
  364. }
  365. },
  366. getIndent: function(){
  367. return (this.data.level.toFloat()-1)*20;
  368. },
  369. addActions: function(){
  370. MWF.AC.isCompanyEditor({
  371. "id": this.data.id,
  372. "yes": function(){
  373. this.isEditor = true;
  374. this.deleteNode = new Element("div", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  375. this.addDepartmentNode = new Element("div", {"styles": this.style.actionAddDepartmentNode, "title": this.explorer.app.lp.createSubDepartment}).inject(this.actionNode);
  376. this.addCompanyNode = new Element("div", {"styles": this.style.actionAddCompanyNode, "title": this.explorer.app.lp.createSubCompany}).inject(this.actionNode);
  377. this.actionConfigNode = new Element("div", {"styles": this.style.actionConfigNode, "title": this.explorer.app.lp.configCompany}).inject(this.actionNode);
  378. this.deleteNode.addEvent("click", function(e){
  379. this.deleteButton();
  380. e.stopPropagation();
  381. }.bind(this));
  382. this.addDepartmentNode.addEvent("click", function(e){
  383. if (!this.checkDelete()) if (this.data.id) this.addDepartment();
  384. e.stopPropagation();
  385. }.bind(this));
  386. this.addCompanyNode.addEvent("click", function(e){
  387. if (!this.checkDelete()) if (this.data.id) this.addCompany();
  388. e.stopPropagation();
  389. }.bind(this));
  390. this.actionConfigNode.addEvent("click", function(e){
  391. if (!this.checkDelete()) if (this.data.id) this.configCompany(e);
  392. e.stopPropagation();
  393. }.bind(this));
  394. }.bind(this)
  395. });
  396. },
  397. deleteButton: function(){
  398. if (!this.deleteSelected){
  399. this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  400. this.contentNode.setStyles(this.style.contentNode_selected);
  401. this.node.setStyles(this.style.node_forDelete);
  402. //this.node.setStyles(this.style.node_forDelete);
  403. if (this.addDepartmentNode) this.addDepartmentNode.setStyle("display", "none");
  404. if (this.addCompanyNode) this.addCompanyNode.setStyle("display", "none");
  405. if (this.actionConfigNode) this.actionConfigNode.setStyle("display", "none");
  406. //this.childNode.mask({
  407. // "id": "mask"+this.data.id,
  408. // "inject": this.node,
  409. // "style": this.style.nodeMask
  410. //});
  411. var removeItems = [];
  412. this.explorer.deleteElements.each(function(item){
  413. if (this.childNode.contains(item.node)){
  414. item.deleteNode.setStyles(item.style.actionDeleteNode);
  415. item.contentNode.setStyles(item.style.contentNode);
  416. item.node.setStyles(this.style.node);
  417. if (item.addDepartmentNode) item.addDepartmentNode.setStyle("display", "block");
  418. if (item.addCompanyNode) item.addCompanyNode.setStyle("display", "block");
  419. if (item.actionConfigNode) item.actionConfigNode.setStyle("display", "block");
  420. item.actionNode.setStyle("opacity", "0");
  421. // item.childNode.unmask();
  422. item.deleteSelected = false;
  423. removeItems.push(item);
  424. }
  425. }.bind(this));
  426. removeItems.each(function(item){
  427. this.explorer.deleteElements.erase(item);
  428. }.bind(this));
  429. this.explorer.deleteElements.push(this);
  430. this.deleteSelected = true;
  431. this.explorer.checkDeleteElements();
  432. }else{
  433. this.deleteNode.setStyles(this.style.actionDeleteNode);
  434. this.contentNode.setStyles(this.style.contentNode);
  435. this.node.setStyles(this.style.node);
  436. if (this.addDepartmentNode) this.addDepartmentNode.setStyle("display", "block");
  437. if (this.addCompanyNode) this.addCompanyNode.setStyle("display", "block");
  438. if (this.actionConfigNode) this.actionConfigNode.setStyle("display", "block");
  439. // this.actionNode.setStyle("opacity", "0");
  440. // this.childNode.unmask();
  441. this.explorer.deleteElements.erase(this);
  442. this.deleteSelected = false;
  443. this.explorer.checkDeleteElements();
  444. }
  445. },
  446. addCompany: function(){
  447. var isNewElement = true;
  448. if (this.explorer.currentItem) isNewElement = this.explorer.currentItem.unSelected();
  449. if (isNewElement){
  450. var newElementData = this.explorer._getAddCompanyData();
  451. newElementData.superior = this.data.id;
  452. var item = new MWF.xApplication.Organization.OrgExplorer.Company(newElementData, this.explorer);
  453. item.parentItem = this;
  454. item.load();
  455. item.selected();
  456. item.editBaseInfor();
  457. (new Fx.Scroll(this.explorer.chartScrollNode)).toElementCenter(item.node);
  458. }else{
  459. this.app.notice(this.explorer.app.lp.organizationSave, "error", this.propertyContentNode);
  460. }
  461. },
  462. addDepartment: function(){
  463. var isNewElement = true;
  464. if (this.explorer.currentItem) isNewElement = this.explorer.currentItem.unSelected();
  465. if (isNewElement){
  466. var newElementData = this.explorer._getAddDepartmentData();
  467. newElementData.company = this.data.id;
  468. var item = new MWF.xApplication.Organization.OrgExplorer.Department(newElementData, this.explorer);
  469. item.parentItem = this;
  470. item.load();
  471. item.selected();
  472. item.editBaseInfor();
  473. (new Fx.Scroll(this.explorer.chartScrollNode)).toElementCenter(item.node);
  474. }else{
  475. this.app.notice(this.explorer.app.lp.organizationSave, "error", this.propertyContentNode);
  476. }
  477. },
  478. configCompany: function(e) {
  479. var controllerList = this.data.controllerList || [];
  480. var options = {
  481. "title": this.explorer.app.lp.configCompany,
  482. "type": "person",
  483. "values": controllerList,
  484. "onComplete": function(items){
  485. var ids = [];
  486. items.each(function(item){
  487. ids.push(item.data.id);
  488. });
  489. if (!ids.length){
  490. var _self = this;
  491. this.explorer.app.confirm("warn", e, this.explorer.app.lp.configCompanyNullTitle, {"html": this.explorer.app.lp.configCompanyNull}, 400, 160, function(){
  492. _self.data.controllerList = ids;
  493. _self.explorer.actions.saveCompany(_self.data, function(json){
  494. this.explorer.app.notice(this.explorer.app.lp.configCompanyOk, "success");
  495. }.bind(_self));
  496. this.close();
  497. }, function(){
  498. this.close();
  499. });
  500. }else{
  501. this.data.controllerList = ids;
  502. this.explorer.actions.saveCompany(this.data, function(json){
  503. this.explorer.app.notice(this.explorer.app.lp.configCompanyOk, "success");
  504. }.bind(this));
  505. }
  506. }.bind(this)
  507. }
  508. var selector = new MWF.OrgSelector(this.explorer.app.content, options)
  509. },
  510. checkDelete: function(){
  511. //if (this.deleteSelected) reutrn true;
  512. var item = this;
  513. while (item){
  514. if (item.deleteSelected) return true;
  515. var item = item.parentItem
  516. }
  517. return false;
  518. },
  519. setEvent: function(){
  520. // this.node.addEvents({
  521. // "mouseover": function(e){
  522. // this.node.setStyles(this.style.nodeOver);
  523. // e.stopPropagation();
  524. // }.bind(this),
  525. // "mouseout": function(e){
  526. // this.node.setStyles(this.style.node);
  527. // }.bind(this)
  528. // });
  529. this.contentNode.addEvents({
  530. "mouseover": function(e){
  531. if (this.explorer.currentItem!=this){
  532. this.flagNode.setStyles(this.style.flagNodeOver);
  533. }
  534. if (!this.checkDelete()) if (this.data.id) this.actionNode.fade("in");
  535. }.bind(this),
  536. "mouseout": function(e){
  537. if (this.explorer.currentItem!=this){
  538. this.flagNode.setStyles(this.style.flagNode);
  539. }
  540. if (!this.checkDelete()) if (this.data.id) this.actionNode.fade("out");
  541. }.bind(this),
  542. "click": function(e){
  543. this.itemClick();
  544. }.bind(this)
  545. });
  546. this.flagNode.addEvents({
  547. "click": function(e){
  548. if (!this.childTween.isRunning()){
  549. var oy = this.childNode.retrieve("c-height", 0);
  550. var cy = this.childNode.getSize().y;
  551. if (cy>0){
  552. this.childNode.store("c-height", cy);
  553. this.childTween.start("height", cy, 0);
  554. this.flagIconNode.setStyles(this.style.flagIconNode_c);
  555. }else{
  556. this.childTween.start("height", 0, oy);
  557. this.flagIconNode.setStyles(this.style.flagIconNode_e);
  558. }
  559. }
  560. }.bind(this)
  561. });
  562. },
  563. itemClick: function(){
  564. if (this.explorer.currentItem){
  565. if (this.explorer.currentItem.unSelected()){
  566. this.selected();
  567. }else{
  568. this.explorer.app.notice(this.explorer.app.lp.organizationSave, "error", this.propertyContentNode);
  569. }
  570. }else{
  571. this.selected();
  572. }
  573. },
  574. selected: function(){
  575. this.explorer.currentItem = this;
  576. this.flagNode.setStyles(this.style.flagNodeSelected);
  577. this.showItemProperty();
  578. },
  579. unSelected: function(){
  580. if (this.isEdit) return false;
  581. this.explorer.currentItem = null;
  582. this.flagNode.setStyles(this.style.flagNode);
  583. this.clearItemProperty();
  584. return true;
  585. },
  586. showItemProperty: function(){
  587. this.explorer.propertyTitleNode.set("text", this.data.name);
  588. this.showItemPropertyBase();
  589. this.showItemPropertyDuty();
  590. this.showItemPropertyAttribute();
  591. },
  592. showItemPropertyBase: function(){
  593. this.propertyBaseNode = new Element("div", {
  594. "styles": this.style.propertyInforNode
  595. }).inject(this.explorer.propertyContentNode);
  596. this.baseActionNode = new Element("div", {
  597. "styles": this.style.propertyInforActionNode
  598. }).inject(this.propertyBaseNode);
  599. this.propertyBaseTextNode = new Element("div", {
  600. "styles": this.style.propertyInforTextNode,
  601. "text": this.explorer.app.lp.companyBaseText
  602. }).inject(this.propertyBaseNode);
  603. if (this.isEditor) this.createEditBaseNode();
  604. this.propertyBaseContentNode = new Element("div", {
  605. "styles": this.style.propertyInforContentNode
  606. }).inject(this.propertyBaseNode);
  607. var html = "<table cellspacing='0' cellpadding='0' border='0' width='95%' align='center'>";
  608. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.companyName+"</td><td id='formCompanyName'></td></tr>";
  609. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.companyNumber+"</td><td id='formCompanyNumber'></td></tr>";
  610. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.companyAddress+"</td><td id='formCompanyAddress'></td></tr>";
  611. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.companyShortname+"</td><td id='formCompanyShortname'></td></tr>";
  612. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.orderNumber+"</td><td id='formOrderNumber'></td><tr>";
  613. html += "</table>";
  614. this.propertyBaseContentNode.set("html", html);
  615. // this.propertyBaseContentNode.getElements("td").setStyles({
  616. // "border-bottom": "1px solid #c9c9c9"
  617. // });
  618. this.propertyBaseContentNode.getElements("td.formTitle").setStyles(this.style.propertyBaseContentTdTitle);
  619. this.companyNameInput = new MWF.xApplication.Organization.Input(this.propertyBaseContentNode.getElement("#formCompanyName"), this.data.name, this.explorer.css.formInput);
  620. this.companyNumberInput = new MWF.xApplication.Organization.Input(this.propertyBaseContentNode.getElement("#formCompanyNumber"), this.data.number, this.explorer.css.formInput);
  621. this.companyAddressInput = new MWF.xApplication.Organization.Input(this.propertyBaseContentNode.getElement("#formCompanyAddress"), this.data.address, this.explorer.css.formInput);
  622. this.companyShortnameInput = new MWF.xApplication.Organization.Input(this.propertyBaseContentNode.getElement("#formCompanyShortname"), this.data.shortname, this.explorer.css.formInput);
  623. this.orderNumberInput = new MWF.xApplication.Organization.Input(this.propertyBaseContentNode.getElement("#formOrderNumber"), this.data.orderNumber, this.explorer.css.formInput);;
  624. },
  625. createEditBaseNode: function(){
  626. this.editBaseNode = new Element("button", {
  627. "styles": this.style.editBaseNode,
  628. "text": this.explorer.app.lp.edit,
  629. "events": {"click": this.editBaseInfor.bind(this)}
  630. }).inject(this.baseActionNode);
  631. },
  632. createCancelBaseNode: function(){
  633. this.cancelBaseNode = new Element("button", {
  634. "styles": this.style.cancelBaseNode,
  635. "text": this.explorer.app.lp.cancel,
  636. "events": {"click": this.cancelBaseInfor.bind(this)}
  637. }).inject(this.baseActionNode);
  638. },
  639. createSaveBaseNode: function(){
  640. this.saveBaseNode = new Element("button", {
  641. "styles": this.style.saveBaseNode,
  642. "text": this.explorer.app.lp.save,
  643. "events": {"click": this.saveBaseInfor.bind(this)}
  644. }).inject(this.baseActionNode);
  645. },
  646. editBaseInfor: function(){
  647. this.baseActionNode.empty();
  648. this.editBaseNode = null;
  649. this.createCancelBaseNode();
  650. this.createSaveBaseNode();
  651. this.editMode();
  652. },
  653. cancelBaseInfor: function(){
  654. if (this.data.name){
  655. this.baseActionNode.empty();
  656. this.cancelBaseNode = null;
  657. this.saveBaseNode = null;
  658. this.createEditBaseNode();
  659. this.readMode();
  660. }else{
  661. this.destroy();
  662. }
  663. },
  664. destroy: function(){
  665. if (this.parentItem) this.parentItem.children.erase(this);
  666. this.explorer.currentItem = null;
  667. this.clearItemProperty();
  668. this.node.destroy();
  669. delete this;
  670. },
  671. saveBaseInfor: function(callback){
  672. if (!this.companyNameInput.input.get("value")){
  673. this.explorer.app.notice(this.explorer.app.lp.inputOrganizationInfor, "error", this.explorer.propertyContentNode);
  674. return false;
  675. }
  676. this.propertyBaseNode.mask({
  677. "style": {
  678. "opacity": 0.7,
  679. "background-color": "#999"
  680. }
  681. });
  682. this.save(function(){
  683. this.baseActionNode.empty();
  684. this.cancelBaseNode = null;
  685. this.saveBaseNode = null;
  686. this.createEditBaseNode();
  687. this.readMode();
  688. this.setNewItem();
  689. this.propertyBaseNode.unmask();
  690. if (callback) callback();
  691. }.bind(this), function(xhr, text, error){
  692. var errorText = error;
  693. if (xhr) errorText = xhr.responseText;
  694. this.explorer.app.notice("request json error: "+errorText, "error");
  695. this.propertyBaseNode.unmask();
  696. }.bind(this));
  697. },
  698. clearItemProperty: function(){
  699. this.explorer.propertyTitleNode.empty();
  700. this.explorer.propertyContentNode.empty();
  701. },
  702. editMode: function(){
  703. this.companyNameInput.editMode();
  704. this.companyNumberInput.editMode();
  705. this.companyAddressInput.editMode();
  706. this.companyShortnameInput.editMode();
  707. this.orderNumberInput.editMode();
  708. this.isEdit = true;
  709. },
  710. readMode: function(){
  711. this.companyNameInput.readMode();
  712. this.companyNumberInput.readMode();
  713. this.companyAddressInput.readMode();
  714. this.companyShortnameInput.readMode();
  715. this.orderNumberInput.readMode();
  716. this.isEdit = false;
  717. },
  718. save: function(callback, cancel){
  719. this.data.name = this.companyNameInput.save();
  720. this.data.number = this.companyNumberInput.save();
  721. this.data.address = this.companyAddressInput.save();
  722. this.data.shortname = this.companyShortnameInput.save();
  723. this.data.orderNumber = this.orderNumberInput.save();
  724. this.explorer.actions.saveCompany(this.data, function(json){
  725. if (!this.data.id) this.data.id = json.data.id;
  726. this.textNode.set("text", this.data.name);
  727. if (callback) callback();
  728. }.bind(this), function(xhr, text, error){
  729. if (cancel) cancel(xhr, text, error);
  730. }.bind(this));
  731. },
  732. showItemPropertyDuty: function(){
  733. this.propertyDutyNode = new Element("div", {
  734. "styles": this.style.propertyInforNode
  735. }).inject(this.explorer.propertyContentNode);
  736. this.dutyActionNode = new Element("div", {
  737. "styles": this.style.propertyInforActionNode
  738. }).inject(this.propertyDutyNode);
  739. this.propertyDutyTextNode = new Element("div", {
  740. "styles": this.style.propertyInforTextNode,
  741. "text": this.explorer.app.lp.companyDutyText
  742. }).inject(this.propertyDutyNode);
  743. // this.createEditBaseNode();
  744. this.propertyDutyContentNode = new Element("div", {
  745. "styles": this.style.propertyInforContentNode
  746. }).inject(this.propertyDutyNode);
  747. if (this.isEditor) {
  748. this.createDeleteDutyNode();
  749. this.createAddDutyNode();
  750. }
  751. this.listDuty();
  752. },
  753. createAddDutyNode: function(){
  754. this.addDutyNode = new Element("button", {
  755. "styles": this.style.addDutyNode,
  756. "text": this.explorer.app.lp.add,
  757. "events": {"click": this.addDuty.bind(this)}
  758. }).inject(this.dutyActionNode);
  759. },
  760. createDeleteDutyNode: function(){
  761. this.deleteDutyNode = new Element("button", {
  762. "styles": this.style.deleteDutyNode_desable,
  763. "text": this.explorer.app.lp["delete"],
  764. "disable": true
  765. }).inject(this.dutyActionNode);
  766. },
  767. addDuty: function(){
  768. var data = this.getNewDutyData();
  769. if (!this.created){
  770. this.saveBaseInfor(function(){
  771. new MWF.xApplication.Organization.CompanyDuty(this.propertyDutyContentNode.getElement("table").getFirst(), data, this, this.explorer.css.map);
  772. }.bind(this));
  773. }else{
  774. new MWF.xApplication.Organization.CompanyDuty(this.propertyDutyContentNode.getElement("table").getFirst(), data, this, this.explorer.css.map);
  775. }
  776. },
  777. getNewDutyData: function(){
  778. return {
  779. "company": this.data.id,
  780. "name": "",
  781. };
  782. },
  783. checkDeleteDutyAction: function(){
  784. if (this.selectedDutys.length){
  785. if (this.deleteDutyNode.get("disable")){
  786. this.deleteDutyNode.set({
  787. "styles": this.style.deleteDutyNode
  788. });
  789. this.deleteDutyNode.removeProperty("disable");
  790. this.deleteDutyNode.addEvent("click", function(e){this.deleteDuty(e);}.bind(this));
  791. }
  792. }else{
  793. if (!this.deleteDutyNode.get("disable")){
  794. this.deleteDutyNode.set({
  795. "styles": this.style.deleteDutyNode_desable,
  796. "disable": true
  797. });
  798. this.deleteDutyNode.removeEvents("click");
  799. }
  800. }
  801. },
  802. deleteDuty: function(e){
  803. var _self = this;
  804. this.explorer.app.confirm("infor", e, this.explorer.app.lp.deleteDutyTitle, this.explorer.app.lp.deleteDuty, 300, 120, function(){
  805. this.close();
  806. _self.selectedDutys.each(function(duty){
  807. duty.remove();
  808. });
  809. delete _self.selectedDutys;
  810. _self.selectedDutys = [];
  811. _self.checkDeleteDutyAction();
  812. }, function(){this.close();});
  813. },
  814. listDuty: function(){
  815. var html = "<table cellspacing='0' cellpadding='5' border='0' width='95%' align='center' style='line-height:normal'>";
  816. html += "<tr><th style='width:20px'></th>";
  817. html += "<th style='width: 30%; border-right: 1px solid #FFF'>"+this.explorer.app.lp.dutyName+"</th>";
  818. html += "<th>"+this.explorer.app.lp.dutyMember+"</th><th style='width:20px'></th></tr>";
  819. html += "</table>";
  820. this.propertyDutyContentNode.set("html", html);
  821. this.propertyDutyContentNode.getElements("th").setStyles(this.style.propertyDutyContentTdTitle);
  822. if (this.data.id){
  823. this.explorer.actions.listCompanyDuty(function(json){
  824. json.data.each(function(item){
  825. new MWF.xApplication.Organization.CompanyDuty(this.propertyDutyContentNode.getElement("table").getFirst(), item, this, this.explorer.css.map);
  826. }.bind(this));
  827. }.bind(this), null, this.data.id);
  828. }
  829. },
  830. getDutyCount: function(){
  831. if (this.data.id){
  832. var count = 0;
  833. this.explorer.actions.listCompanyDuty(function(json){
  834. count = json.data.length;
  835. }.bind(this), null, this.data.id, false);
  836. return count;
  837. }
  838. return 0;
  839. },
  840. showItemPropertyAttribute: function(){
  841. this.propertyAttributeNode = new Element("div", {
  842. "styles": this.style.propertyInforNode
  843. }).inject(this.explorer.propertyContentNode);
  844. this.attributeActionNode = new Element("div", {
  845. "styles": this.style.propertyInforActionNode
  846. }).inject(this.propertyAttributeNode);
  847. this.propertyAttributeTextNode = new Element("div", {
  848. "styles": this.style.propertyInforTextNode,
  849. "text": this.explorer.app.lp.companyAttributeText
  850. }).inject(this.propertyAttributeNode);
  851. // this.createEditBaseNode();
  852. this.propertyAttributeContentNode = new Element("div", {
  853. "styles": this.style.propertyInforContentNode
  854. }).inject(this.propertyAttributeNode);
  855. if (this.isEditor) {
  856. this.createDeleteAttributeNode();
  857. this.createAddAttributeNode();
  858. }
  859. this.listAttribute();
  860. },
  861. createAddAttributeNode: function(){
  862. this.addAttributeNode = new Element("button", {
  863. "styles": this.style.addDutyNode,
  864. "text": this.explorer.app.lp.add,
  865. "events": {"click": this.addAttribute.bind(this)}
  866. }).inject(this.attributeActionNode);
  867. },
  868. createDeleteAttributeNode: function(){
  869. this.deleteAttributeNode = new Element("button", {
  870. "styles": this.style.deleteDutyNode_desable,
  871. "text": this.explorer.app.lp["delete"],
  872. "disable": true
  873. }).inject(this.attributeActionNode);
  874. },
  875. addAttribute: function(){
  876. var data = this.getNewAttributeData();
  877. if (!this.created){
  878. this.saveBaseInfor(function(){
  879. new MWF.xApplication.Organization.CompanyAttribute(this.propertyAttributeContentNode.getElement("table").getFirst(), data, this, this.explorer.css.map);
  880. }.bind(this));
  881. }else{
  882. new MWF.xApplication.Organization.CompanyAttribute(this.propertyAttributeContentNode.getElement("table").getFirst(), data, this, this.explorer.css.map);
  883. }
  884. },
  885. getNewAttributeData: function(){
  886. return {
  887. "company": this.data.id,
  888. "name": "",
  889. "attributeList":[]
  890. };
  891. },
  892. checkDeleteAttributeAction: function(){
  893. if (this.selectedAttributes.length){
  894. if (this.deleteAttributeNode.get("disable")){
  895. this.deleteAttributeNode.set({
  896. "styles": this.style.deleteDutyNode
  897. });
  898. this.deleteAttributeNode.removeProperty("disable");
  899. this.deleteAttributeNode.addEvent("click", function(e){this.deleteAttribute(e);}.bind(this));
  900. }
  901. }else{
  902. if (!this.deleteAttributeNode.get("disable")){
  903. this.deleteAttributeNode.set({
  904. "styles": this.style.deleteDutyNode_desable,
  905. "disable": true
  906. });
  907. this.deleteAttributeNode.removeEvents("click");
  908. }
  909. }
  910. },
  911. deleteAttribute: function(e){
  912. var _self = this;
  913. this.explorer.app.confirm("infor", e, this.explorer.app.lp.deleteAttributeTitle, this.explorer.app.lp.deleteAttribute, 300, 120, function(){
  914. this.close();
  915. _self.selectedAttributes.each(function(attribute){
  916. attribute.remove();
  917. });
  918. delete _self.selectedAttributes;
  919. _self.selectedAttribute = [];
  920. _self.checkDeleteAttributeAction();
  921. }, function(){this.close();});
  922. },
  923. listAttribute: function(){
  924. var html = "<table cellspacing='0' cellpadding='5' border='0' width='95%' align='center' style='line-height:normal'>";
  925. html += "<tr><th style='width:20px'></th>";
  926. html += "<th style='width: 30%; border-right: 1px solid #FFF'>"+this.explorer.app.lp.attributeName+"</th>";
  927. html += "<th>"+this.explorer.app.lp.attributeValue+"</th><th style='width:20px'></th></tr>";
  928. html += "</table>";
  929. this.propertyAttributeContentNode.set("html", html);
  930. this.propertyAttributeContentNode.getElements("th").setStyles(this.style.propertyDutyContentTdTitle);
  931. if (this.data.id){
  932. this.explorer.actions.listCompanyAttribute(function(json){
  933. json.data.each(function(item){
  934. new MWF.xApplication.Organization.CompanyAttribute(this.propertyAttributeContentNode.getElement("table").getFirst(), item, this, this.explorer.css.map);
  935. }.bind(this));
  936. }.bind(this), null, this.data.id);
  937. }
  938. },
  939. getAttributeCount: function(){
  940. if (this.data.id){
  941. var count = 0;
  942. this.explorer.actions.listCompanyAttribute(function(json){
  943. count = json.data.length;
  944. }.bind(this), null, this.data.id, false);
  945. return count;
  946. }
  947. return 0;
  948. },
  949. getMemberCount: function(){return 0;},
  950. "delete": function(success, failure){
  951. this.children.each(function(item){
  952. item["delete"]();
  953. });
  954. this._deleteDutys();
  955. this._deleteAttributes();
  956. this._deleteMembers();
  957. this._deleteItem(this.data.id, function(){
  958. this.destroy();
  959. if (success) success();
  960. }.bind(this), function(xhr, text, error){
  961. var errorText = error;
  962. if (xhr) errorText = xhr.responseText;
  963. if (failure) failure(errorText);
  964. }.bind(this));
  965. },
  966. _deleteItem: function(id, success, failure){
  967. this.explorer.actions.deleteCompany(id, success, failure, false);
  968. },
  969. _deleteDutys: function(){
  970. this._listDutys(function(json){
  971. json.data.each(function(duty){
  972. this.explorer.actions.deleteCompanyDuty(duty.id, null, null, false);
  973. }.bind(this));
  974. }.bind(this));
  975. },
  976. _listDutys: function(success){
  977. this.explorer.actions.listCompanyDuty(function(json){
  978. if (success) success(json);
  979. }.bind(this), null, this.data.id, false);
  980. },
  981. _deleteAttributes: function(){
  982. this._listAttributes(function(json){
  983. json.data.each(function(att){
  984. this.explorer.actions.deleteCompanyAttribute(att.id, null, null, false);
  985. }.bind(this));
  986. }.bind(this));
  987. },
  988. _listAttributes: function(success){
  989. this.explorer.actions.listCompanyAttribute(function(json){
  990. if (success) success(json);
  991. }.bind(this), null, this.data.id, false);
  992. },
  993. _deleteMembers: function(){
  994. return true;
  995. }
  996. });
  997. MWF.xApplication.Organization.OrgExplorer.Company = new Class({
  998. Extends: MWF.xApplication.Organization.OrgExplorer.Item
  999. });
  1000. MWF.xApplication.Organization.OrgExplorer.Department = new Class({
  1001. Extends: MWF.xApplication.Organization.OrgExplorer.Item,
  1002. initStyle: function(){
  1003. this.style = this.explorer.css.departmentItem;
  1004. },
  1005. addActions: function(){
  1006. MWF.AC.isDepartmentEditor({
  1007. "id": this.data.company,
  1008. "yes": function(){
  1009. this.isEditor = true;
  1010. this.deleteNode = new Element("div", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  1011. this.addDepartmentNode = new Element("div", {"styles": this.style.actionAddDepartmentNode, "title": this.explorer.app.lp.createSubDepartment}).inject(this.actionNode);
  1012. this.deleteNode.addEvent("click", function(e){
  1013. this.deleteButton();
  1014. e.stopPropagation();
  1015. }.bind(this));
  1016. this.addDepartmentNode.addEvent("click", function(e){
  1017. if (!this.checkDelete()) if (this.data.id) this.addDepartment();
  1018. e.stopPropagation();
  1019. }.bind(this));
  1020. }.bind(this)
  1021. });
  1022. },
  1023. addDepartment: function(){
  1024. var isNewElement = true;
  1025. if (this.explorer.currentItem) isNewElement = this.explorer.currentItem.unSelected();
  1026. if (isNewElement){
  1027. var newElementData = this.explorer._getAddDepartmentData();
  1028. newElementData.superior = this.data.id;
  1029. var item = new MWF.xApplication.Organization.OrgExplorer.Department(newElementData, this.explorer);
  1030. item.parentItem = this;
  1031. item.load();
  1032. item.selected();
  1033. item.editBaseInfor();
  1034. (new Fx.Scroll(this.explorer.chartScrollNode)).toElementCenter(item.node, "y");
  1035. }else{
  1036. this.app.notice(this.explorer.app.lp.organizationSave, "error", this.propertyContentNode);
  1037. }
  1038. },
  1039. saveBaseInfor: function(callback){
  1040. if (!this.departmentNameInput.input.get("value")){
  1041. this.explorer.app.notice(this.explorer.app.lp.inputOrganizationInfor, "error", this.explorer.propertyContentNode);
  1042. return false;
  1043. }
  1044. this.propertyBaseNode.mask({
  1045. "style": {
  1046. "opacity": 0.7,
  1047. "background-color": "#999"
  1048. }
  1049. });
  1050. this.save(function(){
  1051. this.baseActionNode.empty();
  1052. this.cancelBaseNode = null;
  1053. this.saveBaseNode = null;
  1054. this.createEditBaseNode();
  1055. this.readMode();
  1056. this.setNewItem();
  1057. this.propertyBaseNode.unmask();
  1058. if (callback) callback();
  1059. }.bind(this), function(xhr, text, error){
  1060. var errorText = error;
  1061. if (xhr) errorText = xhr.responseText;
  1062. this.explorer.app.notice("request json error: "+errorText, "error");
  1063. this.propertyBaseNode.unmask();
  1064. }.bind(this));
  1065. },
  1066. showItemProperty: function(){
  1067. this.explorer.propertyTitleNode.set("text", this.data.name);
  1068. this.showItemPropertyBase();
  1069. this.showItemPropertyDuty();
  1070. this.showItemPropertyAttribute();
  1071. this.showItemMembers();
  1072. },
  1073. showItemPropertyBase: function(){
  1074. this.propertyBaseNode = new Element("div", {
  1075. "styles": this.style.propertyInforNode
  1076. }).inject(this.explorer.propertyContentNode);
  1077. this.baseActionNode = new Element("div", {
  1078. "styles": this.style.propertyInforActionNode
  1079. }).inject(this.propertyBaseNode);
  1080. this.propertyBaseTextNode = new Element("div", {
  1081. "styles": this.style.propertyInforTextNode,
  1082. "text": this.explorer.app.lp.departmentBaseText
  1083. }).inject(this.propertyBaseNode);
  1084. if (this.isEditor) this.createEditBaseNode();
  1085. this.propertyBaseContentNode = new Element("div", {
  1086. "styles": this.style.propertyInforContentNode
  1087. }).inject(this.propertyBaseNode);
  1088. var html = "<table cellspacing='0' cellpadding='0' border='0' width='95%' align='center'>";
  1089. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.departmentName+"</td><td id='formDepartmentName'></td></tr>";
  1090. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.departmentNumber+"</td><td id='formDepartmentNumber'></td></tr>";
  1091. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.departmentShortname+"</td><td id='formDepartmentShortname'></td></tr>";
  1092. html += "<tr><td class='formTitle'>"+this.explorer.app.lp.orderNumber+"</td><td id='formOrderNumber'></td></tr>";
  1093. html += "</table>";
  1094. this.propertyBaseContentNode.set("html", html);
  1095. // this.propertyBaseContentNode.getElements("td").setStyles({
  1096. // "border-bottom": "1px solid #c9c9c9"
  1097. // });
  1098. this.propertyBaseContentNode.getElements("td.formTitle").setStyles(this.style.propertyBaseContentTdTitle);
  1099. this.departmentNameInput = new MWF.xApplication.Organization.Input(this.propertyBaseContentNode.getElement("#formDepartmentName"), this.data.name, this.explorer.css.formInput);
  1100. this.departmentNumberInput = new MWF.xApplication.Organization.Input(this.propertyBaseContentNode.getElement("#formDepartmentNumber"), this.data.number, this.explorer.css.formInput);
  1101. this.departmentShortnameInput = new MWF.xApplication.Organization.Input(this.propertyBaseContentNode.getElement("#formDepartmentShortname"), this.data.shortname, this.explorer.css.formInput);
  1102. this.orderNumberInput = new MWF.xApplication.Organization.Input(this.propertyBaseContentNode.getElement("#formOrderNumber"), this.data.orderNumber, this.explorer.css.formInput);;
  1103. },
  1104. editMode: function(){
  1105. this.departmentNameInput.editMode();
  1106. this.departmentNumberInput.editMode();
  1107. this.departmentShortnameInput.editMode();
  1108. this.orderNumberInput.editMode();
  1109. this.isEdit = true;
  1110. },
  1111. readMode: function(){
  1112. this.departmentNameInput.readMode();
  1113. this.departmentNumberInput.readMode();
  1114. this.departmentShortnameInput.readMode();
  1115. this.orderNumberInput.readMode();
  1116. this.isEdit = false;
  1117. },
  1118. save: function(callback){
  1119. this.data.name = this.departmentNameInput.save();
  1120. this.data.number = this.departmentNumberInput.save();
  1121. this.data.shortname = this.departmentShortnameInput.save();
  1122. this.data.orderNumber = this.orderNumberInput.save();
  1123. this.explorer.actions.saveDepartment(this.data, function(json){
  1124. if (!this.data.id) this.data.id = json.data.id;
  1125. this.textNode.set("text", this.data.name);
  1126. if (callback) callback();
  1127. }.bind(this));
  1128. },
  1129. getNewDutyData: function(){
  1130. return {
  1131. "department": this.data.id,
  1132. "name": ""
  1133. };
  1134. },
  1135. getNewAttributeData: function(){
  1136. return {
  1137. "department": this.data.id,
  1138. "name": "",
  1139. "attributeList":[]
  1140. };
  1141. },
  1142. listDuty: function(){
  1143. this.propertyDutyTextNode.set("text", this.explorer.app.lp.departmentDutyText);
  1144. var html = "<table cellspacing='0' cellpadding='5' border='0' width='95%' align='center' style='line-height:normal'>";
  1145. html += "<tr><th style='width:20px'></th>";
  1146. html += "<th style='width: 30%; border-right: 1px solid #FFF'>"+this.explorer.app.lp.dutyName+"</th>";
  1147. html += "<th>"+this.explorer.app.lp.dutyMember+"</th><th style='width:20px'></th></tr>";
  1148. html += "</table>";
  1149. this.propertyDutyContentNode.set("html", html);
  1150. this.propertyDutyContentNode.getElements("th").setStyles(this.style.propertyDutyContentTdTitle);
  1151. if (this.data.id){
  1152. this.explorer.actions.listDepartmentDuty(function(json){
  1153. json.data.each(function(item){
  1154. new MWF.xApplication.Organization.DepartmentDuty(this.propertyDutyContentNode.getElement("table").getFirst(), item, this, this.explorer.css.map);
  1155. }.bind(this));
  1156. }.bind(this), null, this.data.id);
  1157. }
  1158. },
  1159. getDutyCount: function(){
  1160. if (this.data.id){
  1161. var count = 0;
  1162. this.explorer.actions.listDepartmentDuty(function(json){
  1163. count = json.data.length;
  1164. }.bind(this), null, this.data.id, false);
  1165. return count;
  1166. }
  1167. return 0;
  1168. },
  1169. addDuty: function(){
  1170. var data = this.getNewDutyData();
  1171. if (!this.created){
  1172. this.saveBaseInfor(function(){
  1173. new MWF.xApplication.Organization.DepartmentDuty(this.propertyDutyContentNode.getElement("table").getFirst(), data, this, this.explorer.css.map);
  1174. }.bind(this));
  1175. }else{
  1176. new MWF.xApplication.Organization.DepartmentDuty(this.propertyDutyContentNode.getElement("table").getFirst(), data, this, this.explorer.css.map);
  1177. }
  1178. },
  1179. listAttribute: function(){
  1180. this.propertyAttributeTextNode.set("text", this.explorer.app.lp.departmentAttributeText);
  1181. var html = "<table cellspacing='0' cellpadding='5' border='0' width='95%' align='center' style='line-height:normal'>";
  1182. html += "<tr><th style='width:20px'></th>";
  1183. html += "<th style='width: 30%; border-right: 1px solid #FFF'>"+this.explorer.app.lp.attributeName+"</th>";
  1184. html += "<th>"+this.explorer.app.lp.attributeValue+"</th><th style='width:20px'></th></tr>";
  1185. html += "</table>";
  1186. this.propertyAttributeContentNode.set("html", html);
  1187. this.propertyAttributeContentNode.getElements("th").setStyles(this.style.propertyDutyContentTdTitle);
  1188. if (this.data.id){
  1189. this.explorer.actions.listDepartmentAttribute(function(json){
  1190. json.data.each(function(item){
  1191. new MWF.xApplication.Organization.DepartmentAttribute(this.propertyAttributeContentNode.getElement("table").getFirst(), item, this, this.explorer.css.map);
  1192. }.bind(this));
  1193. }.bind(this), null, this.data.id);
  1194. }
  1195. },
  1196. getAttributeCount: function(){
  1197. if (this.data.id){
  1198. var count = 0;
  1199. this.explorer.actions.listDepartmentAttribute(function(json){
  1200. count = json.data.length;
  1201. }.bind(this), null, this.data.id, false);
  1202. return count;
  1203. }
  1204. return 0;
  1205. },
  1206. addAttribute: function(){
  1207. var data = this.getNewAttributeData();
  1208. if (!this.created){
  1209. this.saveBaseInfor(function(){
  1210. new MWF.xApplication.Organization.DepartmentAttribute(this.propertyAttributeContentNode.getElement("table").getFirst(), data, this, this.explorer.css.map);
  1211. }.bind(this));
  1212. }else{
  1213. new MWF.xApplication.Organization.DepartmentAttribute(this.propertyAttributeContentNode.getElement("table").getFirst(), data, this, this.explorer.css.map);
  1214. }
  1215. },
  1216. showItemMembers: function(){
  1217. this.propertyMembersNode = new Element("div", {
  1218. "styles": this.style.propertyInforNode
  1219. }).inject(this.explorer.propertyContentNode);
  1220. this.membersActionNode = new Element("div", {
  1221. "styles": this.style.propertyInforActionNode
  1222. }).inject(this.propertyMembersNode);
  1223. this.propertyMembersTextNode = new Element("div", {
  1224. "styles": this.style.propertyInforTextNode,
  1225. "text": this.explorer.app.lp.departmentMemberText
  1226. }).inject(this.propertyMembersNode);
  1227. this.propertyMemberContentNode = new Element("div", {
  1228. "styles": this.style.propertyInforContentNode
  1229. }).inject(this.propertyMembersNode);
  1230. // this.createDeleteMemberNode();
  1231. if (this.isEditor) this.createAddMemberNode();
  1232. this.listMembers();
  1233. },
  1234. createAddMemberNode: function(){
  1235. this.addMemberNode = new Element("button", {
  1236. "styles": this.style.addDutyNode,
  1237. "text": this.explorer.app.lp.add,
  1238. "events": {"click": this.addMember.bind(this)}
  1239. }).inject(this.membersActionNode);
  1240. },
  1241. createDeleteMemberNode: function(){
  1242. this.deleteMemberNode = new Element("button", {
  1243. "styles": this.style.deleteDutyNode_desable,
  1244. "text": this.explorer.app.lp["delete"],
  1245. "disable": true
  1246. }).inject(this.membersActionNode);
  1247. },
  1248. checkSaveBaseInfor: function(callback){
  1249. if (!this.created){
  1250. this.saveBaseInfor(function(){
  1251. if (callback) callback();
  1252. }.bind(this));
  1253. }else{
  1254. if (callback) callback();
  1255. }
  1256. },
  1257. addMember: function(){
  1258. this.checkSaveBaseInfor(function(){
  1259. MWF.xDesktop.requireApp("Organization", "Selector.Person", function(){
  1260. var selector = new MWF.xApplication.Organization.Selector.Person(this.explorer.app.content,{
  1261. "values": [],
  1262. "onComplete": function(items){
  1263. var ids = 0;
  1264. items.each(function(item){
  1265. var newIData = {
  1266. "person": item.data.id,
  1267. "department": this.data.id,
  1268. "name": item.data.name+"("+this.data.name+")"
  1269. };
  1270. this.explorer.actions.saveIdentity(newIData, function(json){
  1271. newIData.id = json.data.id;
  1272. this.createIdentity(newIData);
  1273. }.bind(this));
  1274. }.bind(this));
  1275. }.bind(this)
  1276. });
  1277. selector.load();
  1278. }.bind(this));
  1279. }.bind(this));
  1280. },
  1281. listMembers: function(){
  1282. if (this.data.id) {
  1283. this.explorer.actions.listIdentity(function (json) {
  1284. json.data.each(function (item) {
  1285. var _department = this;
  1286. this.createIdentity(item);
  1287. }.bind(this));
  1288. }.bind(this), null, this.data.id);
  1289. }
  1290. },
  1291. getMemberCount: function(){
  1292. if (this.data.id){
  1293. var count = 0;
  1294. this.explorer.actions.listIdentity(function(json){
  1295. count = json.data.length;
  1296. }.bind(this), null, this.data.id, false);
  1297. return count;
  1298. }
  1299. return 0;
  1300. },
  1301. createIdentity: function(item){
  1302. _department = this;
  1303. MWF.require("MWF.widget.Identity", function(){
  1304. new MWF.widget.Identity(item, this.propertyMemberContentNode, this.explorer, this.isEditor, function(e){
  1305. var _self = this;
  1306. var text = this.explorer.app.lp.deleteIdentityInDepartment;
  1307. text = text.replace("{depart}", _department.data.name);
  1308. text = text.replace("{identity}", this.data.name);
  1309. _self.explorer.app.confirm("warn", e, this.explorer.app.lp.deleteIdentityInDepartmentTitle, text, 400, 140, function(){
  1310. _self.explorer.actions.deleteIdentity(_self.data.id, function(){
  1311. _self.node.destroy();
  1312. delete _self;
  1313. // _department.
  1314. });
  1315. this.close();
  1316. }, function(){
  1317. this.close();
  1318. });
  1319. });
  1320. }.bind(this));
  1321. },
  1322. _deleteItem: function(id, success, failure){
  1323. this.explorer.actions.deleteDepartment(id, success, failure, false);
  1324. },
  1325. _deleteDutys: function(){
  1326. this._listDutys(function(json){
  1327. json.data.each(function(duty){
  1328. this.explorer.actions.deleteDepartmentDuty(duty.id, null, null, false);
  1329. }.bind(this));
  1330. }.bind(this));
  1331. },
  1332. _listDutys: function(success){
  1333. this.explorer.actions.listDepartmentDuty(function(json){
  1334. if (success) success(json);
  1335. }.bind(this), null, this.data.id, false);
  1336. },
  1337. _deleteAttributes: function(){
  1338. this._listAttributes(function(json){
  1339. json.data.each(function(att){
  1340. this.explorer.actions.deleteDepartmentAttribute(att.id, null, null, false);
  1341. }.bind(this));
  1342. }.bind(this));
  1343. },
  1344. _listAttributes: function(success){
  1345. this.explorer.actions.listDepartmentAttribute(function(json){
  1346. if (success) success(json);
  1347. }.bind(this), null, this.data.id, false);
  1348. },
  1349. _deleteMembers: function(){
  1350. this.explorer.actions.listIdentity(function(json){
  1351. json.data.each(function(i){
  1352. this.explorer.actions.deleteIdentity(i.id, null, null, false);
  1353. }.bind(this));
  1354. }.bind(this), null, this.data.id, false);
  1355. }
  1356. });
  1357. MWF.xApplication.Organization.Input = new Class({
  1358. Implements: [Events],
  1359. initialize: function(node, value, style){
  1360. this.node = $(node);
  1361. this.value = value || "";
  1362. this.style = style;
  1363. this.load();
  1364. },
  1365. load: function(){
  1366. this.content = new Element("div", {
  1367. "styles": this.style.content,
  1368. "text": this.value
  1369. }).inject(this.node);
  1370. },
  1371. editMode: function(){
  1372. this.content.empty();
  1373. this.input = new Element("input",{
  1374. "styles": this.style.input,
  1375. "value": this.value
  1376. }).inject(this.content);
  1377. this.input.addEvents({
  1378. "focus": function(){
  1379. this.input.setStyles(this.style.input_focus);
  1380. }.bind(this),
  1381. "blur": function(){
  1382. this.input.setStyles(this.style.input);
  1383. }.bind(this)
  1384. });
  1385. },
  1386. readMode: function(){
  1387. this.content.empty();
  1388. this.input = null;
  1389. this.content.set("text", this.value);
  1390. },
  1391. save: function(){
  1392. if (this.input) this.value = this.input.get("value");
  1393. return this.value;
  1394. }
  1395. });
  1396. MWF.xApplication.Organization.CompanyDuty = new Class({
  1397. initialize: function(container, data, item, style){
  1398. this.container = $(container);
  1399. this.data = data;
  1400. if (this.data.identityList) this.data.identityList = data.identityList.filter(function(item){return item;});
  1401. this.style = style;
  1402. this.item = item;
  1403. this.identitys = [];
  1404. this.selected = false;
  1405. this.load();
  1406. },
  1407. load: function(){
  1408. this.node = new Element("tr", {
  1409. "styles": this.style.contentNode
  1410. }).inject(this.container);
  1411. this.selectNode = new Element("td", {
  1412. "styles": this.style.selectNode
  1413. }).inject(this.node);
  1414. this.nameNode = new Element("td", {
  1415. "styles": this.style.nameNode,
  1416. "html": (this.data.name) ? this.data.name : "<input type='text'/>"
  1417. }).inject(this.node);
  1418. this.input = this.nameNode.getFirst("input");
  1419. if (this.input) this.setEditNameInput();
  1420. this.valueNode = new Element("td", {
  1421. "styles": this.style.valueNode
  1422. }).inject(this.node);
  1423. this.createActionNode();
  1424. this.setEvent();
  1425. this.loadValue();
  1426. },
  1427. createActionNode: function(){
  1428. this.actionNode = new Element("td", {
  1429. "styles": this.style.actionNode
  1430. }).inject(this.node);
  1431. if (this.item.isEditor) {
  1432. this.actionNode.addEvent("click", function () {
  1433. this.addIdentitys();
  1434. }.bind(this));
  1435. }else{
  1436. this.actionNode.setStyle("background", "transparent");
  1437. }
  1438. },
  1439. setEvent: function(){
  1440. this.selectNode.addEvent("click", function(){
  1441. this.selectNodeClick();
  1442. }.bind(this));
  1443. this.nameNode.addEvent("click", function(){
  1444. if (!this.input){
  1445. this.nameNode.empty();
  1446. this.input = new Element("input", {"type": "text", "value": this.data.name}).inject(this.nameNode);
  1447. this.setEditNameInput();
  1448. }
  1449. }.bind(this));
  1450. this.valueNodeClick();
  1451. },
  1452. selectNodeClick: function(){
  1453. if (!this.selected){
  1454. this.selected = true;
  1455. this.selectNode.setStyles(this.style.selectNode_selected);
  1456. this.node.setStyles(this.style.contentNode_selected);
  1457. this.item.selectedDutys.push(this);
  1458. this.item.checkDeleteDutyAction();
  1459. }else{
  1460. this.selected = false;
  1461. this.selectNode.setStyles(this.style.selectNode);
  1462. this.node.setStyles(this.style.contentNode);
  1463. this.item.selectedDutys.erase(this);
  1464. this.item.checkDeleteDutyAction();
  1465. }
  1466. },
  1467. valueNodeClick: function(){
  1468. },
  1469. setEditNameInput: function(){
  1470. this.input.setStyles(this.style.nameInputNode);
  1471. this.input.focus();
  1472. this.input.addEvents({
  1473. "blur": function(){
  1474. var name = this.input.get("value");
  1475. if (name){
  1476. if (name != this.data.name){
  1477. this.save(name);
  1478. }else{
  1479. this.nameNode.empty();
  1480. this.input = null;
  1481. this.nameNode.set("text", this.data.name);
  1482. }
  1483. }else{
  1484. if (!this.data.id){
  1485. this.node.destroy();
  1486. delete this;
  1487. }else{
  1488. this.nameNode.empty();
  1489. this.input = null;
  1490. this.nameNode.set("text", this.data.name);
  1491. }
  1492. }
  1493. }.bind(this)
  1494. });
  1495. },
  1496. save: function(name){
  1497. var oldName = this.data.name;
  1498. if (name) this.data.name = name;
  1499. this.item.explorer.actions.saveCompanyDuty(this.data, function(json){
  1500. this.data.id = json.data.id;
  1501. this.nameNode.empty();
  1502. this.input = null;
  1503. this.nameNode.set("text", this.data.name)
  1504. this.loadValue();
  1505. }.bind(this), function(xhr, text, error){
  1506. this.data.name = oldName;
  1507. this.input.focus();
  1508. var errorText = error;
  1509. if (xhr) errorText = xhr.responseText;
  1510. this.item.explorer.app.notice("request json error: "+errorText, "error");
  1511. }.bind(this));
  1512. },
  1513. loadValue: function(){
  1514. this.identitys = [];
  1515. this.valueNode.empty();
  1516. if (this.data.identityList){
  1517. this.data.identityList.each(function(id){
  1518. if (id){
  1519. this.item.explorer.actions.getIdentity(function(identity){
  1520. MWF.require("MWF.widget.Identity", function(){
  1521. this.identitys.push(new MWF.widget.Identity(identity.data, this.valueNode, this.item.explorer));
  1522. }.bind(this));
  1523. }.bind(this), null, id, false);
  1524. }
  1525. }.bind(this));
  1526. }
  1527. },
  1528. addIdentitys: function(){
  1529. var selector = new MWF.OrgSelector(this.item.explorer.app.content, {
  1530. "type": "Identity",
  1531. "values": this.data.identityList || [],
  1532. "onComplete": function(items){
  1533. var ids = [];
  1534. items.each(function(item){ids.push(item.data.id);});
  1535. this.data.identityList = ids;
  1536. this.save();
  1537. }.bind(this)
  1538. });
  1539. //selector.load();
  1540. },
  1541. remove: function(){
  1542. this.item.explorer.actions.deleteCompanyDuty(this.data.id, function(){
  1543. this.node.destroy();
  1544. delete this;
  1545. }.bind(this));
  1546. }
  1547. });
  1548. MWF.xApplication.Organization.DepartmentDuty = new Class({
  1549. Extends: MWF.xApplication.Organization.CompanyDuty,
  1550. save: function(name){
  1551. var oldName = this.data.name;
  1552. if (name) this.data.name = name;
  1553. this.item.explorer.actions.saveDepartmentDuty(this.data, function(json){
  1554. this.data.id = json.data.id;
  1555. this.nameNode.empty();
  1556. this.input = null;
  1557. this.nameNode.set("text", this.data.name);
  1558. this.loadValue();
  1559. }.bind(this), function(xhr, text, error){
  1560. this.data.name = oldName;
  1561. this.input.focus();
  1562. var errorText = error;
  1563. if (xhr) errorText = xhr.responseText;
  1564. this.item.explorer.app.notice("request json error: "+errorText, "error");
  1565. }.bind(this));
  1566. },
  1567. remove: function(){
  1568. this.item.explorer.actions.deleteDepartmentDuty(this.data.id, function(){
  1569. this.node.destroy();
  1570. delete this;
  1571. }.bind(this));
  1572. }
  1573. });
  1574. MWF.xApplication.Organization.CompanyAttribute = new Class({
  1575. Extends: MWF.xApplication.Organization.CompanyDuty,
  1576. createActionNode: function(){
  1577. this.actionNode = new Element("td", {"styles": this.style.actionAttributeNode}).inject(this.node);
  1578. },
  1579. selectNodeClick: function(){
  1580. if (!this.selected){
  1581. this.selected = true;
  1582. this.selectNode.setStyles(this.style.selectNode_selected);
  1583. this.node.setStyles(this.style.contentNode_selected);
  1584. this.item.selectedAttributes.push(this);
  1585. this.item.checkDeleteAttributeAction();
  1586. }else{
  1587. this.selected = false;
  1588. this.selectNode.setStyles(this.style.selectNode);
  1589. this.node.setStyles(this.style.contentNode);
  1590. this.item.selectedAttributes.erase(this);
  1591. this.item.checkDeleteAttributeAction();
  1592. }
  1593. },
  1594. valueNodeClick: function(){
  1595. this.valueNode.addEvent("click", function(){
  1596. if (!this.valueInput){
  1597. this.valueNode.empty();
  1598. this.valueInput = new Element("input", {"type": "text", "value": (this.data.attributeList) ? this.data.attributeList.join(",") : ""}).inject(this.valueNode);
  1599. this.setEditValueInput();
  1600. }
  1601. }.bind(this));
  1602. },
  1603. setEditValueInput: function(){
  1604. this.valueInput.setStyles(this.style.nameInputNode);
  1605. this.valueInput.focus();
  1606. this.valueInput.addEvents({
  1607. "blur": function(){
  1608. var value = this.valueInput.get("value");
  1609. if (value){
  1610. if (value != this.data.attributeList.join(",")){
  1611. this.saveValue(value);
  1612. }else{
  1613. this.valueNode.empty();
  1614. this.valueInput = null;
  1615. this.valueNode.set("text", this.data.attributeList.join(","));
  1616. }
  1617. }else{
  1618. if (!this.data.id){
  1619. this.node.destroy();
  1620. delete this;
  1621. }else{
  1622. this.valueNode.empty();
  1623. this.valueInput = null;
  1624. this.valueNode.set("text", this.data.attributeList.join(","));
  1625. }
  1626. }
  1627. }.bind(this)
  1628. });
  1629. },
  1630. saveValue: function(value){
  1631. var oldValue = this.data.attributeList;
  1632. this.data.attributeList = value.split("/,\s*/");
  1633. this.item.explorer.actions.saveCompanyAttribute(this.data, function(json){
  1634. this.data.id = json.data.id;
  1635. this.valueNode.empty();
  1636. this.valueInput = null;
  1637. this.valueNode.set("text", this.data.attributeList.join(","));
  1638. }.bind(this), function(xhr, text, error){
  1639. this.data.attributeList = oldValue;
  1640. this.valueInput.focus();
  1641. var errorText = error;
  1642. if (xhr) errorText = xhr.responseText;
  1643. this.item.explorer.app.notice("request json error: "+errorText, "error");
  1644. }.bind(this));
  1645. },
  1646. loadValue: function(){
  1647. if (this.data.attributeList) this.valueNode.set("text", this.data.attributeList.join(","));
  1648. },
  1649. save: function(name){
  1650. var oldName = this.data.name;
  1651. this.data.name = name;
  1652. this.item.explorer.actions.saveCompanyAttribute(this.data, function(json){
  1653. this.data.id = json.data.id;
  1654. this.nameNode.empty();
  1655. this.input = null;
  1656. this.nameNode.set("text", this.data.name);
  1657. }.bind(this), function(xhr, text, error){
  1658. this.data.name = oldName;
  1659. this.input.focus();
  1660. var errorText = error;
  1661. if (xhr) errorText = xhr.responseText;
  1662. this.item.explorer.app.notice("request json error: "+errorText, "error");
  1663. }.bind(this));
  1664. },
  1665. remove: function(){
  1666. this.item.explorer.actions.deleteCompanyAttribute(this.data.id, function(){
  1667. this.node.destroy();
  1668. delete this;
  1669. }.bind(this));
  1670. }
  1671. });
  1672. MWF.xApplication.Organization.DepartmentAttribute = new Class({
  1673. Extends: MWF.xApplication.Organization.CompanyAttribute,
  1674. saveValue: function(value){
  1675. var oldValue = this.data.attributeList;
  1676. this.data.attributeList = value.split("/,\s*/");
  1677. this.item.explorer.actions.saveDepartmentAttribute(this.data, function(json){
  1678. this.data.id = json.data.id;
  1679. this.valueNode.empty();
  1680. this.valueInput = null;
  1681. this.valueNode.set("text", this.data.attributeList.join(","));
  1682. }.bind(this), function(xhr, text, error){
  1683. this.data.attributeList = oldValue;
  1684. this.valueInput.focus();
  1685. var errorText = error;
  1686. if (xhr) errorText = xhr.responseText;
  1687. this.item.explorer.app.notice("request json error: "+errorText, "error");
  1688. }.bind(this));
  1689. },
  1690. save: function(name){
  1691. var oldName = this.data.name;
  1692. this.data.name = name;
  1693. this.item.explorer.actions.saveDepartmentAttribute(this.data, function(json){
  1694. this.data.id = json.data.id;
  1695. this.nameNode.empty();
  1696. this.input = null;
  1697. this.nameNode.set("text", this.data.name);
  1698. }.bind(this), function(xhr, text, error){
  1699. this.data.name = oldName;
  1700. this.input.focus();
  1701. var errorText = error;
  1702. if (xhr) errorText = xhr.responseText;
  1703. this.item.explorer.app.notice("request json error: "+errorText, "error");
  1704. }.bind(this));
  1705. },
  1706. remove: function(){
  1707. this.item.explorer.actions.deleteDepartmentAttribute(this.data.id, function(){
  1708. this.node.destroy();
  1709. delete this;
  1710. }.bind(this));
  1711. }
  1712. });
  1713. //MWF.xApplication.Organization.Identity = new Class({
  1714. // initialize: function(data, container, explorer, style, canRemove, removeAction){
  1715. // this.container = $(container);
  1716. // this.data = data;
  1717. // this.style = style;
  1718. // this.explorer = explorer;
  1719. // this.canRemove = canRemove || false;
  1720. // this.removeAction = removeAction;
  1721. // this.load();
  1722. // },
  1723. // load: function(){
  1724. // this.node = new Element("div", {
  1725. // "styles": this.style.identityNode,
  1726. // "text": this.data.name
  1727. // }).inject(this.container);
  1728. //
  1729. // if (this.canRemove){
  1730. // this.removeNode = new Element("div", {
  1731. // "styles": this.style.identityRemoveNode
  1732. // }).inject(this.node);
  1733. // if (this.removeAction) this.removeNode.addEvent("click", this.removeAction.bind(this));
  1734. //// var pr = this.node.getStyle("padding-right").toFloat();
  1735. //// pr = pr+this.removeNode.getSize().x;
  1736. //// this.node.setStyle("padding-right", ""+pr+"px");
  1737. // }
  1738. //
  1739. // this.explorer.actions.getPerson(function(person){
  1740. // this.inforNode = new Element("div", {
  1741. // "styles": this.style.identityInforNode
  1742. // });
  1743. // var nameNode = new Element("div", {
  1744. // "styles": this.style.identityInforNameNode
  1745. // }).inject(this.inforNode);
  1746. // var picNode = new Element("div", {
  1747. // "styles": this.style.identityInforPicNode,
  1748. // "html": "<img width='50' height='50' border='0' src='"+"/x_component_Organization/$OrgExplorer/default/icon/head.png'></img>"
  1749. // }).inject(nameNode);
  1750. // var nameTextNode = new Element("div", {
  1751. // "styles": this.style.identityInforNameTextNode,
  1752. // "text": person.data.display
  1753. // }).inject(nameNode);
  1754. //
  1755. // var phoneNode = new Element("div", {
  1756. // "styles": this.style.identityInforPhoneNode,
  1757. // "html": "<div style='width:30px; float:left'>"+this.explorer.app.lp.phone+": </div><div style='width:90px; float:left; margin-left:10px'>"+person.data.mobile+"</div>"
  1758. // }).inject(this.inforNode);
  1759. // var mailNode = new Element("div", {
  1760. // "styles": this.style.identityInforPhoneNode,
  1761. // "html": "<div style='width:30px; float:left'>"+this.explorer.app.lp.mail+": </div><div style='width:90px; float:left; margin-left:10px'>"+person.data.mail+"</div>"
  1762. // }).inject(this.inforNode);
  1763. //
  1764. //
  1765. // new mBox.Tooltip({
  1766. // content: this.inforNode,
  1767. // setStyles: {content: {padding: 15, lineHeight: 20}},
  1768. // attach: this.node,
  1769. // transition: 'flyin'
  1770. // });
  1771. //
  1772. // }.bind(this), null, this.data.person);
  1773. //
  1774. //
  1775. // this.node.addEvents({
  1776. // "mouseover": function(){
  1777. // this.node.setStyles(this.style.identityNode_over);
  1778. // // this.showPersonInfor();
  1779. // }.bind(this),
  1780. // "mouseout": function(){
  1781. // this.node.setStyles(this.style.identityNode);
  1782. // // this.hidePersonInfor();
  1783. // }.bind(this)
  1784. // });
  1785. // }
  1786. //});