Document.js 39 KB

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