$Explorer.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. MWF.require("MWF.widget.Tab", null, false);
  2. MWF.xDesktop.requireApp("Org", "List", null, false);
  3. MWF.xApplication.Org.$Explorer = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default"
  8. },
  9. _loadPath: function(){
  10. this.path = "../x_component_Org/$Explorer/";
  11. this.cssPath = "../x_component_Org/$Explorer/"+this.options.style+"/css.wcss";
  12. },
  13. initialize: function(node, actions, options){
  14. this.setOptions(options);
  15. this._loadPath();
  16. this._loadCss();
  17. this.actions = actions;
  18. this.node = $(node);
  19. this.loaddingElement = false;
  20. this.elements = [];
  21. this.isElementLoaded = false;
  22. this.loadElementQueue = 0;
  23. this.deleteElements = [];
  24. },
  25. _loadLp: function(){
  26. this.options.lp = {
  27. "elementLoaded": this.app.lp.personLoaded,
  28. "search": this.app.lp.search,
  29. "searchText": this.app.lp.searchText,
  30. "elementSave": this.app.lp.personSave,
  31. "deleteElements": this.app.lp.deletePersons,
  32. "deleteElementsCancel": this.app.lp.deleteElementsCancel,
  33. "deleteElementsTitle": this.app.lp.deletePersonsTitle,
  34. "deleteElementsConfirm": this.app.lp.deletePersonsConfirm,
  35. "elementBaseText": this.app.lp.personBaseText,
  36. "elementName": this.app.lp.personName,
  37. "noSignature": this.app.lp.noSignature,
  38. "edit": this.app.lp.edit,
  39. "cancel": this.app.lp.cancel,
  40. "save": this.app.lp.save,
  41. "add": this.app.lp.add
  42. }
  43. },
  44. clear: function(){
  45. this.loaddingElement = false;
  46. this.isElementLoaded = false;
  47. this.loadElementQueue = 0;
  48. this.listNode.empty();
  49. },
  50. load: function(){
  51. this._loadLp();
  52. this.loadLayout();
  53. this.loadList();
  54. },
  55. loadLayout: function(){
  56. this.listAreaNode = new Element("div", {"styles": this.css.listAreaNode}).inject(this.node);
  57. this.propertyAreaNode = new Element("div", {"styles": this.css.propertyAreaNode}).inject(this.node);
  58. this.resizeBarNode = new Element("div", {"styles": this.css.resizeBarNode}).inject(this.propertyAreaNode);
  59. this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.propertyAreaNode);
  60. this.propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  61. this.propertyContentNode = new Element("div", {"styles": this.css.propertyContentNode}).inject(this.propertyNode);
  62. this.propertyContentNode.setStyle("-webkit-user-select", "text");
  63. this.node.addEvent("selectstart", function(e){
  64. this.propertyContentNode.setStyle("-webkit-user-select", "text");
  65. }.bind(this));
  66. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode}).inject(this.listAreaNode);
  67. this.listScrollNode = new Element("div", {"styles": this.css.listScrollNode}).inject(this.listAreaNode);
  68. this.listNode = new Element("div", {"styles": this.css.listNode}).inject(this.listScrollNode);
  69. this.loadToolbar();
  70. this.resizePropertyContentNodeFun = this.resizePropertyContentNode.bind(this);
  71. this.resizePropertyContentNodeFun();
  72. this.app.addEvent("resize", this.resizePropertyContentNodeFun);
  73. this.loadScroll();
  74. this.loadResize();
  75. },
  76. loadToolbar: function(){
  77. if (this._isActionManager()) {
  78. this.isEditor = true;
  79. this.addTopElementNode = new Element("div", {"styles": this.css.addTopGroupNode}).inject(this.toolbarNode);
  80. this.addTopElementNode.addEvent("click", function () {
  81. this.addTopElement();
  82. }.bind(this));
  83. }
  84. this.createSearchNode();
  85. this.loadPingyinArea();
  86. },
  87. loadPingyinArea: function(){
  88. this.pingyinAction = new Element("div", {"styles": this.css.pingyinAction}).inject(this.app.pingyinArea);
  89. this.pingyinAction.addEvent("click", function(e){
  90. if (!this.pingyinNode) this.createPingyinNode();
  91. if (this.pingyinMorph){
  92. if (!this.pingyinMorph.isRunning()){
  93. if (this.pingyinNode.getStyle("display")==="none"){
  94. this.showPingyin();
  95. }else{
  96. this.hidePingyin();
  97. }
  98. }
  99. }else{
  100. this.showPingyin();
  101. }
  102. }.bind(this));
  103. this.pingyinAction.addEvent("mousedown", function(e){e.stopPropagation();});
  104. this.hidePingyinFun = this.hidePingyin.bind(this);
  105. this.app.content.addEvent("mousedown", this.hidePingyinFun);
  106. this.removePingyinFun = this.removePingyin.bind(this);
  107. this.app.addEvent("queryClose", this.removePingyinFun);
  108. },
  109. removePingyin: function(){
  110. this.app.content.removeEvent("mousedown", this.hidePingyinFun);
  111. },
  112. hidePingyin: function(){
  113. if (this.pingyinNode){
  114. if (!this.pingyinMorph){
  115. this.pingyinMorph = new Fx.Morph(this.pingyinNode, {duration: 50, link: "chain"});
  116. }
  117. if (!this.pingyinMorph.isRunning()){
  118. if (this.pingyinNode.getStyle("display")!=="none"){
  119. this.pingyinMorph.start(this.css.pingyinNode).chain(function(){
  120. this.pingyinNode.setStyle("display", "none");
  121. }.bind(this));
  122. }
  123. }
  124. }
  125. },
  126. showPingyin: function(){
  127. this.resizePropertyContentNode();
  128. if (!this.pingyinMorph){
  129. this.pingyinMorph = new Fx.Morph(this.pingyinNode, {duration: 50, link: "chain"});
  130. }
  131. this.pingyinNode.setStyle("display", "block");
  132. this.pingyinMorph.start(this.css.pingyinNode_to).chain(function(){
  133. this.pingyinNode.setStyles(this.css.pingyinNode_to);
  134. }.bind(this));
  135. },
  136. setPingyinNodePosition: function(){
  137. this.pingyinNode.position({
  138. relativeTo: this.node,
  139. position: "leftTop",
  140. edge: "leftTop"
  141. });
  142. },
  143. createPingyinNode: function(){
  144. this.pingyinNode = new Element("div", {"styles": this.css.pingyinNode}).inject(this.node);
  145. this.pingyinNode.addEvent("mousedown", function(e){e.stopPropagation();});
  146. letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
  147. letters.each(function(l){
  148. var letterNode = new Element("div", {"styles": this.css.letterNode,"text": l}).inject(this.pingyinNode);
  149. letterNode.addEvents({
  150. "mouseover": function(e){
  151. e.target.setStyles(this.css.letterNode_over);
  152. }.bind(this),
  153. "mouseout": function(e){
  154. e.target.setStyles(this.css.letterNode);
  155. }.bind(this),
  156. "click": function(e){
  157. this.searchInputNode.set("value", e.target.get("text"));
  158. this.searchOrg();
  159. this.hidePingyin();
  160. }.bind(this)
  161. });
  162. }.bind(this));
  163. },
  164. addTopElement: function(){
  165. var isNewElement = true;
  166. if (this.currentItem) isNewElement = this.currentItem.unSelected();
  167. if (isNewElement){
  168. var newElementData = this._getAddElementData();
  169. var item = this._newElement(newElementData, this);
  170. item.load();
  171. item.selected();
  172. item.editBaseInfor();
  173. (new Fx.Scroll(this.listScrollNode)).toElementCenter(item.node);
  174. }else{
  175. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  176. }
  177. },
  178. createSearchNode: function(){
  179. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.toolbarNode);
  180. this.searchButtonNode = new Element("div", {"styles": this.css.searchButtonNode,"title": this.options.lp.search}).inject(this.searchNode);
  181. this.searchButtonNode.addEvent("click", function(){this.searchOrg();}.bind(this));
  182. this.searchInputAreaNode = new Element("div", {"styles": this.css.searchInputAreaNode}).inject(this.searchNode);
  183. this.searchInputNode = new Element("input", {
  184. "type": "text",
  185. "value": this.options.lp.searchText,
  186. "styles": this.css.searchInputNode,
  187. //"x-webkit-speech": "1",
  188. "x-webkit-speech": "x-webkit-speech"
  189. }).inject(this.searchInputAreaNode);
  190. var _self = this;
  191. this.searchInputNode.addEvents({
  192. "focus": function(){if (this.value ===_self.options.lp.searchText) this.set("value", "");},
  193. "blur": function(){if (!this.value) this.set("value", _self.options.lp.searchText);},
  194. "keydown": function(e){
  195. if (e.code===13){
  196. this.searchOrg();
  197. e.preventDefault();
  198. }
  199. }.bind(this),
  200. "selectstart": function(e){e.preventDefault();},
  201. "change": function(){
  202. var key = this.searchInputNode.get("value");
  203. if (!key || key===this.options.lp.searchText) {
  204. if (this.currentItem){
  205. if (this.currentItem.unSelected()){
  206. this.clear();
  207. this.loadElements();
  208. }else{
  209. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  210. }
  211. }
  212. }
  213. }.bind(this)
  214. });
  215. // this.searchButtonNode.addEvent("click", function(){this.searchOrg();}.bind(this));
  216. },
  217. searchOrg: function(){
  218. debugger;
  219. var key = this.searchInputNode.get("value");
  220. var isSearchElement = true;
  221. this.searching = false;
  222. if (key){
  223. if (key!==this.options.lp.searchText){
  224. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  225. if (isSearchElement){
  226. this._listElementByKey(function(json){
  227. if (this.currentItem) this.currentItem.unSelected();
  228. this.clear();
  229. json.data.each(function(itemData){
  230. var item = this._newElement(itemData, this);
  231. item.load();
  232. }.bind(this));
  233. this.searching = true;
  234. }.bind(this), null, key);
  235. }else{
  236. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  237. }
  238. }else{
  239. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  240. if (isSearchElement){
  241. this.clear();
  242. this.reloadElements();
  243. }else{
  244. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  245. }
  246. }
  247. }else{
  248. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  249. if (isSearchElement){
  250. this.clear();
  251. this.reloadElements();
  252. }else{
  253. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  254. }
  255. }
  256. },
  257. resizePropertyContentNode: function(){
  258. var size = this.node.getSize();
  259. var tSize = this.propertyTitleNode.getSize();
  260. var mtt = this.propertyTitleNode.getStyle("margin-top").toFloat();
  261. var mbt = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  262. var mtc = this.propertyContentNode.getStyle("margin-top").toFloat();
  263. var mbc = this.propertyContentNode.getStyle("margin-bottom").toFloat();
  264. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  265. this.propertyContentNode.setStyle("height", height);
  266. tSize = this.toolbarNode.getSize();
  267. mtt = this.toolbarNode.getStyle("margin-top").toFloat();
  268. mbt = this.toolbarNode.getStyle("margin-bottom").toFloat();
  269. mtc = this.toolbarNode.getStyle("margin-top").toFloat();
  270. mbc = this.toolbarNode.getStyle("margin-bottom").toFloat();
  271. height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  272. this.listScrollNode.setStyle("height", ""+height+"px");
  273. if (this.pingyinNode){
  274. this.setPingyinNodePosition();
  275. this.pingyinNode.setStyle("height", ""+size.y+"px");
  276. }
  277. },
  278. loadScroll: function(){
  279. MWF.require("MWF.widget.ScrollBar", function(){
  280. var _self = this;
  281. new MWF.widget.ScrollBar(this.listScrollNode, {
  282. "style":"xApp_Organization_Explorer",
  283. "where": "before",
  284. "distance": 100,
  285. "friction": 4,
  286. "axis": {"x": false, "y": true},
  287. "onScroll": function(y){
  288. if( _self.searching )return;
  289. var scrollSize = _self.listScrollNode.getScrollSize();
  290. var clientSize = _self.listScrollNode.getSize();
  291. var scrollHeight = scrollSize.y-clientSize.y;
  292. if (y+200>scrollHeight) {
  293. if (!_self.isElementLoaded) _self.loadElements();
  294. }
  295. }
  296. });
  297. // new MWF.widget.ScrollBar(this.propertyContentNode, {
  298. // "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  299. // });
  300. }.bind(this));
  301. },
  302. loadResize: function(){
  303. this.propertyResize = new Drag(this.resizeBarNode,{
  304. "snap": 1,
  305. "onStart": function(el, e){
  306. var x = e.event.clientX;
  307. var y = e.event.clientY;
  308. el.store("position", {"x": x, "y": y});
  309. var size = this.listAreaNode.getSize();
  310. el.store("initialWidth", size.x);
  311. }.bind(this),
  312. "onDrag": function(el, e){
  313. var x = e.event.clientX;
  314. // var y = e.event.y;
  315. var bodySize = this.node.getSize();
  316. var position = el.retrieve("position");
  317. var initialWidth = el.retrieve("initialWidth").toFloat();
  318. var dx = position.x.toFloat()-x.toFloat();
  319. var width = initialWidth-dx;
  320. if (width> bodySize.x/1.5) width = bodySize.x/1.5;
  321. if (width<300) width = 300;
  322. this.listAreaNode.setStyle("width", width+1);
  323. this.propertyAreaNode.setStyle("margin-left", width);
  324. }.bind(this)
  325. });
  326. },
  327. getPageNodeCount: function(){
  328. var size = this.listScrollNode.getSize();
  329. return (size.y / 50).toInt() + 5;
  330. },
  331. loadList: function(){
  332. this.loadElements();
  333. this.continueLoadFun = this.continueLoad.bind(this);
  334. this.app.addEvent("resize", this.continueLoadFun);
  335. },
  336. continueLoad: function(){
  337. if (this.elements.length<this.getPageNodeCount()){
  338. this.loadElements(true);
  339. }
  340. },
  341. reloadElements : function(){
  342. this.elements = [];
  343. this.clear();
  344. this.loadElements();
  345. },
  346. loadElements: function(addToNext){
  347. if (!this.isElementLoaded){
  348. if (!this.loaddingElement){
  349. this.loaddingElement = true;
  350. var count = this.getPageNodeCount();
  351. this._listElementNext(this.getLastLoadedElementId(), count, function(json){
  352. if (json.data.length){
  353. this.loadListContent(json.data);
  354. this.loaddingElement = false;
  355. if (json.data.length<count){
  356. this.isElementLoaded = true;
  357. this.app.notice(this.options.lp.elementLoaded, "ok", this.listScrollNode, {"x": "center", "y": "bottom"});
  358. }else{
  359. if (this.loadElementQueue>0){
  360. this.loadElementQueue--;
  361. this.loadElements();
  362. }
  363. }
  364. }else{
  365. if (!this.elements.length){
  366. //this.setNoGroupNoticeArea();
  367. }else{
  368. this.app.notice(this.options.lp.elementLoaded, "ok", this.listScrollNode, {"x": "center", "y": "bottom"});
  369. }
  370. this.isElementLoaded = true;
  371. this.loaddingElement = false;
  372. }
  373. }.bind(this));
  374. }else{
  375. if (addToNext) this.loadElementQueue++;
  376. }
  377. }
  378. },
  379. getLastLoadedElementId: function(){
  380. return (this.elements.length) ? this.elements[this.elements.length-1].data.id : "";
  381. },
  382. loadListContent: function(data){
  383. data.each(function(itemData, i){
  384. var item = this._newElement(itemData, this, i);
  385. this.elements.push(item);
  386. item.load();
  387. if (this.elements.length===1) item.selected();
  388. }.bind(this));
  389. },
  390. setNoElementNoticeArea: function(){
  391. //没有数据时的提示
  392. },
  393. checkDeleteElements: function(item){
  394. if (this.deleteElements.length){
  395. if (!this.deleteElementsNode){
  396. this.deleteElementsNode = new Element("div", {"styles": this.css.deleteElementsNode}).inject(this.node);
  397. this.deleteElementsDeleteNode = new Element("div", {"styles": this.css.deleteElementsDeleteNode,"text": this.options.lp.deleteElements}).inject(this.deleteElementsNode);
  398. this.deleteElementsCancelNode = new Element("div", {"styles": this.css.deleteElementsCancelNode,"text": this.options.lp.deleteElementsCancel}).inject(this.deleteElementsNode);
  399. this.deleteElementsDeleteNode.addEvent("click", function(e){this.deleteSelectedElements(e);}.bind(this));
  400. this.deleteElementsCancelNode.addEvent("click", function(e){this.deleteSelectedElementsCancel(e);}.bind(this));
  401. }
  402. this.deleteElementsNode.position({
  403. relativeTo: (item) ? item.node : this.toolbarNode,
  404. position: "topRight",
  405. edge: "topLeft"
  406. });
  407. }else{
  408. if (this.deleteElementsNode){
  409. this.deleteElementsNode.destroy();
  410. this.deleteElementsNode = null;
  411. delete this.deleteElementsNode;
  412. }
  413. }
  414. },
  415. deleteSelectedElements: function(e){
  416. var _self = this;
  417. this.app.confirm("infor", e, this.options.lp.deleteElementsTitle, this.options.lp.deleteElementsConfirm, 300, 120, function(){
  418. var deleted = [];
  419. var doCount = 0;
  420. var readyCount = _self.deleteElements.length;
  421. var errorText = "";
  422. var complete;
  423. complete = function () {
  424. if (doCount === readyCount) {
  425. if (errorText) {
  426. _self.app.notice(errorText, "error", _self.propertyContentNode, {x: "left", y: "top"});
  427. }
  428. }
  429. };
  430. _self.deleteElements.each(function(element){
  431. element["delete"](function(){
  432. deleted.push(element);
  433. doCount++;
  434. if (_self.deleteElements.length===doCount){
  435. _self.deleteElements = _self.deleteElements.filter(function (item) {
  436. return !deleted.contains(item);
  437. });
  438. _self.checkDeleteElements();
  439. }
  440. complete();
  441. }, function(error){
  442. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  443. doCount++;
  444. if (_self.deleteElements.length !== doCount) {
  445. } else {
  446. _self.deleteElements = _self.deleteElements.filter(function (item) {
  447. return !deleted.contains(item);
  448. });
  449. _self.checkDeleteElements();
  450. }
  451. complete();
  452. });
  453. });
  454. this.close();
  455. }, function(){
  456. this.close();
  457. });
  458. },
  459. deleteSelectedElementsCancel: function() {
  460. while (this.deleteElements.length){
  461. var element = this.deleteElements[0];
  462. element.setUndelete();
  463. //if (element.deleteNode) element.deleteNode.click();
  464. if (this.currentItem!==element){
  465. element.contentNode.setStyles(element.style.contentNode);
  466. if (element.data.id) element.actionNode.fade("out");
  467. }
  468. }
  469. this.checkDeleteElements();
  470. },
  471. destroy: function(){
  472. if (this.hidePingyinFun) this.app.content.removeEvent("mousedown", this.hidePingyinFun);
  473. if (this.resizePropertyContentNodeFun) this.app.removeEvent("resize", this.resizePropertyContentNodeFun);
  474. if (this.continueLoadFun) this.app.removeEvent("resize", this.continueLoadFun);
  475. if (this.removePingyinFun) this.app.removeEvent("queryClose", this.removePingyinFun);
  476. MWF.release(this);
  477. },
  478. _isActionManager: function(){
  479. return MWF.AC.isOrganizationManager();
  480. },
  481. _listElementNext: function(lastid, count, callback){
  482. this.actions.listPersonNext(lastid, count, function(json){
  483. if (callback) {
  484. callback.apply(this, [json]);
  485. }
  486. }.bind(this));
  487. },
  488. _newElement: function(data, explorer, i){
  489. return new MWF.xApplication.Org.PersonExplorer.Person(data, explorer, this.isEditor, i);
  490. },
  491. _listElementByKey: function(callback, failure, key){
  492. this.actions.listPersonByKey(function(json){
  493. if (callback) {
  494. callback.apply(this, [json]);
  495. }
  496. }.bind(this), failure, key);
  497. },
  498. _getAddElementData: function(){
  499. return {
  500. "employee": "",
  501. "password": "",
  502. "display": "",
  503. "qq": "",
  504. "mail": "",
  505. "weixin": "",
  506. "weibo": "",
  507. "mobile": "",
  508. "name": "",
  509. "controllerList": []
  510. };
  511. },
  512. getContentStyle: function(contentNode, node){
  513. var position = this.propertyContentNode.getPosition(this.propertyContentNode.getOffsetParent());
  514. var size = this.propertyContentNode.getSize();
  515. contentNode.position({"relativeTo": node,"position": "upperLeft","edge": "upperLeft"});
  516. return {
  517. "top": ""+position.y+"px",
  518. "left": ""+position.x+"px",
  519. "height": ""+size.y+"px",
  520. "width": ""+size.x+"px"
  521. };
  522. },
  523. openPerson: function(data, node){
  524. this.openContent("PersonExplorer", "PersonContent", data, node);
  525. },
  526. openGroup: function(data, node){
  527. this.openContent("GroupExplorer", "GroupContent", data, node);
  528. },
  529. openUnit: function(data, node){
  530. this.openContent("UnitExplorer", "UnitContent", data, node);
  531. },
  532. openRole: function(data, node){
  533. this.openContent("RoleExplorer", "RoleContent", data, node);
  534. },
  535. openContent: function(explorerClazz, contentClazz, data, node){
  536. MWF.xDesktop.requireApp("Org", explorerClazz, function(){
  537. var contentNode = new Element("div", {"styles": this.css.popContentNode}).inject(this.propertyContentNode, "top");
  538. var to = this.getContentStyle(contentNode, node);
  539. var resize = true;
  540. new Fx.Morph(contentNode, {
  541. "duration": 300,
  542. "transition": Fx.Transitions.Expo.easeOut
  543. }).start(to).chain(function(){
  544. content.setContentSize();
  545. resize = false;
  546. contentNode.setStyles({"position": "static","width": "100%","height": "100%"});
  547. }.bind(this));
  548. var item = {
  549. "explorer": this,
  550. "style": this.css.item,
  551. "data": data,
  552. "isEdit": false,
  553. "refresh": function(){},
  554. "propertyContentNode": contentNode
  555. };
  556. var content = new MWF.xApplication.Org[explorerClazz][contentClazz](item, true);
  557. var timeoutResize = function(){
  558. content.setContentSize();
  559. if (resize)window.setTimeout(function(){timeoutResize();}, 30);
  560. };
  561. window.setTimeout(function(){timeoutResize();}, 30);
  562. }.bind(this));
  563. }
  564. });
  565. MWF.xApplication.Org.$Explorer.Item = new Class({
  566. //Extends: MWF.xApplication.Organization.GroupExplorer.Group,
  567. initialize: function(data, explorer, isEditor, i){
  568. this.i = i;
  569. this.data = data;
  570. this.explorer = explorer;
  571. this.listNode = this.explorer.listNode;
  572. this.propertyContentNode = this.explorer.propertyContentNode;
  573. this.initStyle();
  574. this.selectedAttributes = [];
  575. this.isEdit = false;
  576. this.isEditor = isEditor;
  577. this.deleteSelected = false;
  578. },
  579. initStyle: function(){
  580. this.style = this.explorer.css.item;
  581. },
  582. refresh: function(){
  583. this.iconNode.getElement("img").set("src", this._getIcon());
  584. this._loadTextNode();
  585. if (this.content){
  586. if (this.content.titleInfor) this.content.titleInfor.refresh();
  587. if (this.content.bottomInfor) this.content.bottomInfor.refresh();
  588. }
  589. this.addActions();
  590. },
  591. load: function(){
  592. this.node = new Element("div", {"styles": this.style.node}).inject(this.listNode);
  593. // if (this.i<10){
  594. // var r = (59+((255-59)*this.i)/10).toInt();
  595. // var g = (118+((255-118)*this.i)/10).toInt();
  596. // var b = (182+((255-182)*this.i)/10).toInt();
  597. // this.node.setStyle("background-color", "rgb("+r+","+g+","+b+")");
  598. // }
  599. this.contentNode = new Element("div", {"styles": this.style.contentNode}).inject(this.node);
  600. this.iconNode = new Element("div", {"styles": this.style.iconNode}).inject(this.contentNode);
  601. var src = this._getIcon();
  602. var img = new Element("img", {
  603. "styles": this.style.iconImgNode,
  604. "src": src
  605. }).inject(this.iconNode);
  606. this.actionNode = new Element("div", {"styles": this.style.actionNode}).inject(this.contentNode);
  607. this.textNode = new Element("div", {"styles": this.style.textNode}).inject(this.contentNode);
  608. this._loadTextNode();
  609. this.setNewItem();
  610. this.node.inject(this.listNode);
  611. this.addActions();
  612. this.setEvent();
  613. },
  614. setNewItem: function(){
  615. if (!this.created){
  616. if (!this.data.id){
  617. this.created = false;
  618. this.contentNode.setStyles(this.style.contentNodeNew);
  619. }else {
  620. this.created = true;
  621. this.contentNode.setStyles(this.style.contentNode);
  622. }
  623. }
  624. },
  625. addActions: function(){
  626. if (this.isEditor){
  627. if (this.data.id){
  628. if (this.data.control.allowDelete){
  629. if (!this.deleteNode){
  630. this.deleteNode = new Element("div.o2icon-delete", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  631. this.deleteNode.addEvent("click", function(e){
  632. if (!this.notDelete){
  633. if (!this.deleteSelected){
  634. this.setDelete();
  635. }else{
  636. this.setUndelete();
  637. }
  638. }
  639. e.stopPropagation();
  640. }.bind(this));
  641. if (this.explorer.currentItem===this){
  642. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  643. }
  644. }
  645. }
  646. }
  647. }
  648. },
  649. setDelete: function(){
  650. this.actionNode.fade("in");
  651. this.deleteNode.setStyles(this.style.actionDeleteNode_delete);
  652. this.deleteNode.removeClass("o2icon-delete").addClass("o2icon-off");
  653. this.contentNode.setStyles(this.style.contentNode_delete);
  654. this.contentNode.removeClass("mainColor_bg");
  655. this.textNode.setStyles(this.style.textNode);
  656. this.explorer.deleteElements.push(this);
  657. this.deleteSelected = true;
  658. this.contentNode.removeClass("mainColor_bg");
  659. this.contentNode.removeClass("mainColor_bg_opacity");
  660. this.explorer.checkDeleteElements(this);
  661. },
  662. setUndelete: function(){
  663. this.actionNode.fade("out");
  664. if (this.explorer.currentItem!==this){
  665. this.deleteNode.setStyles(this.style.actionDeleteNode);
  666. this.contentNode.setStyles(this.style.contentNode);
  667. this.contentNode.removeClass("mainColor_bg");
  668. this.textNode.setStyles(this.style.textNode);
  669. }else{
  670. this.contentNode.setStyles(this.style.contentNode_selected);
  671. this.contentNode.addClass("mainColor_bg");
  672. this.textNode.setStyles(this.style.textNode_selected);
  673. this.actionNode.setStyles(this.style.actionNode_selected);
  674. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  675. }
  676. this.deleteNode.removeClass("o2icon-off" ).addClass("o2icon-delete");
  677. this.explorer.deleteElements.erase(this);
  678. this.deleteSelected = false;
  679. this.explorer.checkDeleteElements(this);
  680. },
  681. setEvent: function(){
  682. this.contentNode.addEvents({
  683. "mouseover": function(e){
  684. if (this.explorer.currentItem!==this && !this.deleteSelected){
  685. this.contentNode.setStyles(this.style.nodeOver);
  686. this.contentNode.addClass("mainColor_bg_opacity");
  687. if (!this.deleteSelected) if (this.data.id) this.actionNode.fade("in");
  688. if (this.deleteNode)this.deleteNode.addClass("mainColor_color");
  689. if (this.addNode)this.addNode.addClass("mainColor_color");
  690. }
  691. }.bind(this),
  692. "mouseout": function(e){
  693. if (this.explorer.currentItem!==this && !this.deleteSelected){
  694. this.contentNode.setStyles(this.style.contentNode);
  695. this.contentNode.removeClass("mainColor_bg_opacity");
  696. if (!this.deleteSelected) if (this.data.id) this.actionNode.fade("out");
  697. // if (this.deleteNode)this.deleteNode.removeClass("mainColor_color");
  698. // if (this.addNode)this.addNode.removeClass("mainColor_color");
  699. }
  700. }.bind(this),
  701. "click": function(e){
  702. if (!this.deleteSelected){
  703. if (this.explorer.currentItem){
  704. if (this.explorer.currentItem.unSelected()){
  705. this.selected();
  706. }else{
  707. this.explorer.app.notice(this.explorer.options.lp.elementSave, "error", this.propertyContentNode);
  708. }
  709. }else{
  710. this.selected();
  711. }
  712. }
  713. }.bind(this)
  714. });
  715. },
  716. unSelected: function(){
  717. if (this.content.baseInfor.mode==="edit") return false;
  718. if (!this.deleteSelected){
  719. this.explorer.currentItem = null;
  720. this.contentNode.setStyles(this.style.contentNode);
  721. this.textNode.setStyles(this.style.textNode);
  722. this.actionNode.setStyles(this.style.actionNode);
  723. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode);
  724. this.contentNode.removeClass("mainColor_bg_opacity");
  725. this.contentNode.removeClass("mainColor_bg");
  726. if (this.deleteNode)this.deleteNode.removeClass("mainColor_color");
  727. if (this.addNode)this.addNode.removeClass("mainColor_color");
  728. }
  729. this.clearItemProperty();
  730. return true;
  731. },
  732. clearItemProperty: function(){
  733. this.explorer.propertyTitleNode.empty();
  734. if (this.content) this.content.destroy();
  735. this.explorer.propertyContentNode.empty();
  736. },
  737. selected: function(){
  738. debugger;
  739. this.explorer.currentItem = this;
  740. this.contentNode.setStyles(this.style.contentNode_selected);
  741. this.textNode.setStyles(this.style.textNode_selected);
  742. this.actionNode.setStyles(this.style.actionNode_selected);
  743. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  744. this.contentNode.removeClass("mainColor_bg_opacity");
  745. this.contentNode.addClass("mainColor_bg");
  746. if (this.deleteNode)this.deleteNode.removeClass("mainColor_color");
  747. if (this.addNode)this.addNode.removeClass("mainColor_color");
  748. this.showItemProperty();
  749. },
  750. editBaseInfor: function(){
  751. this.content.edit();
  752. },
  753. showItemProperty: function(){
  754. this.content = new MWF.xApplication.Org.PersonExplorer.PersonContent(this);
  755. },
  756. destroy: function(){
  757. if (this.explorer.currentItem===this){
  758. this.explorer.currentItem = null;
  759. this.clearItemProperty();
  760. }
  761. this.node.destroy();
  762. delete this;
  763. },
  764. "delete": function(success, failure){
  765. this.explorer.actions.deletePerson(this.data.id, function(){
  766. this.destroy();
  767. if (success) success();
  768. }.bind(this), function(xhr, text, error){
  769. var errorText = error;
  770. if (xhr) errorText = xhr.responseText;
  771. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  772. if (failure) failure();
  773. });
  774. },
  775. _loadTextNode: function(){
  776. this.textNode.set({"text": this.data.name});
  777. },
  778. _getIcon: function(nocache){
  779. var url = (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "../x_component_Org/$Explorer/default/icon/man.png";
  780. return (nocache) ? url+"?"+(new Date().getTime()) : url;
  781. //return (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "../x_component_Org/$Explorer/default/icon/man.png";
  782. // var src = "data:image/png;base64,"+this.data.icon;
  783. // if (!this.data.icon){
  784. // if (this.data.genderType==="f"){
  785. // src = "../x_component_Org/$Explorer/default/icon/female24.png"
  786. // }else{
  787. // src = "../x_component_Org/$Explorer/default/icon/man24.png"
  788. // }
  789. // }
  790. // return src;
  791. }
  792. });
  793. MWF.xApplication.Org.$Explorer.ItemContent = new Class({
  794. initialize: function (item, isClose) {
  795. this.item = item;
  796. this.isClose = isClose;
  797. this.explorer = this.item.explorer;
  798. this.contentNode = this.item.propertyContentNode;
  799. this.style = this.item.style.person;
  800. this.load();
  801. },
  802. _getData: function(callback){
  803. this.data = this.item.data;
  804. if (callback) callback();
  805. },
  806. load: function(){
  807. this.titleContentNode = new Element("div").inject(this.contentNode);
  808. this.propertyContentScrollNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.contentNode);
  809. this.propertyContentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyContentScrollNode);
  810. this.bottomContentNode = new Element("div").inject(this.contentNode);
  811. this._getData(function(){
  812. this.explorer.propertyTitleNode.set("text", this.data.name);
  813. this._showItemPropertyTitle();
  814. this.loadItemPropertyTab(function(){
  815. this._loadTabs();
  816. this._loadContent();
  817. if (this.propertyTab.pages.length) this.propertyTab.pages[0].showTabIm();
  818. }.bind(this));
  819. this._showItemPropertyBottom();
  820. this.setContentSizeFun = this.setContentSize.bind(this);
  821. this.setContentSize();
  822. this.explorer.app.addEvent("resize", this.setContentSizeFun);
  823. new MWF.widget.ScrollBar(this.propertyContentScrollNode, {
  824. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  825. });
  826. }.bind(this));
  827. //this.showItemPropertyTitle();
  828. },
  829. setContentSize: function(){
  830. var size = this.contentNode.getSize();
  831. var titleSize = this.titleContentNode.getSize();
  832. var bottomSize = this.bottomContentNode.getSize();
  833. var y = size.y-titleSize.y-bottomSize.y;
  834. this.propertyContentScrollNode.setStyle("height", ""+y+"px")
  835. },
  836. loadItemPropertyTab: function(callback){
  837. this.propertyTabContainerNode = new Element("div", {"styles": this.item.style.tabTitleNode}).inject(this.propertyContentNode, "top");
  838. MWF.require("MWF.widget.Tab", function(){
  839. this.propertyTab = new MWF.widget.Tab(this.propertyContentNode, {"style": "org", "useMainColor":true});
  840. this.propertyTab.load();
  841. this.propertyTab.tabNodeContainer.inject(this.propertyTabContainerNode);
  842. if (callback) callback();
  843. }.bind(this));
  844. },
  845. edit: function(){
  846. if (this.baseInfor) this.baseInfor.edit();
  847. },
  848. destroy: function(){
  849. if (this.setContentSizeFun) this.explorer.app.removeEvent("resize", this.setContentSizeFun);
  850. if (this.titleInfor) this.titleInfor.destroy();
  851. if (this.bottomInfor) this.bottomInfor.destroy();
  852. if (this.baseInfor) this.baseInfor.destroy();
  853. this.contentNode.empty();
  854. MWF.release(this);
  855. },
  856. _showItemPropertyTitle: function(){
  857. this.titleInfor = new MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor(this);
  858. },
  859. _showItemPropertyBottom: function(){
  860. this.bottomInfor = new MWF.xApplication.Org.$Explorer.ItemContent.BottmInfor(this);
  861. },
  862. _loadTabs: function(){},
  863. _loadContent: function(){}
  864. });
  865. MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor = new Class({
  866. initialize: function (content) {
  867. this.content = content;
  868. this.item = content.item;
  869. this.data = this.content.data;
  870. this.explorer = this.item.explorer;
  871. this.contentNode = this.content.titleContentNode;
  872. this.style = this._getStyle();
  873. this.load();
  874. },
  875. _getStyle: function(){
  876. return this.item.style.person;
  877. },
  878. load: function(){
  879. this.titleBgNode = new Element("div", {"styles": this.style.titleBgNode}).inject(this.contentNode);
  880. this.titleNode = new Element("div", {"styles": this.style.titleNode}).inject(this.titleBgNode);
  881. this.setBackground();
  882. this.titleInforNode = new Element("div#titleInfor", {"styles": this.style.titleInforNode}).inject(this.titleNode);
  883. this.titleInforLeftNode = new Element("div", {"styles": this.style.titleInforLeftNode}).inject(this.titleInforNode);
  884. this.titleInforRightNode = new Element("div", {"styles": this.style.titleInforRightNode}).inject(this.titleInforNode);
  885. this.loadLeftInfor();
  886. this.loadRightInfor();
  887. this.loadAction();
  888. if (this.content.isClose) this.createCloseNode();
  889. },
  890. createCloseNode: function(){
  891. this.closeNode = new Element("div", {"styles": this.style.titleCloseNode}).inject(this.titleBgNode);
  892. this.closeNode.addEvents({
  893. "mousedown": function(){this.closeNode.setStyles(this.style.titleCloseNode_down)}.bind(this),
  894. "mouseup": function(){this.closeNode.setStyles(this.style.titleCloseNode)}.bind(this),
  895. "click": function(){
  896. var node = this.content.contentNode;
  897. this.content.destroy();
  898. node.destroy();
  899. node = null;
  900. }.bind(this)
  901. });
  902. },
  903. setBackground: function(){
  904. this.titleBgNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/person_bg_bg.png)");
  905. this.titleNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/person_bg.png)");
  906. },
  907. loadLeftInfor: function(){
  908. if (!this.iconAreaNode) this.iconAreaNode = new Element("div", {"styles": this.style.titleInforIconAreaNode}).inject(this.titleInforLeftNode);
  909. if (!this.iconNode) this.iconNode = new Element("img", {"styles": this.style.titleInforIconNode}).inject(this.iconAreaNode);
  910. this.iconNode.set("src", this._getIcon());
  911. },
  912. _getIcon: function(nocache){
  913. var url = (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "../x_component_Org/$Explorer/default/icon/man.png";
  914. return (nocache) ? url+"?"+(new Date().getTime()) : url;
  915. // var src = "data:image/png;base64,"+this.data.icon;
  916. // if (!this.data.icon){
  917. // if (this.data.genderType==="f"){
  918. // src = "../x_component_Org/$Explorer/default/icon/female.png"
  919. // }else{
  920. // src = "../x_component_Org/$Explorer/default/icon/man.png"
  921. // }
  922. // }
  923. // return src;
  924. },
  925. loadRightInfor: function(){
  926. var text = this.data.name+((this.data.employee) ? "("+this.data.employee+")" : "");
  927. if (!this.nameNode) this.nameNode = new Element("div", {"styles": this.style.titleInforNameNode}).inject(this.titleInforRightNode);
  928. if (!this.signatureNode) this.signatureNode = new Element("div", {"styles": this.style.titleInforSignatureNode}).inject(this.titleInforRightNode);
  929. this.nameNode.set("text", text);
  930. this.signatureNode.set("text", (this.data.signature || "" ));
  931. },
  932. refresh: function(){
  933. this.loadLeftInfor();
  934. this.loadRightInfor();
  935. },
  936. loadAction: function(){},
  937. destroy: function(){
  938. this.contentNode.empty();
  939. MWF.release(this);
  940. }
  941. });
  942. MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor = new Class({
  943. initialize: function (content) {
  944. this.content = content;
  945. this.item = content.item;
  946. this.data = this.content.data;
  947. this.explorer = this.item.explorer;
  948. this.contentNode = this.content.bottomContentNode;
  949. this.style = this._getStyle();
  950. this.load();
  951. },
  952. _getStyle: function(){
  953. return this.item.style.person;
  954. },
  955. load: function(){
  956. this.readContentNode = new Element("div", {"styles": this.style.baseReadNode}).inject(this.contentNode);
  957. this.addInforList();
  958. },
  959. addInfor: function(text){
  960. return new Element("div", {"styles": this.style.baseReadContentNode, "text": text}).inject(this.readContentNode);
  961. },
  962. addInforList: function(){},
  963. refresh: function(){
  964. this.readContentNode.empty();
  965. this.addInforList();
  966. },
  967. destroy: function(){
  968. this.readContentNode.empty();
  969. this.readContentNode.destroy();
  970. MWF.release(this);
  971. }
  972. });