Document.js 39 KB

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