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