SettingIndexUI.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. MWF.xDesktop.requireApp("Setting", "SettingLoginUI", null, false);
  2. MWF.xApplication.Setting.UIIndexDocument = new Class({
  3. Extends: MWF.xApplication.Setting.UILoginDocument,
  4. load: function(){
  5. this.node = new Element("div", {"styles": {"overflow": "hidden", "padding-bottom": "80px"}}).inject(this.contentAreaNode);
  6. this.titleName = new Element("div", {"styles": this.explorer.css.explorerContentTitleNode}).inject(this.node);
  7. this.titleName.set("text", this.lp.ui_indexSetting);
  8. MWF.getJSON("/x_desktop/res/mwf4/package/xDesktop/$Layout/styles.json", function(json){
  9. MWF.UD.getPublicData("indexThemes", function(themesJson){
  10. var init = false;
  11. if (themesJson){
  12. this.enabledThemes = themesJson;
  13. }else{
  14. this.enabledThemes = [];
  15. init = true;
  16. }
  17. json.map(function(item, index){
  18. item.id = item.style;
  19. item.name = "default";
  20. //item.url = "/x_desktop/res/mwf4/package/xDesktop/$Layout/"+item.style;
  21. item.url = item.style;
  22. item.enabled = (!this.enabledThemes.length || this.enabledThemes.indexOf(item.style)!=-1);
  23. if (init) this.enabledThemes.push(item.style);
  24. return item;
  25. }.bind(this));
  26. this.styleList = new MWF.xApplication.Setting.UIIndexDocument.StyleList(this, this.node, json, {
  27. "title": this.lp.ui_index_systemStyle,
  28. "infor": this.lp.ui_index_systemStyle_infor,
  29. "type": "loginStyle",
  30. "onCreateStyle": function(name, css){
  31. this.createStyle(name, css);
  32. }.bind(this)
  33. });
  34. MWF.UD.getPublicData("indexStyleList", function(json){
  35. debugger;
  36. this.indexStyleList = json;
  37. if (!this.indexStyleList) this.indexStyleList = {"styleList": []};
  38. this.styleList = new MWF.xApplication.Setting.UIIndexDocument.StyleList(this, this.node, this.indexStyleList.styleList, {
  39. "title": this.lp.ui_index_customStyle,
  40. "infor": this.lp.ui_index_customStyle_infor,
  41. "actionTitle": this.lp.ui_index_customStyle_Action,
  42. "type": "loginStyle",
  43. "onCreateStyle": function(name, css){
  44. this.createStyle(name, css);
  45. }.bind(this)
  46. });
  47. }.bind(this));
  48. }.bind(this));
  49. }.bind(this));
  50. },
  51. createStyle: function(name, css){
  52. debugger;
  53. var id = (new MWF.widget.UUID()).id;
  54. var listItem = {
  55. "title": name,
  56. "name": "indexStyle_"+id,
  57. "id": "indexStyle_"+id,
  58. "preview": css.desktop.desktop.background,
  59. "enabled": true
  60. };
  61. var styleData = {
  62. "title": name,
  63. "name": "indexStyle_"+id,
  64. "id": "indexStyle_"+id,
  65. "data": css
  66. };
  67. this.indexStyleList.styleList.push(listItem);
  68. MWF.UD.putPublicData("indexStyle_"+id, styleData, function(){
  69. MWF.UD.putPublicData("indexStyleList", this.indexStyleList, {
  70. "success": function(){
  71. this.styleList.addItem(listItem);
  72. }.bind(this),
  73. "failure": function(){
  74. MWF.UD.deletePublicData("indexStyle_"+id);
  75. }.bind(this)
  76. });
  77. }.bind(this));
  78. }
  79. });
  80. MWF.xApplication.Setting.UIIndexDocument.StyleList = new Class({
  81. Extends: MWF.xApplication.Setting.UILoginDocument.StyleList,
  82. addItem: function(item){
  83. this.items.push(new MWF.xApplication.Setting.UIIndexDocument.Item(this, item));
  84. }
  85. });
  86. MWF.xApplication.Setting.UIIndexDocument.Item = new Class({
  87. Extends: MWF.xApplication.Setting.UILoginDocument.Style.Item,
  88. getCss: function(){
  89. var css = null;
  90. if (this.data.url){
  91. var cssDesktopPath = "/x_desktop/res/mwf4/package/xDesktop/$Layout/"+this.data.url+"/css.wcss";
  92. cssDesktopPath = (cssDesktopPath.indexOf("?")!=-1) ? cssDesktopPath+"&v="+COMMON.version : cssDesktopPath+"?v="+COMMON.version;
  93. var cssWindowPath = "/x_desktop/res/mwf4/package/xDesktop/$Window/desktop_"+this.data.url+"/css.wcss";
  94. cssWindowPath = (cssWindowPath.indexOf("?")!=-1) ? cssWindowPath+"&v="+COMMON.version : cssWindowPath+"?v="+COMMON.version;
  95. css = {};
  96. MWF.getJSON(cssDesktopPath, function(json){
  97. css.desktop = json;
  98. }.bind(this), false);
  99. MWF.getJSON(cssWindowPath, function(json){
  100. css.window = json;
  101. }.bind(this), false);
  102. }else{
  103. MWF.UD.getPublicData(this.data.name, function(json){
  104. css = json.data;
  105. }, false);
  106. }
  107. return css;
  108. },
  109. showPreview: function(){
  110. this.styleCss = this.getCss();
  111. this.previewNode = new Element("div.previewNode", {"styles": {
  112. "margin-top": "10px",
  113. "position": "relative"
  114. }}).inject(this.itemArea);
  115. MWF.xDesktop.requireApp("Setting", "preview.Layout", function(){
  116. var layout = new MWF.xApplication.Setting.preview.Layout(this.previewNode, {
  117. styles: {"position": "absolute", "height": "720px", "width": "960px", "box-shadow": "0px 0px 30px #666666"}
  118. });
  119. layout.app = this.app;
  120. layout.css = this.styleCss.desktop;
  121. layout.windowCss = this.styleCss.window;
  122. layout.load();
  123. this.previewMaskNode = new Element("div", {"styles": {"position": "absolute", "top": "0px", "left": "0px"}}).inject(this.previewNode);
  124. var size = layout.node.getSize();
  125. var zidx = layout.node.getStyle("z-index") || 0;
  126. if (MWF.xDesktop.zIndexPool) zidx = MWF.xDesktop.zIndexPool.applyZindex();
  127. this.previewMaskNode.setStyles({"width": ""+size.x+"px", "height": ""+size.y+"px", "z-index": zidx});
  128. this.previewMaskNode.addEvents({
  129. "click": function(e){
  130. window.open("/x_desktop/index.html?style="+this.data.id+"&styletype="+((this.data.name=="default") ? "default" : "custom"));
  131. e.stopPropagation();
  132. }.bind(this),
  133. "mousedown": function(e){e.stopPropagation();},
  134. "mouseup": function(e){e.stopPropagation();}
  135. });
  136. this.previewNode.setStyles({
  137. "transform-origin": "0px 0px",
  138. "transform": "scale(0.4)"
  139. })
  140. }.bind(this));
  141. },
  142. hidePreview: function(){
  143. this.previewMaskNode.destroy();
  144. this.previewNode.getFirst().destroy();
  145. this.previewNode.empty();
  146. this.previewNode.destroy();
  147. this.previewMaskNode = null;
  148. this.previewNode = null;
  149. },
  150. setCurrent: function(e){
  151. if (this.data.enabled){
  152. this.list.document.enabledThemes.erase(this.data.id);
  153. this.setUncurrentStyle();
  154. }else{
  155. this.list.document.enabledThemes.push(this.data.id);
  156. this.setCurrentStyle()
  157. }
  158. MWF.UD.putPublicData("indexThemes", this.list.document.enabledThemes);
  159. MWF.UD.putPublicData("indexStyleList", this.list.document.indexStyleList);
  160. e.stopPropagation();
  161. },
  162. setUncurrentStyle: function(){
  163. this.data.enabled = false;
  164. this.checkIcon.setStyles(this.css.explorerContentListNotCheckIconAreaNode);
  165. this.checkIcon.set("title", this.lp.ui_index_disabled);
  166. },
  167. setCurrentStyle: function(nosave){
  168. this.data.enabled = true;
  169. this.checkIcon.setStyles(this.css.explorerContentListCheckIconAreaNode);
  170. this.checkIcon.set("title", this.lp.ui_index_enabled);
  171. },
  172. createNewCustomStyleData: function(dlg){
  173. var name = dlg.content.getElement("input").get("value");
  174. if (!name){
  175. this.app.notice(ui_login_customStyle_newName_empty, "error");
  176. return false;
  177. }else{
  178. var css = this.getCss();
  179. var newCss = Object.clone(css);
  180. this.list.fireEvent("createStyle", [name, newCss]);
  181. dlg.close();
  182. }
  183. },
  184. editStyle: function(){
  185. this.editor = new MWF.xApplication.Setting.UIIndexDocument.Editor(this);
  186. },
  187. deleteStyleData: function(){
  188. this.list.document.indexStyleList.styleList.erase(this.data);
  189. MWF.UD.deletePublicData(this.data.id, function(){
  190. MWF.UD.putPublicData("indexStyleList", this.list.document.indexStyleList, function(){
  191. this.list.items.erase(this);
  192. this.destroy();
  193. }.bind(this));
  194. }.bind(this))
  195. }
  196. });
  197. MWF.xApplication.Setting.UIIndexDocument.Editor = new Class({
  198. Extends: MWF.xApplication.Setting.UILoginDocument.Style.Editor,
  199. createCssEditor: function(){
  200. var _self = this;
  201. MWF.require("MWF.widget.Maplist", function(){
  202. Object.each(this.styleCss.desktop, function(v, k){
  203. var mapListNode = new Element("div", {"styles": this.css.explorerContentStyleEditMapNode}).inject(this.editorArea);
  204. var mList = new MWF.widget.Maplist.Style(mapListNode, {"title": "desktop."+k, "style": "styleEditor",
  205. "onChange": function(){
  206. _self.styleCss.desktop[k] = this.toJson();
  207. if (k=="desktop"){
  208. _self.item.data.preview = _self.styleCss.desktop[k].background;
  209. MWF.UD.putPublicData("indexStyleList", _self.item.list.document.indexStyleList);
  210. }
  211. _self.showPreview();
  212. var o = {
  213. "name": _self.item.data.name,
  214. "title": _self.item.data.title,
  215. "id": _self.item.data.id,
  216. "data": _self.styleCss
  217. };
  218. MWF.UD.putPublicData(_self.item.data.id, o);
  219. }
  220. });
  221. mList.app = this.app;
  222. mList.load(v);
  223. }.bind(this));
  224. Object.each(this.styleCss.window, function(v, k){
  225. var mapListNode = new Element("div", {"styles": this.css.explorerContentStyleEditMapNode}).inject(this.editorArea);
  226. var mList = new MWF.widget.Maplist.Style(mapListNode, {"title": "window."+k, "style": "styleEditor",
  227. "onChange": function(){
  228. _self.styleCss.window[k] = this.toJson();
  229. _self.showPreview();
  230. var o = {
  231. "name": _self.item.data.name,
  232. "title": _self.item.data.title,
  233. "id": _self.item.data.id,
  234. "data": _self.styleCss
  235. };
  236. MWF.UD.putPublicData(_self.item.data.id, o);
  237. }
  238. });
  239. mList.app = this.app;
  240. mList.load(v);
  241. }.bind(this));
  242. }.bind(this));
  243. },
  244. showPreview: function(){
  245. this.previewArea.empty();
  246. this.previewNode = new Element("div", {"styles": {"position": "relative", "height": "216px"}}).inject(this.previewArea);
  247. //this.styleCss = this.getCss();
  248. // this.previewNode = new Element("div.previewNode", {"styles": {
  249. // "margin-top": "10px",
  250. // "position": "relative"
  251. // }}).inject(this.itemArea);
  252. MWF.xDesktop.requireApp("Setting", "preview.Layout", function(){
  253. var layout = new MWF.xApplication.Setting.preview.Layout(this.previewNode, {
  254. styles: {"position": "absolute", "height": "720px", "width": "960px", "box-shadow": "0px 0px 30px #666666"}
  255. });
  256. layout.app = this.app;
  257. layout.css = this.styleCss.desktop;
  258. layout.windowCss = this.styleCss.window;
  259. layout.load();
  260. this.previewMaskNode = new Element("div", {"styles": {"position": "absolute", "top": "0px", "left": "0px"}}).inject(this.previewNode);
  261. var size = layout.node.getSize();
  262. var zidx = layout.node.getStyle("z-index") || 0;
  263. if (MWF.xDesktop.zIndexPool) zidx = MWF.xDesktop.zIndexPool.applyZindex();
  264. this.previewMaskNode.setStyles({"width": ""+size.x+"px", "height": ""+size.y+"px", "z-index": zidx});
  265. this.previewMaskNode.addEvents({
  266. "click": function(e){
  267. window.open("/x_desktop/index.html?style="+this.item.data.id+"&styletype="+((this.item.data.name=="default") ? "default" : "custom"));
  268. e.stopPropagation();
  269. }.bind(this),
  270. "mousedown": function(e){e.stopPropagation();},
  271. "mouseup": function(e){e.stopPropagation();}
  272. });
  273. this.previewNode.setStyles({
  274. "transform-origin": "0px 0px",
  275. "transform": "scale(0.6)"
  276. })
  277. }.bind(this));
  278. }
  279. });