Document.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. MWF.xApplication.Setting.Document = new Class({
  2. Implements: [Options, Events],
  3. initialize: function(explorer, contentAreaNode, options){
  4. this.setOptions(options);
  5. this.explorer = explorer;
  6. this.app = this.explorer.app;
  7. this.lp = this.app.lp;
  8. this.actions = this.app.actions;
  9. this.css = this.app.css;
  10. this.contentAreaNode = contentAreaNode;
  11. this.load();
  12. },
  13. load: function(){
  14. this.node = new Element("div", {"styles": {"overflow": "hidden", "padding-bottom": "80px"}}).inject(this.contentAreaNode);
  15. this.titleName = new Element("div", {"styles": this.explorer.css.explorerContentTitleNode}).inject(this.node);
  16. this.titleName.set("text", this.lp.base_nameSetting);
  17. this.baseTitleInput = new MWF.xApplication.Setting.Document.Input(this.explorer, this.node, {
  18. "lp": {"title": this.lp.base_title, "infor": this.lp.base_title_infor, "action": this.lp.base_title_action},
  19. "data": {"key": "collectData", "valueKey": "title", "notEmpty": true, "infor": this.lp.base_title_empty },
  20. "value": this.explorer.collectData.title
  21. });
  22. this.baseFooterInput = new MWF.xApplication.Setting.Document.Input(this.explorer, this.node, {
  23. "lp": {"title": this.lp.base_footer, "infor": this.lp.base_footer_infor, "action": this.lp.base_footer_action},
  24. "data": {"key": "collectData", "valueKey": "footer", "notEmpty": false},
  25. "value": this.explorer.collectData.footer
  26. });
  27. },
  28. "destroy": function(){
  29. this.node.destroy();
  30. this.contentAreaNode.empty();
  31. MWF.release(this);
  32. }
  33. });
  34. MWF.xApplication.Setting.Document.Input = new Class({
  35. Implements: [Options, Events],
  36. initialize: function(explorer, contentAreaNode, data, options){
  37. this.setOptions(options);
  38. this.explorer = explorer;
  39. this.app = this.explorer.app;
  40. this.lp = this.app.lp;
  41. this.contentAreaNode = contentAreaNode;
  42. this.actions = this.app.actions;
  43. this.css = this.app.css;
  44. this.data = data;
  45. this.load();
  46. },
  47. load: function(){
  48. this.loadInput(this.data.lp.title, this.data.lp.infor, this.data.value, true, this.data.lp.action, function(){
  49. this.inputValueArea.empty();
  50. if (!this.input) this.input = new Element("input", {"disabled": true, "styles": this.css.explorerContentInputNode}).inject(this.inputValueArea);
  51. this.input.set("value", this.data.value);
  52. this.input.set({"disabled": false, "styles": this.css.explorerContentInputNode_edit});
  53. this.button.setStyle("display", "none");
  54. this.input.focus();
  55. if (!this.okButton) this.okButton = this.createButton(this.lp.ok, function(){
  56. if (this.submitData()) this.editCancel();
  57. }.bind(this)).inject(this.button, "after");
  58. if (!this.cancelButton) this.cancelButton = this.createButton(this.lp.cancel, function(){
  59. this.fireEvent("cancel");
  60. this.editCancel();
  61. }.bind(this)).inject(this.okButton, "after");
  62. this.okButton.setStyle("display", "block");
  63. this.cancelButton.setStyle("display", "block");
  64. }.bind(this));
  65. },
  66. editCancel: function(){
  67. this.input.set({"disabled": true, "styles": this.css.explorerContentInputNode, "value": this.data.value});
  68. this.inputValueArea.empty();
  69. this.input = null;
  70. this.inputValueArea.set("text", this.data.value);
  71. this.okButton.setStyle("display", "none");
  72. this.cancelButton.setStyle("display", "none");
  73. this.button.setStyle("display", "block");
  74. },
  75. submitData: function(){
  76. var value = this.input.get("value");
  77. if (this.data.data.notEmpty){
  78. if (!value){
  79. this.app.notice(this.data.data.infor, "error");
  80. return false;
  81. }
  82. }
  83. this.explorer[this.data.data.key][this.data.data.valueKey] = value;
  84. this.data.value = value;
  85. var method = "";
  86. if (this.data.data.key=="collectData") method = "setCollect";
  87. if (this.data.data.key=="personData") method = "setPerson";
  88. if (this.data.data.key=="tokenData") method = "setToken";
  89. if (this.data.data.key=="proxyData") method = "setProxy";
  90. if (this.data.data.key=="nativeData"){
  91. method = "setAppStyle";
  92. if (!this.explorer.nativeData.indexPortal){
  93. this.explorer.nativeData.indexType = "default";
  94. }else{
  95. this.explorer.nativeData.indexType = "portal";
  96. }
  97. }
  98. this.actions[method](this.explorer[this.data.data.key], function(){
  99. this.fireEvent("editSuccess");
  100. this.app.notice(this.lp.setSaved, "success");
  101. }.bind(this));
  102. return true;
  103. },
  104. createButton: function(text, action){
  105. var button = new Element("div", {"type": "button", "styles": this.css.explorerContentButtonNode, "text": text});
  106. button.addEvents({
  107. "click": function(){
  108. if (action) action(button);
  109. }.bind(this),
  110. "mouseover": function(){this.setStyle("border", "1px solid #999999");},
  111. "mouseout": function(){this.setStyle("border", "1px solid #eeeeee");}
  112. });
  113. return button
  114. },
  115. loadInput: function(title, infor, value, isEdit, actionTitle, action){
  116. var titleNode = new Element("div", {"styles": this.css.explorerContentItemTitleNode, "text": title}).inject(this.contentAreaNode);
  117. // var dataNode = new Element("div", {"styles": this.css.explorerContentItemDataNode, "text": title}).inject(this.contentAreaNode);
  118. // dataNode.set("text", value);
  119. var titleInforArea = new Element("div", {"styles": this.css.explorerContentInputInforNode, "text": infor}).inject(this.contentAreaNode);
  120. var inputArea = new Element("div", {"styles": this.css.explorerContentInputAreaNode}).inject(this.contentAreaNode);
  121. this.inputValueArea = new Element("div", {"styles": this.css.explorerContentInputValueAreaNode}).inject(inputArea);
  122. this.inputValueArea.set("text", value);
  123. // this.input = new Element("input", {"disabled": true, "styles": this.css.explorerContentInputNode}).inject(inputValueArea);
  124. // this.input.set("value", value);
  125. if (isEdit){
  126. this.button = this.createButton(actionTitle, action).inject(inputArea);
  127. }
  128. // return this.input;
  129. }
  130. });
  131. MWF.xApplication.Setting.Document.Check = new Class({
  132. Extends: MWF.xApplication.Setting.Document.Input,
  133. loadInput: function(title, infor, value, isEdit, actionTitle, action){
  134. var titleNode = new Element("div", {"styles": this.css.explorerContentItemTitleNode, "text": title}).inject(this.contentAreaNode);
  135. if (infor) var titleInforArea = new Element("div", {"styles": this.css.explorerContentInputInforNode, "text": infor}).inject(this.contentAreaNode);
  136. var inputArea = new Element("div", {"styles": this.css.explorerContentInputAreaNode}).inject(this.contentAreaNode);
  137. this.inputValueArea = new Element("div").inject(inputArea);
  138. this.inputPoint = new Element("div").inject(this.inputValueArea);
  139. this.inputInfor = new Element("div", {"styles": this.css.explorerContentCheckInforValueAreaNode}).inject(inputArea);
  140. if (value) {
  141. this.inputPoint.setStyles(this.css.explorerContentCheckPointValueAreaNode_on);
  142. this.inputValueArea.setStyles(this.css.explorerContentCheckValueAreaNode_on);
  143. this.inputInfor.set("text", this.lp.on);
  144. }else{
  145. this.inputPoint.setStyles(this.css.explorerContentCheckPointValueAreaNode_off);
  146. this.inputValueArea.setStyles(this.css.explorerContentCheckValueAreaNode_off);
  147. this.inputInfor.set("text", this.lp.off);
  148. }
  149. if (isEdit){
  150. this.inputValueArea.addEvent("click", function(){
  151. if (this.data.value) {
  152. this.data.value = false;
  153. if (this.data.data.valueKey.indexOf(".")!=-1){
  154. var o = this.explorer[this.data.data.key];
  155. var keys = this.data.data.valueKey.split(".");
  156. keys.each(function(k, i){
  157. if (i==(keys.length-1)){
  158. o[k] = false;
  159. }else{
  160. o = o[k];
  161. }
  162. }.bind(this));
  163. }else{
  164. this.explorer[this.data.data.key][this.data.data.valueKey] = false;
  165. }
  166. this.inputPoint.setStyles(this.css.explorerContentCheckPointValueAreaNode_off);
  167. this.inputValueArea.setStyles(this.css.explorerContentCheckValueAreaNode_off);
  168. this.inputInfor.set("text", this.lp.off);
  169. }else{
  170. this.data.value = true;
  171. if (this.data.data.valueKey.indexOf(".")!=-1){
  172. var o = this.explorer[this.data.data.key];
  173. var keys = this.data.data.valueKey.split(".");
  174. keys.each(function(k, i){
  175. if (i==(keys.length-1)){
  176. o[k] = true;
  177. }else{
  178. o = o[k];
  179. }
  180. }.bind(this));
  181. }else{
  182. this.explorer[this.data.data.key][this.data.data.valueKey] = true;
  183. }
  184. this.inputPoint.setStyles(this.css.explorerContentCheckPointValueAreaNode_on);
  185. this.inputValueArea.setStyles(this.css.explorerContentCheckValueAreaNode_on);
  186. this.inputInfor.set("text", this.lp.on);
  187. }
  188. var method = "";
  189. if (this.data.data.key=="collectData") method = "setCollect";
  190. if (this.data.data.key=="personData") method = "setPerson";
  191. if (this.data.data.key=="tokenData") method = "setToken";
  192. if (this.data.data.key=="proxyData") method = "setProxy";
  193. if (this.data.data.key=="mobileStyleData") method = "setProxy";
  194. if (this.data.data.key=="nativeData"){
  195. method = "setAppStyle";
  196. if (!this.explorer.nativeData.indexPortal){
  197. this.explorer.nativeData.indexType = "default";
  198. }else{
  199. this.explorer.nativeData.indexType = "portal";
  200. }
  201. }
  202. this.actions[method](this.explorer[this.data.data.key], function(){
  203. this.fireEvent("editSuccess");
  204. //this.app.notice(this.lp.setSaved, "success");
  205. }.bind(this));
  206. }.bind(this));
  207. }
  208. }
  209. });
  210. MWF.xApplication.Setting.Document.Select = new Class({
  211. Extends: MWF.xApplication.Setting.Document.Input,
  212. loadInput: function(title, infor, value, isEdit, actionTitle, action){
  213. var titleNode = new Element("div", {"styles": this.css.explorerContentItemTitleNode, "text": title}).inject(this.contentAreaNode);
  214. if (infor) var titleInforArea = new Element("div", {"styles": this.css.explorerContentInputInforNode, "text": infor}).inject(this.contentAreaNode);
  215. var inputArea = new Element("div", {"styles": this.css.explorerContentInputAreaNode}).inject(this.contentAreaNode);
  216. this.inputValueArea = new Element("div", {"styles": this.css.explorerContentInputValueAreaNode}).inject(inputArea);
  217. this.input = new Element("select", {"styles": this.css.explorerContentSelectValueAreaNode}).inject(this.inputValueArea);
  218. this.data.options.each(function(option){
  219. new Element("option", {"value": option.value, "text": option.text, "selected": (value==option.value)}).inject(this.input);
  220. }.bind(this));
  221. if (isEdit){
  222. this.input.addEvent("change", function(){
  223. var v = this.input.options[this.input.selectedIndex].get("value");
  224. this.data.value = v;
  225. this.explorer[this.data.data.key][this.data.data.valueKey] = v;
  226. var method = "";
  227. if (this.data.data.key=="collectData") method = "setCollect";
  228. if (this.data.data.key=="personData") method = "setPerson";
  229. if (this.data.data.key=="tokenData") method = "setToken";
  230. if (this.data.data.key=="proxyData") method = "setProxy";
  231. if (this.data.data.key=="nativeData"){
  232. method = "setAppStyle";
  233. if (!this.explorer.nativeData.indexPortal){
  234. this.explorer.nativeData.indexType = "default";
  235. }else{
  236. this.explorer.nativeData.indexType = "portal";
  237. }
  238. }
  239. this.actions[method](this.explorer[this.data.data.key], function(){
  240. this.fireEvent("editSuccess");
  241. //this.app.notice(this.lp.setSaved, "success");
  242. }.bind(this));
  243. }.bind(this));
  244. }
  245. }
  246. });
  247. MWF.xApplication.Setting.Document.Button = new Class({
  248. Extends: MWF.xApplication.Setting.Document.Input,
  249. loadInput: function(title, infor, value, isEdit, actionTitle, action){
  250. var titleNode = new Element("div", {"styles": this.css.explorerContentItemTitleNode, "text": title}).inject(this.contentAreaNode);
  251. if (infor) var titleInforArea = new Element("div", {"styles": this.css.explorerContentInputInforNode, "text": infor}).inject(this.contentAreaNode);
  252. var inputArea = new Element("div", {"styles": this.css.explorerContentInputAreaNode}).inject(this.contentAreaNode);
  253. this.itemArea = new Element("div", {"styles": this.css.explorerContentListActionAreaNode}).inject(inputArea);
  254. this.itemIconArea = new Element("div", {"styles": this.css.explorerContentListItemIconAreaNode}).inject(this.itemArea);
  255. this.itemIcon = new Element("div", {"styles": this.css.explorerContentListItemIconNode}).inject(this.itemIconArea);
  256. this.itemTextArea = new Element("div", {"styles": this.css.explorerContentListActionTextAreaNode}).inject(this.itemArea);
  257. this.itemIcon.setStyle("background", "url("+this.app.path+this.app.options.style+"/icon/"+this.data.icon+") no-repeat center center");
  258. var t = this.data.itemTitle;
  259. var regexp = /\{.+?\}/g;
  260. var r = t.match(regexp);
  261. if(r){
  262. if (r.length){
  263. for (var i=0; i<r.length; i++){
  264. var text = r[i].substr(0,r[i].lastIndexOf("}"));
  265. text = text.substr(text.indexOf("{")+1,text.length);
  266. var value = this.data[text];
  267. var reg = new RegExp("\\{"+text+"\\}", "g");
  268. t = t.replace(reg,value);
  269. }
  270. }
  271. }
  272. this.itemTextArea.set("text", t);
  273. var _self = this;
  274. this.itemArea.addEvents({
  275. "mouseover": function(){if (!_self.isSelected) this.setStyles(_self.css.explorerContentListActionAreaNode_over);},
  276. "mouseout": function(){if (!_self.isSelected) this.setStyles(_self.css.explorerContentListActionAreaNode);},
  277. "mousedown": function(){if (!_self.isSelected) this.setStyles(_self.css.explorerContentListActionAreaNode_down);},
  278. "mouseup": function(){if (!_self.isSelected) this.setStyles(_self.css.explorerContentListActionAreaNode_over);},
  279. "click": function(e){_self.data.action(e);}
  280. });
  281. }
  282. });
  283. MWF.xApplication.Setting.Document.Image = new Class({
  284. Extends: MWF.xApplication.Setting.Document.Input,
  285. loadInput: function(title, infor, value, isEdit, actionTitle, action){
  286. var titleNode = new Element("div", {"styles": this.css.explorerContentItemTitleNode, "text": title}).inject(this.contentAreaNode);
  287. if (infor) var titleInforArea = new Element("div", {"styles": this.css.explorerContentInputInforNode, "text": infor}).inject(this.contentAreaNode);
  288. var inputArea = new Element("div", {"styles": this.css.explorerContentImgInputAreaNode}).inject(this.contentAreaNode);
  289. this.itemArea = new Element("div", {"styles": this.css.explorerContentImgActionAreaNode}).inject(inputArea);
  290. this.itemIconArea = new Element("div", {"styles": this.css.explorerContentImgItemIconAreaNode}).inject(this.itemArea);
  291. this.itemIcon = new Element("div", {"styles": this.css.explorerContentImgItemIconNode}).inject(this.itemIconArea);
  292. if (this.data.iconData){
  293. this.img = new Element("img", {"src": "data:image/png;base64,"+this.data.iconData}).inject(this.itemIcon);
  294. }else{
  295. this.itemIcon.setStyle("background", "url("+this.app.path+this.app.options.style+"/icon/"+this.list.data.icon+") no-repeat center center");
  296. }
  297. this.itemTextArea = new Element("div", {"styles": this.css.explorerContentImgActionTextAreaNode}).inject(this.itemArea);
  298. this.itemTextDefaultArea = new Element("div", {"styles": this.css.explorerContentImgActionTextAreaNode}).inject(this.itemArea);
  299. if (this.img){
  300. var size = this.img.getSize();
  301. var x = Math.round(size.x);
  302. var y = Math.round(size.y);
  303. titleNode.set("text", title+this.lp.imgSize+x+" * "+y);
  304. }
  305. var t = this.data.itemTitle;
  306. var regexp = /\{.+?\}/g;
  307. var r = t.match(regexp);
  308. if(r){
  309. if (r.length){
  310. for (var i=0; i<r.length; i++){
  311. var text = r[i].substr(0,r[i].lastIndexOf("}"));
  312. text = text.substr(text.indexOf("{")+1,text.length);
  313. var value = this.data[text];
  314. var reg = new RegExp("\\{"+text+"\\}", "g");
  315. t = t.replace(reg,value);
  316. }
  317. }
  318. }
  319. this.itemTextArea.set("text", t);
  320. this.itemTextDefaultArea.set("text", this.lp.defaultImg);
  321. var _self = this;
  322. // this.itemArea.addEvents({
  323. // "mouseover": function(){if (!_self.isSelected) this.setStyles(_self.css.explorerContentImgActionAreaNode_over);},
  324. // "mouseout": function(){if (!_self.isSelected) this.setStyles(_self.css.explorerContentImgActionAreaNode);}
  325. // });
  326. this.itemTextArea.addEvents({
  327. "mouseover": function(){this.itemTextArea.setStyles(this.css.explorerContentImgActionTextAreaNode_over);}.bind(this),
  328. "mouseout": function(){this.itemTextArea.setStyles(this.css.explorerContentImgActionTextAreaNode);}.bind(this),
  329. "click": function(e){_self.changeImage(e);}
  330. });
  331. this.itemTextDefaultArea.addEvents({
  332. "mouseover": function(){this.itemTextDefaultArea.setStyles(this.css.explorerContentImgActionTextAreaNode_over);}.bind(this),
  333. "mouseout": function(){this.itemTextDefaultArea.setStyles(this.css.explorerContentImgActionTextAreaNode);}.bind(this),
  334. "click": function(e){_self.defaultImage(e);}
  335. });
  336. },
  337. changeImage: function(e){
  338. var method = "";
  339. switch (this.data.value.name){
  340. case "launch_logo":
  341. method = "imageLaunchLogo";
  342. break;
  343. case "login_avatar":
  344. method = "imageLoginAvatar";
  345. break;
  346. case "index_bottom_menu_logo_blur":
  347. method = "imageMenuLogoBlur";
  348. break;
  349. case "index_bottom_menu_logo_focus":
  350. method = "imageMenuLogoFocus";
  351. break;
  352. case "people_avatar_default":
  353. method = "imagePeopleAvatarDefault";
  354. break;
  355. case "process_default":
  356. method = "imageProcessDefault";
  357. break;
  358. case "setup_about_logo":
  359. method = "imageSetupAboutLogo";
  360. break;
  361. }
  362. MWF.require("MWF.widget.Upload", function(){
  363. var upload = new MWF.widget.Upload(this.app.content, {
  364. "data": null,
  365. "action": this.actions.action,
  366. "method": method,
  367. "onCompleted": function(json){
  368. debugger;
  369. this.actions.mobile_currentStyle(function(json){
  370. var imgs = json.data.images.filter(function(img){
  371. return img.name==this.data.value.name;
  372. }.bind(this));
  373. var imgData = imgs[0].value;
  374. this.img.set("src", "data:image/png;base64,"+imgData);
  375. }.bind(this));
  376. }.bind(this)
  377. });
  378. upload.load();
  379. }.bind(this));
  380. },
  381. defaultImage: function(e){
  382. var _self = this;
  383. var imgName = this.lp.mobile_style_imgs[this.data.value.name];
  384. var imgInfor = this.lp.mobile_style_imgs_defaultInfor.replace("{name}", imgName);
  385. this.app.confirm("infor", e, this.lp.mobile_style_imgs_defaultTitle, imgInfor, 360, 150, function(){
  386. _self.setDefaultImage();
  387. this.close();
  388. }, function(){
  389. this.close();
  390. });
  391. },
  392. setDefaultImage: function(){
  393. var method = "";
  394. switch (this.data.value.name){
  395. case "launch_logo":
  396. method = "imageLaunchLogoErase";
  397. break;
  398. case "login_avatar":
  399. method = "imageLoginAvatarErase";
  400. break;
  401. case "index_bottom_menu_logo_blur":
  402. method = "imageMenuLogoBlurErase";
  403. break;
  404. case "index_bottom_menu_logo_focus":
  405. method = "imageMenuLogoFocusErase";
  406. break;
  407. case "people_avatar_default":
  408. method = "imagePeopleAvatarDefaultErase";
  409. break;
  410. case "process_default":
  411. method = "imageProcessDefaultErase";
  412. break;
  413. case "setup_about_logo":
  414. method = "imageSetupAboutLogoErase";
  415. break;
  416. }
  417. this.actions[method](function(){
  418. this.actions.mobile_currentStyle(function(json){
  419. var imgs = json.data.images.filter(function(img){
  420. return img.name==this.data.value.name;
  421. }.bind(this));
  422. var imgData = imgs[0].data;
  423. this.img.set("src", "data:image/png;base64,"+this.data.iconData);
  424. }.bind(this));
  425. }.bind(this));
  426. }
  427. });
  428. MWF.xApplication.Setting.Document.List = new Class({
  429. Extends: MWF.xApplication.Setting.Document.Input,
  430. loadInput: function(title, infor, value, isEdit, actionTitle, action){
  431. this.items = [];
  432. var titleNode = new Element("div", {"styles": this.css.explorerContentItemTitleNode, "text": title}).inject(this.contentAreaNode);
  433. if (infor) var titleInforArea = new Element("div", {"styles": this.css.explorerContentInputInforNode, "text": infor}).inject(this.contentAreaNode);
  434. var inputArea = new Element("div", {"styles": this.css.explorerContentListAreaNode}).inject(this.contentAreaNode);
  435. this.type = (typeOf(value)=="object") ? "object" : "list";
  436. if (actionTitle){
  437. this.actionArea = new Element("div", {"styles": this.css.explorerContentListActionAreaNode}).inject(inputArea);
  438. var actionIconArea = new Element("div", {"styles": this.css.explorerContentListActionIconAreaNode}).inject(this.actionArea);
  439. var actionIcon = new Element("div", {"styles": this.css.explorerContentListActionIconNode}).inject(actionIconArea);
  440. if (this.type=="object") actionIcon.setStyle("background", "url("+this.app.path+this.app.options.style+"/icon/edit.png) no-repeat center center");
  441. var actionTextArea = new Element("div", {"styles": this.css.explorerContentListActionTextAreaNode, "text": actionTitle}).inject(this.actionArea);
  442. this.actionArea.addEvents({
  443. "mouseover": function(){this.actionArea.setStyles(this.css.explorerContentListActionAreaNode_over);}.bind(this),
  444. "mouseout": function(){this.actionArea.setStyles(this.css.explorerContentListActionAreaNode);}.bind(this),
  445. "mousedown": function(){this.actionArea.setStyles(this.css.explorerContentListActionAreaNode_down);}.bind(this),
  446. "mouseup": function(){this.actionArea.setStyles(this.css.explorerContentListActionAreaNode_over);}.bind(this),
  447. "click": function(){
  448. if (this.type=="list") this.addItem();
  449. if (this.type=="object") this.items[0].edit();
  450. }.bind(this)
  451. });
  452. }
  453. this.itemArea = new Element("div", {"styles": {"overflow": "hidden", "clear": "both"}}).inject(inputArea);
  454. if (this.type=="list"){
  455. if (value.length && value.length){
  456. value.each(function(v){
  457. this.createItem(v);
  458. }.bind(this));
  459. }
  460. }
  461. if (this.type=="object"){
  462. this.createItem(value);
  463. }
  464. },
  465. createItem: function(v){
  466. this.items.push(new MWF.xApplication.Setting.Document.List.Item(this, v));
  467. },
  468. addItem: function(){
  469. new MWF.xApplication.Setting.Document.List.ItemEditor(this, Object.clone(this.data.addItem), function(data){
  470. this.data.value.push(data);
  471. this.save(data);
  472. }.bind(this));
  473. },
  474. save: function(data){
  475. var method = "";
  476. if (this.data.data.key=="collectData") method = "setCollect";
  477. if (this.data.data.key=="personData") method = "setPerson";
  478. if (this.data.data.key=="tokenData") method = "setToken";
  479. if (this.data.data.key=="proxyData") method = "setProxy";
  480. if (this.data.data.key=="nativeData"){
  481. method = "setAppStyle";
  482. if (!this.explorer.nativeData.indexPortal){
  483. this.explorer.nativeData.indexType = "default";
  484. }else{
  485. this.explorer.nativeData.indexType = "portal";
  486. }
  487. }
  488. this.actions[method](this.explorer[this.data.data.key], function(){
  489. this.fireEvent("editSuccess");
  490. this.reloadItems();
  491. }.bind(this));
  492. },
  493. reloadItems: function(){
  494. this.itemArea.empty();
  495. this.items = [];
  496. if (this.type=="list"){
  497. if (this.data.value.length && this.data.value.length){
  498. this.data.value.each(function(v){
  499. this.createItem(v);
  500. }.bind(this));
  501. }
  502. }
  503. if (this.type=="object"){
  504. this.createItem(this.data.value);
  505. }
  506. }
  507. });
  508. MWF.xApplication.Setting.Document.List.ItemEditor = new Class({
  509. initialize: function(list, data, saveAction, title){
  510. this.list = list;
  511. this.title= title;
  512. this.explorer = this.list.explorer;
  513. this.app = this.explorer.app;
  514. this.lp = this.app.lp;
  515. this.actions = this.app.actions;
  516. this.css = this.app.css;
  517. this.data = data;
  518. this.isSelected = false;
  519. this.saveAction = saveAction;
  520. this.load();
  521. },
  522. load: function(){
  523. var position = (this.list.actionArea) ? this.list.actionArea.getPosition(this.app.content) : this.list.itemArea.getPosition(this.app.content);
  524. var size = this.app.content.getSize();
  525. var width = size.x*0.9;
  526. if (width>600) width = 600;
  527. var h=0;
  528. Object.each(this.data, function(v, k){
  529. if ((this.list.data.readonly && this.list.data.readonly.indexOf(k)==-1) || !this.list.data.readonly) {
  530. var t = typeOf(v);
  531. switch (t) {
  532. case "string":
  533. h += 80;
  534. break;
  535. case "object":
  536. h += 180;
  537. break;
  538. default:
  539. h += 80;
  540. }
  541. }
  542. }.bind(this));
  543. //var i = Object.keys(this.data).length;
  544. var height = h+80;
  545. //var height = size.y*0.9;
  546. var x = (size.x-width)/2;
  547. var y = (size.y-height)/2;
  548. var _self = this;
  549. MWF.require("MWF.xDesktop.Dialog", function(){
  550. var dlg = new MWF.xDesktop.Dialog({
  551. "title": this.title || this.list.data.lp.action || this.list.data.lp.editAction,
  552. "style": "setting",
  553. "top": y,
  554. "left": x,
  555. "fromTop":position.y,
  556. "fromLeft": position.x,
  557. "width": width,
  558. "height": height,
  559. "html": "",
  560. "maskNode": this.app.content,
  561. "container": this.app.content,
  562. "buttonList": [
  563. {
  564. "text": this.lp.ok,
  565. "action": function(){
  566. _self.save(this);
  567. }
  568. },
  569. {
  570. "text": this.lp.cancel,
  571. "action": function(){this.close();}
  572. }
  573. ]
  574. });
  575. dlg.show();
  576. this.content = new Element("div", {"styles": this.css.explorerContentListEditAreaNode}).inject(dlg.content);
  577. this.inputs = {};
  578. Object.each(this.data, function(v, k){
  579. if ((this.list.data.readonly && this.list.data.readonly.indexOf(k)==-1) || !this.list.data.readonly){
  580. new Element("div", {"styles": this.css.explorerContentListEditTitleNode, "text": this.lp.list[k]}).inject(this.content);
  581. if (typeOf(v)=="string"){
  582. this.inputs[k] = new Element("input", {"styles": this.css.explorerContentListEditInputNode, "value": v}).inject(this.content);
  583. }
  584. if (typeOf(v)=="number"){
  585. this.inputs[k] = new Element("input", {"styles": this.css.explorerContentListEditInputNode, "value": v}).inject(this.content);
  586. }
  587. if (typeOf(v)=="object"){
  588. var mapListNode = new Element("div", {"styles": this.css.explorerContentListEditMapNode}).inject(this.content);
  589. MWF.require("MWF.widget.Maplist", function(){
  590. var mList = new MWF.widget.Maplist(mapListNode, {"title": this.lp.list[k], "style": "setting"});
  591. mList.load(v);
  592. this.inputs[k] = mList;
  593. }.bind(this));
  594. }
  595. }
  596. }.bind(this));
  597. //setupModule = new MWF.xApplication.AppMarket.Module.Setup(this, dlg);
  598. }.bind(this));
  599. },
  600. save: function(dlg){
  601. var keys = Object.keys(this.inputs);
  602. var values = {};
  603. var flag = true;
  604. Object.each(this.inputs, function(input, k){
  605. if ((this.list.data.readonly && this.list.data.readonly.indexOf(k)==-1) || !this.list.data.readonly){
  606. var value = (typeOf(input)=="element") ? input.get("value") : input.getValue();
  607. if (!value){
  608. flag = false;
  609. this.app.notice(this.lp.pleaseInput+this.lp.list[keys[i]], "error");
  610. return false;
  611. }else{
  612. values[k] = value;
  613. }
  614. }
  615. }.bind(this));
  616. if (flag){
  617. Object.each(this.data, function(v, k){
  618. if (typeOf(this.data[k])=="number"){
  619. this.data[k] = values[k].toFloat();
  620. }else{
  621. this.data[k] = values[k] || v;
  622. }
  623. }.bind(this));
  624. if (this.saveAction) this.saveAction(this.data);
  625. dlg.close();
  626. }
  627. }
  628. });
  629. MWF.xApplication.Setting.Document.List.Item = new Class({
  630. initialize: function(list, data){
  631. this.list = list;
  632. this.explorer = this.list.explorer;
  633. this.app = this.explorer.app;
  634. this.lp = this.app.lp;
  635. this.content = this.list.itemArea;
  636. this.actions = this.app.actions;
  637. this.css = this.app.css;
  638. this.data = data;
  639. this.isSelected = false;
  640. this.load();
  641. },
  642. load: function(){
  643. this.itemArea = new Element("div", {"styles": this.css.explorerContentListActionAreaNode}).inject(this.content);
  644. this.itemIconArea = new Element("div", {"styles": this.css.explorerContentListItemIconAreaNode}).inject(this.itemArea);
  645. this.itemIcon = new Element("div", {"styles": this.css.explorerContentListItemIconNode}).inject(this.itemIconArea);
  646. this.itemTextArea = new Element("div", {"styles": this.css.explorerContentListActionTextAreaNode}).inject(this.itemArea);
  647. if (this.list.data.iconData){
  648. this.itemArea.setStyles(this.css.explorerContentListActionAreaNode_img);
  649. this.itemIconArea.setStyles(this.css.explorerContentListItemIconAreaNode_img);
  650. this.img = new Element("img", {"src": "data:image/png;base64,"+this.list.data.iconData}).inject(this.itemIcon);
  651. }else{
  652. this.itemIcon.setStyle("background", "url("+this.app.path+this.app.options.style+"/icon/"+this.list.data.icon+") no-repeat center center");
  653. }
  654. var t = this.list.data.itemTitle;
  655. var regexp = /\{.+?\}/g;
  656. var r = t.match(regexp);
  657. if(r){
  658. if (r.length){
  659. for (var i=0; i<r.length; i++){
  660. var text = r[i].substr(0,r[i].lastIndexOf("}"));
  661. text = text.substr(text.indexOf("{")+1,text.length);
  662. var value = this.data[text];
  663. var reg = new RegExp("\\{"+text+"\\}", "g");
  664. t = t.replace(reg,value);
  665. }
  666. }
  667. }
  668. this.itemTextArea.set("text", t);
  669. var _self = this;
  670. this.itemArea.addEvents({
  671. "mouseover": function(){if (!_self.isSelected) this.setStyles(_self.css.explorerContentListActionAreaNode_over);},
  672. "mouseout": function(){if (!_self.isSelected) this.setStyles(_self.css.explorerContentListActionAreaNode);},
  673. "mousedown": function(){if (!_self.isSelected) this.setStyles(_self.css.explorerContentListActionAreaNode_down);},
  674. "mouseup": function(){if (!_self.isSelected) this.setStyles(_self.css.explorerContentListActionAreaNode_over);},
  675. "click": function(){if (!_self.isSelected) _self.clickItem(this);}
  676. });
  677. },
  678. clickItem: function(){
  679. debugger;
  680. this.list.items.each(function(item){
  681. if (item.isSelected) item.unSelected();
  682. }.bind(this));
  683. if ((this.list.type != "object") && this.list.data.lp.action){
  684. this.itemArea.setStyles(this.css.explorerContentListActionAreaNode_selected);
  685. this.isSelected = true;
  686. this.createAction();
  687. }else{
  688. this.edit();
  689. }
  690. },
  691. unSelected: function(){
  692. this.itemArea.setStyles(this.css.explorerContentListActionAreaNode);
  693. if (this.actionArea) this.actionArea.setStyle("display", "none");
  694. this.isSelected = false;
  695. },
  696. createAction: function(){
  697. if (!this.actionArea){
  698. this.actionArea = new Element("div", {"styles": this.css.explorerContentListItemActionAreaNode}).inject(this.itemArea);
  699. this.createActionButton(this.lp.delete, function(button, e){
  700. var _self = this;
  701. this.app.confirm("infor", e, this.lp.deleteItem, this.lp.deleteItemInfor, 400, 150, function(){
  702. _self.deleteItem();
  703. this.close();
  704. }, function(){this.close()});
  705. }.bind(this));
  706. this.createActionButton(this.lp.edit, function(button, e){
  707. this.edit();
  708. }.bind(this));
  709. }else{
  710. this.actionArea.setStyle("display", "block");
  711. }
  712. },
  713. edit: function(){
  714. new MWF.xApplication.Setting.Document.List.ItemEditor(this.list, this.data, function(data){
  715. this.list.save(data);
  716. }.bind(this), this.list.data.lp.editAction);
  717. },
  718. createActionButton: function(text, action){
  719. var button = new Element("div", {"styles": this.css.explorerContentListItemActionNode, "text": text}).inject(this.actionArea);
  720. button.addEvents({
  721. "click": function(e){
  722. if (action) action(button, e);
  723. }.bind(this),
  724. "mouseover": function(){this.setStyle("border", "1px solid #999999");},
  725. "mouseout": function(){this.setStyle("border", "1px solid #eeeeee");}
  726. });
  727. },
  728. deleteItem: function(){
  729. this.list.data.value.erase(this.data);
  730. this.list.save();
  731. this.destroy();
  732. },
  733. destroy: function(){
  734. this.itemArea.destroy();
  735. MWF.release(this);
  736. }
  737. });