Document.js 38 KB

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