Document.js 40 KB

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