Document.js 41 KB

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