$Explorer.js 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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. var key = this.searchInputNode.get("value");
  219. var isSearchElement = true;
  220. this.searching = false;
  221. if (key){
  222. if (key!==this.options.lp.searchText){
  223. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  224. if (isSearchElement){
  225. this._listElementByKey(function(json){
  226. if (this.currentItem) this.currentItem.unSelected();
  227. this.clear();
  228. json.data.each(function(itemData){
  229. var item = this._newElement(itemData, this);
  230. item.load();
  231. }.bind(this));
  232. this.searching = true;
  233. }.bind(this), null, key);
  234. }else{
  235. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  236. }
  237. }else{
  238. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  239. if (isSearchElement){
  240. this.clear();
  241. this.reloadElements();
  242. }else{
  243. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  244. }
  245. }
  246. }else{
  247. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  248. if (isSearchElement){
  249. this.clear();
  250. this.reloadElements();
  251. }else{
  252. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  253. }
  254. }
  255. },
  256. resizePropertyContentNode: function(){
  257. var size = this.node.getSize();
  258. var tSize = this.propertyTitleNode.getSize();
  259. var mtt = this.propertyTitleNode.getStyle("margin-top").toFloat();
  260. var mbt = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  261. var mtc = this.propertyContentNode.getStyle("margin-top").toFloat();
  262. var mbc = this.propertyContentNode.getStyle("margin-bottom").toFloat();
  263. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  264. this.propertyContentNode.setStyle("height", height);
  265. tSize = this.toolbarNode.getSize();
  266. mtt = this.toolbarNode.getStyle("margin-top").toFloat();
  267. mbt = this.toolbarNode.getStyle("margin-bottom").toFloat();
  268. mtc = this.toolbarNode.getStyle("margin-top").toFloat();
  269. mbc = this.toolbarNode.getStyle("margin-bottom").toFloat();
  270. height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  271. this.listScrollNode.setStyle("height", ""+height+"px");
  272. if (this.pingyinNode){
  273. this.setPingyinNodePosition();
  274. this.pingyinNode.setStyle("height", ""+size.y+"px");
  275. }
  276. },
  277. loadScroll: function(){
  278. MWF.require("MWF.widget.ScrollBar", function(){
  279. var _self = this;
  280. new MWF.widget.ScrollBar(this.listScrollNode, {
  281. "style":"xApp_Organization_Explorer",
  282. "where": "before",
  283. "distance": 100,
  284. "friction": 4,
  285. "axis": {"x": false, "y": true},
  286. "onScroll": function(y){
  287. if( _self.searching )return;
  288. var scrollSize = _self.listScrollNode.getScrollSize();
  289. var clientSize = _self.listScrollNode.getSize();
  290. var scrollHeight = scrollSize.y-clientSize.y;
  291. if (y+200>scrollHeight) {
  292. if (!_self.isElementLoaded) _self.loadElements();
  293. }
  294. }
  295. });
  296. // new MWF.widget.ScrollBar(this.propertyContentNode, {
  297. // "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  298. // });
  299. }.bind(this));
  300. },
  301. loadResize: function(){
  302. this.propertyResize = new Drag(this.resizeBarNode,{
  303. "snap": 1,
  304. "onStart": function(el, e){
  305. var x = e.event.clientX;
  306. var y = e.event.clientY;
  307. el.store("position", {"x": x, "y": y});
  308. var size = this.listAreaNode.getSize();
  309. el.store("initialWidth", size.x);
  310. }.bind(this),
  311. "onDrag": function(el, e){
  312. var x = e.event.clientX;
  313. // var y = e.event.y;
  314. var bodySize = this.node.getSize();
  315. var position = el.retrieve("position");
  316. var initialWidth = el.retrieve("initialWidth").toFloat();
  317. var dx = position.x.toFloat()-x.toFloat();
  318. var width = initialWidth-dx;
  319. if (width> bodySize.x/1.5) width = bodySize.x/1.5;
  320. if (width<300) width = 300;
  321. this.listAreaNode.setStyle("width", width+1);
  322. this.propertyAreaNode.setStyle("margin-left", width);
  323. }.bind(this)
  324. });
  325. },
  326. getPageNodeCount: function(){
  327. var size = this.listScrollNode.getSize();
  328. return (size.y / 50).toInt() + 5;
  329. },
  330. loadList: function(){
  331. this.loadElements();
  332. this.continueLoadFun = this.continueLoad.bind(this);
  333. this.app.addEvent("resize", this.continueLoadFun);
  334. },
  335. continueLoad: function(){
  336. if (this.elements.length<this.getPageNodeCount()){
  337. this.loadElements(true);
  338. }
  339. },
  340. reloadElements : function(){
  341. this.elements = [];
  342. this.clear();
  343. this.loadElements();
  344. },
  345. loadElements: function(addToNext){
  346. if (!this.isElementLoaded){
  347. if (!this.loaddingElement){
  348. this.loaddingElement = true;
  349. var count = this.getPageNodeCount();
  350. this._listElementNext(this.getLastLoadedElementId(), count, function(json){
  351. if (json.data.length){
  352. this.loadListContent(json.data);
  353. this.loaddingElement = false;
  354. if (json.data.length<count){
  355. this.isElementLoaded = true;
  356. this.app.notice(this.options.lp.elementLoaded, "ok", this.listScrollNode, {"x": "center", "y": "bottom"});
  357. }else{
  358. if (this.loadElementQueue>0){
  359. this.loadElementQueue--;
  360. this.loadElements();
  361. }
  362. }
  363. }else{
  364. if (!this.elements.length){
  365. //this.setNoGroupNoticeArea();
  366. }else{
  367. this.app.notice(this.options.lp.elementLoaded, "ok", this.listScrollNode, {"x": "center", "y": "bottom"});
  368. }
  369. this.isElementLoaded = true;
  370. this.loaddingElement = false;
  371. }
  372. }.bind(this));
  373. }else{
  374. if (addToNext) this.loadElementQueue++;
  375. }
  376. }
  377. },
  378. getLastLoadedElementId: function(){
  379. return (this.elements.length) ? this.elements[this.elements.length-1].data.id : "";
  380. },
  381. loadListContent: function(data){
  382. data.each(function(itemData, i){
  383. var item = this._newElement(itemData, this, i);
  384. this.elements.push(item);
  385. item.load();
  386. if (this.elements.length===1) item.selected();
  387. }.bind(this));
  388. },
  389. setNoElementNoticeArea: function(){
  390. //没有数据时的提示
  391. },
  392. checkDeleteElements: function(item){
  393. if (this.deleteElements.length){
  394. if (!this.deleteElementsNode){
  395. this.deleteElementsNode = new Element("div", {"styles": this.css.deleteElementsNode}).inject(this.node);
  396. this.deleteElementsDeleteNode = new Element("div", {"styles": this.css.deleteElementsDeleteNode,"text": this.options.lp.deleteElements}).inject(this.deleteElementsNode);
  397. this.deleteElementsCancelNode = new Element("div", {"styles": this.css.deleteElementsCancelNode,"text": this.options.lp.deleteElementsCancel}).inject(this.deleteElementsNode);
  398. this.deleteElementsDeleteNode.addEvent("click", function(e){this.deleteSelectedElements(e);}.bind(this));
  399. this.deleteElementsCancelNode.addEvent("click", function(e){this.deleteSelectedElementsCancel(e);}.bind(this));
  400. }
  401. this.deleteElementsNode.position({
  402. relativeTo: (item) ? item.node : this.toolbarNode,
  403. position: "centerBottom",
  404. edge: "centerTop"
  405. });
  406. }else{
  407. if (this.deleteElementsNode){
  408. this.deleteElementsNode.destroy();
  409. this.deleteElementsNode = null;
  410. delete this.deleteElementsNode;
  411. }
  412. }
  413. },
  414. deleteSelectedElements: function(e){
  415. var _self = this;
  416. this.app.confirm("infor", e, this.options.lp.deleteElementsTitle, this.options.lp.deleteElementsConfirm, 300, 120, function(){
  417. var deleted = [];
  418. var doCount = 0;
  419. var readyCount = _self.deleteElements.length;
  420. var errorText = "";
  421. var complete;
  422. complete = function () {
  423. if (doCount === readyCount) {
  424. if (errorText) {
  425. _self.app.notice(errorText, "error", _self.propertyContentNode, {x: "left", y: "top"});
  426. }
  427. }
  428. };
  429. _self.deleteElements.each(function(element){
  430. element["delete"](function(){
  431. deleted.push(element);
  432. doCount++;
  433. if (_self.deleteElements.length===doCount){
  434. _self.deleteElements = _self.deleteElements.filter(function (item) {
  435. return !deleted.contains(item);
  436. });
  437. _self.checkDeleteElements();
  438. }
  439. complete();
  440. }, function(error){
  441. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  442. doCount++;
  443. if (_self.deleteElements.length !== doCount) {
  444. } else {
  445. _self.deleteElements = _self.deleteElements.filter(function (item) {
  446. return !deleted.contains(item);
  447. });
  448. _self.checkDeleteElements();
  449. }
  450. complete();
  451. });
  452. });
  453. this.close();
  454. }, function(){
  455. this.close();
  456. });
  457. },
  458. deleteSelectedElementsCancel: function() {
  459. while (this.deleteElements.length){
  460. var element = this.deleteElements[0];
  461. element.setUndelete();
  462. //if (element.deleteNode) element.deleteNode.click();
  463. if (this.currentItem!==element){
  464. element.contentNode.setStyles(element.style.contentNode);
  465. if (element.data.id) element.actionNode.fade("out");
  466. }
  467. }
  468. this.checkDeleteElements();
  469. },
  470. destroy: function(){
  471. if (this.hidePingyinFun) this.app.content.removeEvent("mousedown", this.hidePingyinFun);
  472. if (this.resizePropertyContentNodeFun) this.app.removeEvent("resize", this.resizePropertyContentNodeFun);
  473. if (this.continueLoadFun) this.app.removeEvent("resize", this.continueLoadFun);
  474. if (this.removePingyinFun) this.app.removeEvent("queryClose", this.removePingyinFun);
  475. MWF.release(this);
  476. },
  477. _isActionManager: function(){
  478. return MWF.AC.isOrganizationManager();
  479. },
  480. _listElementNext: function(lastid, count, callback){
  481. this.actions.listPersonNext(lastid, count, function(json){
  482. if (callback) {
  483. callback.apply(this, [json]);
  484. }
  485. }.bind(this));
  486. },
  487. _newElement: function(data, explorer, i){
  488. return new MWF.xApplication.Org.PersonExplorer.Person(data, explorer, this.isEditor, i);
  489. },
  490. _listElementByKey: function(callback, failure, key){
  491. this.actions.listPersonByKey(function(json){
  492. if (callback) {
  493. callback.apply(this, [json]);
  494. }
  495. }.bind(this), failure, key);
  496. },
  497. _getAddElementData: function(){
  498. return {
  499. "employee": "",
  500. "password": "",
  501. "display": "",
  502. "qq": "",
  503. "mail": "",
  504. "weixin": "",
  505. "weibo": "",
  506. "mobile": "",
  507. "name": "",
  508. "controllerList": []
  509. };
  510. },
  511. getContentStyle: function(contentNode, node){
  512. var position = this.propertyContentNode.getPosition(this.propertyContentNode.getOffsetParent());
  513. var size = this.propertyContentNode.getSize();
  514. contentNode.position({"relativeTo": node,"position": "upperLeft","edge": "upperLeft"});
  515. return {
  516. "top": ""+position.y+"px",
  517. "left": ""+position.x+"px",
  518. "height": ""+size.y+"px",
  519. "width": ""+size.x+"px"
  520. };
  521. },
  522. openPerson: function(data, node){
  523. this.openContent("PersonExplorer", "PersonContent", data, node);
  524. },
  525. openGroup: function(data, node){
  526. this.openContent("GroupExplorer", "GroupContent", data, node);
  527. },
  528. openUnit: function(data, node){
  529. this.openContent("UnitExplorer", "UnitContent", data, node);
  530. },
  531. openRole: function(data, node){
  532. this.openContent("RoleExplorer", "RoleContent", data, node);
  533. },
  534. openContent: function(explorerClazz, contentClazz, data, node){
  535. MWF.xDesktop.requireApp("Org", explorerClazz, function(){
  536. var contentNode = new Element("div", {"styles": this.css.popContentNode}).inject(this.propertyContentNode, "top");
  537. var to = this.getContentStyle(contentNode, node);
  538. var resize = true;
  539. new Fx.Morph(contentNode, {
  540. "duration": 300,
  541. "transition": Fx.Transitions.Expo.easeOut
  542. }).start(to).chain(function(){
  543. content.setContentSize();
  544. resize = false;
  545. contentNode.setStyles({"position": "static","width": "100%","height": "100%"});
  546. }.bind(this));
  547. var item = {
  548. "explorer": this,
  549. "style": this.css.item,
  550. "data": data,
  551. "isEdit": false,
  552. "refresh": function(){},
  553. "propertyContentNode": contentNode
  554. };
  555. var content = new MWF.xApplication.Org[explorerClazz][contentClazz](item, true);
  556. var timeoutResize = function(){
  557. content.setContentSize();
  558. if (resize)window.setTimeout(function(){timeoutResize();}, 30);
  559. };
  560. window.setTimeout(function(){timeoutResize();}, 30);
  561. }.bind(this));
  562. }
  563. });
  564. MWF.xApplication.Org.$Explorer.Item = new Class({
  565. //Extends: MWF.xApplication.Organization.GroupExplorer.Group,
  566. initialize: function(data, explorer, isEditor, i){
  567. this.i = i;
  568. this.data = data;
  569. this.explorer = explorer;
  570. this.listNode = this.explorer.listNode;
  571. this.propertyContentNode = this.explorer.propertyContentNode;
  572. this.initStyle();
  573. this.selectedAttributes = [];
  574. this.isEdit = false;
  575. this.isEditor = isEditor;
  576. this.deleteSelected = false;
  577. },
  578. initStyle: function(){
  579. this.style = this.explorer.css.item;
  580. },
  581. refresh: function(){
  582. this.iconNode.getElement("img").set("src", this._getIcon());
  583. this._loadTextNode();
  584. if (this.content){
  585. if (this.content.titleInfor) this.content.titleInfor.refresh();
  586. if (this.content.bottomInfor) this.content.bottomInfor.refresh();
  587. }
  588. this.addActions();
  589. },
  590. load: function(){
  591. this.node = new Element("div", {"styles": this.style.node}).inject(this.listNode);
  592. // if (this.i<10){
  593. // var r = (59+((255-59)*this.i)/10).toInt();
  594. // var g = (118+((255-118)*this.i)/10).toInt();
  595. // var b = (182+((255-182)*this.i)/10).toInt();
  596. // this.node.setStyle("background-color", "rgb("+r+","+g+","+b+")");
  597. // }
  598. this.contentNode = new Element("div", {"styles": this.style.contentNode}).inject(this.node);
  599. this.iconNode = new Element("div", {"styles": this.style.iconNode}).inject(this.contentNode);
  600. var src = this._getIcon();
  601. var img = new Element("img", {
  602. "styles": this.style.iconImgNode,
  603. "src": src
  604. }).inject(this.iconNode);
  605. this.actionNode = new Element("div", {"styles": this.style.actionNode}).inject(this.contentNode);
  606. this.textNode = new Element("div", {"styles": this.style.textNode}).inject(this.contentNode);
  607. this._loadTextNode();
  608. this.setNewItem();
  609. this.node.inject(this.listNode);
  610. this.addActions();
  611. this.setEvent();
  612. },
  613. setNewItem: function(){
  614. if (!this.created){
  615. if (!this.data.id){
  616. this.created = false;
  617. this.contentNode.setStyles(this.style.contentNodeNew);
  618. }else {
  619. this.created = true;
  620. this.contentNode.setStyles(this.style.contentNode);
  621. }
  622. }
  623. },
  624. addActions: function(){
  625. if (this.isEditor){
  626. if (this.data.id){
  627. if (this.data.control.allowDelete){
  628. if (!this.deleteNode){
  629. this.deleteNode = new Element("div", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  630. this.deleteNode.addEvent("click", function(e){
  631. if (!this.notDelete){
  632. if (!this.deleteSelected){
  633. this.setDelete();
  634. }else{
  635. this.setUndelete();
  636. }
  637. }
  638. e.stopPropagation();
  639. }.bind(this));
  640. if (this.explorer.currentItem===this){
  641. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  642. }
  643. }
  644. }
  645. }
  646. }
  647. },
  648. setDelete: function(){
  649. this.actionNode.fade("in");
  650. this.deleteNode.setStyles(this.style.actionDeleteNode_delete);
  651. this.contentNode.setStyles(this.style.contentNode_delete);
  652. this.textNode.setStyles(this.style.textNode);
  653. this.explorer.deleteElements.push(this);
  654. this.deleteSelected = true;
  655. this.explorer.checkDeleteElements(this);
  656. },
  657. setUndelete: function(){
  658. this.actionNode.fade("out");
  659. if (this.explorer.currentItem!==this){
  660. this.deleteNode.setStyles(this.style.actionDeleteNode);
  661. this.contentNode.setStyles(this.style.contentNode);
  662. this.textNode.setStyles(this.style.textNode);
  663. }else{
  664. this.contentNode.setStyles(this.style.contentNode_selected);
  665. this.textNode.setStyles(this.style.textNode_selected);
  666. this.actionNode.setStyles(this.style.actionNode_selected);
  667. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  668. }
  669. this.explorer.deleteElements.erase(this);
  670. this.deleteSelected = false;
  671. this.explorer.checkDeleteElements(this);
  672. },
  673. setEvent: function(){
  674. this.contentNode.addEvents({
  675. "mouseover": function(e){
  676. if (this.explorer.currentItem!==this && !this.deleteSelected){
  677. this.contentNode.setStyles(this.style.nodeOver);
  678. if (!this.deleteSelected) if (this.data.id) this.actionNode.fade("in");
  679. }
  680. }.bind(this),
  681. "mouseout": function(e){
  682. if (this.explorer.currentItem!==this && !this.deleteSelected){
  683. this.contentNode.setStyles(this.style.contentNode);
  684. if (!this.deleteSelected) if (this.data.id) this.actionNode.fade("out");
  685. }
  686. }.bind(this),
  687. "click": function(e){
  688. if (!this.deleteSelected){
  689. if (this.explorer.currentItem){
  690. if (this.explorer.currentItem.unSelected()){
  691. this.selected();
  692. }else{
  693. this.explorer.app.notice(this.explorer.options.lp.elementSave, "error", this.propertyContentNode);
  694. }
  695. }else{
  696. this.selected();
  697. }
  698. }
  699. }.bind(this)
  700. });
  701. },
  702. unSelected: function(){
  703. if (this.content.baseInfor.mode==="edit") return false;
  704. if (!this.deleteSelected){
  705. this.explorer.currentItem = null;
  706. this.contentNode.setStyles(this.style.contentNode);
  707. this.textNode.setStyles(this.style.textNode);
  708. this.actionNode.setStyles(this.style.actionNode);
  709. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode);
  710. }
  711. this.clearItemProperty();
  712. return true;
  713. },
  714. clearItemProperty: function(){
  715. this.explorer.propertyTitleNode.empty();
  716. if (this.content) this.content.destroy();
  717. this.explorer.propertyContentNode.empty();
  718. },
  719. selected: function(){
  720. this.explorer.currentItem = this;
  721. this.contentNode.setStyles(this.style.contentNode_selected);
  722. this.textNode.setStyles(this.style.textNode_selected);
  723. this.actionNode.setStyles(this.style.actionNode_selected);
  724. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  725. this.showItemProperty();
  726. },
  727. editBaseInfor: function(){
  728. this.content.edit();
  729. },
  730. showItemProperty: function(){
  731. this.content = new MWF.xApplication.Org.PersonExplorer.PersonContent(this);
  732. },
  733. destroy: function(){
  734. if (this.explorer.currentItem===this){
  735. this.explorer.currentItem = null;
  736. this.clearItemProperty();
  737. }
  738. this.node.destroy();
  739. delete this;
  740. },
  741. "delete": function(success, failure){
  742. this.explorer.actions.deletePerson(this.data.id, function(){
  743. this.destroy();
  744. if (success) success();
  745. }.bind(this), function(xhr, text, error){
  746. var errorText = error;
  747. if (xhr) errorText = xhr.responseText;
  748. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  749. if (failure) failure();
  750. });
  751. },
  752. _loadTextNode: function(){
  753. this.textNode.set({"text": this.data.name});
  754. },
  755. _getIcon: function(nocache){
  756. var url = (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "../x_component_Org/$Explorer/default/icon/man.png";
  757. return (nocache) ? url+"?"+(new Date().getTime()) : url;
  758. //return (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "../x_component_Org/$Explorer/default/icon/man.png";
  759. // var src = "data:image/png;base64,"+this.data.icon;
  760. // if (!this.data.icon){
  761. // if (this.data.genderType==="f"){
  762. // src = "../x_component_Org/$Explorer/default/icon/female24.png"
  763. // }else{
  764. // src = "../x_component_Org/$Explorer/default/icon/man24.png"
  765. // }
  766. // }
  767. // return src;
  768. }
  769. });
  770. MWF.xApplication.Org.$Explorer.ItemContent = new Class({
  771. initialize: function (item, isClose) {
  772. this.item = item;
  773. this.isClose = isClose;
  774. this.explorer = this.item.explorer;
  775. this.contentNode = this.item.propertyContentNode;
  776. this.style = this.item.style.person;
  777. this.load();
  778. },
  779. _getData: function(callback){
  780. this.data = this.item.data;
  781. if (callback) callback();
  782. },
  783. load: function(){
  784. this.titleContentNode = new Element("div").inject(this.contentNode);
  785. this.propertyContentScrollNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.contentNode);
  786. this.propertyContentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyContentScrollNode);
  787. this.bottomContentNode = new Element("div").inject(this.contentNode);
  788. this._getData(function(){
  789. this.explorer.propertyTitleNode.set("text", this.data.name);
  790. this._showItemPropertyTitle();
  791. this.loadItemPropertyTab(function(){
  792. this._loadTabs();
  793. this._loadContent();
  794. if (this.propertyTab.pages.length) this.propertyTab.pages[0].showTabIm();
  795. }.bind(this));
  796. this._showItemPropertyBottom();
  797. this.setContentSizeFun = this.setContentSize.bind(this);
  798. this.setContentSize();
  799. this.explorer.app.addEvent("resize", this.setContentSizeFun);
  800. new MWF.widget.ScrollBar(this.propertyContentScrollNode, {
  801. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  802. });
  803. }.bind(this));
  804. //this.showItemPropertyTitle();
  805. },
  806. setContentSize: function(){
  807. var size = this.contentNode.getSize();
  808. var titleSize = this.titleContentNode.getSize();
  809. var bottomSize = this.bottomContentNode.getSize();
  810. var y = size.y-titleSize.y-bottomSize.y;
  811. this.propertyContentScrollNode.setStyle("height", ""+y+"px")
  812. },
  813. loadItemPropertyTab: function(callback){
  814. this.propertyTabContainerNode = new Element("div", {"styles": this.item.style.tabTitleNode}).inject(this.propertyContentNode, "top");
  815. MWF.require("MWF.widget.Tab", function(){
  816. this.propertyTab = new MWF.widget.Tab(this.propertyContentNode, {"style": "org"});
  817. this.propertyTab.load();
  818. this.propertyTab.tabNodeContainer.inject(this.propertyTabContainerNode);
  819. if (callback) callback();
  820. }.bind(this));
  821. },
  822. edit: function(){
  823. if (this.baseInfor) this.baseInfor.edit();
  824. },
  825. destroy: function(){
  826. if (this.setContentSizeFun) this.explorer.app.removeEvent("resize", this.setContentSizeFun);
  827. if (this.titleInfor) this.titleInfor.destroy();
  828. if (this.bottomInfor) this.bottomInfor.destroy();
  829. if (this.baseInfor) this.baseInfor.destroy();
  830. this.contentNode.empty();
  831. MWF.release(this);
  832. },
  833. _showItemPropertyTitle: function(){
  834. this.titleInfor = new MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor(this);
  835. },
  836. _showItemPropertyBottom: function(){
  837. this.bottomInfor = new MWF.xApplication.Org.$Explorer.ItemContent.BottmInfor(this);
  838. },
  839. _loadTabs: function(){},
  840. _loadContent: function(){}
  841. });
  842. MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor = new Class({
  843. initialize: function (content) {
  844. this.content = content;
  845. this.item = content.item;
  846. this.data = this.content.data;
  847. this.explorer = this.item.explorer;
  848. this.contentNode = this.content.titleContentNode;
  849. this.style = this._getStyle();
  850. this.load();
  851. },
  852. _getStyle: function(){
  853. return this.item.style.person;
  854. },
  855. load: function(){
  856. this.titleBgNode = new Element("div", {"styles": this.style.titleBgNode}).inject(this.contentNode);
  857. this.titleNode = new Element("div", {"styles": this.style.titleNode}).inject(this.titleBgNode);
  858. this.setBackground();
  859. this.titleInforNode = new Element("div#titleInfor", {"styles": this.style.titleInforNode}).inject(this.titleNode);
  860. this.titleInforLeftNode = new Element("div", {"styles": this.style.titleInforLeftNode}).inject(this.titleInforNode);
  861. this.titleInforRightNode = new Element("div", {"styles": this.style.titleInforRightNode}).inject(this.titleInforNode);
  862. this.loadLeftInfor();
  863. this.loadRightInfor();
  864. this.loadAction();
  865. if (this.content.isClose) this.createCloseNode();
  866. },
  867. createCloseNode: function(){
  868. this.closeNode = new Element("div", {"styles": this.style.titleCloseNode}).inject(this.titleBgNode);
  869. this.closeNode.addEvents({
  870. "mousedown": function(){this.closeNode.setStyles(this.style.titleCloseNode_down)}.bind(this),
  871. "mouseup": function(){this.closeNode.setStyles(this.style.titleCloseNode)}.bind(this),
  872. "click": function(){
  873. var node = this.content.contentNode;
  874. this.content.destroy();
  875. node.destroy();
  876. node = null;
  877. }.bind(this)
  878. });
  879. },
  880. setBackground: function(){
  881. this.titleBgNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/person_bg_bg.png)");
  882. this.titleNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/person_bg.png)");
  883. },
  884. loadLeftInfor: function(){
  885. if (!this.iconAreaNode) this.iconAreaNode = new Element("div", {"styles": this.style.titleInforIconAreaNode}).inject(this.titleInforLeftNode);
  886. if (!this.iconNode) this.iconNode = new Element("img", {"styles": this.style.titleInforIconNode}).inject(this.iconAreaNode);
  887. this.iconNode.set("src", this._getIcon());
  888. },
  889. _getIcon: function(nocache){
  890. var url = (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "../x_component_Org/$Explorer/default/icon/man.png";
  891. return (nocache) ? url+"?"+(new Date().getTime()) : url;
  892. // var src = "data:image/png;base64,"+this.data.icon;
  893. // if (!this.data.icon){
  894. // if (this.data.genderType==="f"){
  895. // src = "../x_component_Org/$Explorer/default/icon/female.png"
  896. // }else{
  897. // src = "../x_component_Org/$Explorer/default/icon/man.png"
  898. // }
  899. // }
  900. // return src;
  901. },
  902. loadRightInfor: function(){
  903. var text = this.data.name+((this.data.employee) ? "("+this.data.employee+")" : "");
  904. if (!this.nameNode) this.nameNode = new Element("div", {"styles": this.style.titleInforNameNode}).inject(this.titleInforRightNode);
  905. if (!this.signatureNode) this.signatureNode = new Element("div", {"styles": this.style.titleInforSignatureNode}).inject(this.titleInforRightNode);
  906. this.nameNode.set("text", text);
  907. this.signatureNode.set("text", (this.data.signature || "" ));
  908. },
  909. refresh: function(){
  910. this.loadLeftInfor();
  911. this.loadRightInfor();
  912. },
  913. loadAction: function(){},
  914. destroy: function(){
  915. this.contentNode.empty();
  916. MWF.release(this);
  917. }
  918. });
  919. MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor = new Class({
  920. initialize: function (content) {
  921. this.content = content;
  922. this.item = content.item;
  923. this.data = this.content.data;
  924. this.explorer = this.item.explorer;
  925. this.contentNode = this.content.bottomContentNode;
  926. this.style = this._getStyle();
  927. this.load();
  928. },
  929. _getStyle: function(){
  930. return this.item.style.person;
  931. },
  932. load: function(){
  933. this.readContentNode = new Element("div", {"styles": this.style.baseReadNode}).inject(this.contentNode);
  934. this.addInforList();
  935. },
  936. addInfor: function(text){
  937. return new Element("div", {"styles": this.style.baseReadContentNode, "text": text}).inject(this.readContentNode);
  938. },
  939. addInforList: function(){},
  940. refresh: function(){
  941. this.readContentNode.empty();
  942. this.addInforList();
  943. },
  944. destroy: function(){
  945. this.readContentNode.empty();
  946. this.readContentNode.destroy();
  947. MWF.release(this);
  948. }
  949. });