ElCarouselContent.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. // o2.widget = o2.widget || {};
  2. o2.require("o2.widget.Common", null, false);
  3. // o2.require("o2.widget.Tree", null, false);
  4. o2.requireApp("process.FormDesigner", "widget.ElTreeEditor", null, false);
  5. MWF.xApplication.process.FormDesigner.widget.ElCarouselContent = new Class({
  6. Extends: MWF.xApplication.process.FormDesigner.widget.ElTreeEditor,
  7. initialize: function(node, options){
  8. this.setOptions(options);
  9. this.node = $(node);
  10. this.path = "../x_component_process_FormDesigner/widget/$ElTreeEditor/";
  11. this.cssPath = this.path+this.options.style+"/css.wcss";
  12. this._loadCss();
  13. this.container = new Element("div");
  14. },
  15. createContent: function(content){
  16. this.contentNode = new Element("div", {
  17. "styles": this.css.contentNode
  18. }).inject(this.container);
  19. this.data = content;
  20. this.resizeContentNodeSize();
  21. this.tree = new MWF.xApplication.process.FormDesigner.widget.ElCarouselContent.Tree(this, this.contentNode, {"style": "editor"});
  22. this.tree.data = this.data;
  23. this.tree.load();
  24. },
  25. addTreeNode: function(){
  26. if (this.tree) {
  27. var obj = Object.clone(this.tree.nodejson);
  28. this.data.push(obj);
  29. var treeNode = this.tree.appendChild(obj);
  30. //if (!this.options.expand) this.tree.expandOrCollapseNode(this);
  31. treeNode.selectNode();
  32. treeNode.showItemAction();
  33. treeNode.editItemProperties();
  34. this.fireEvent("change", [{
  35. compareName: " [addSub]",
  36. force: true
  37. }]);
  38. }
  39. },
  40. });
  41. MWF.xApplication.process.FormDesigner.widget.ElCarouselContent.Tree = new Class({
  42. Extends: MWF.xApplication.process.FormDesigner.widget.ElTreeEditor.Tree,
  43. nodejson: {
  44. "type": "img",
  45. "dataPath": "",
  46. "styles": {},
  47. "srcScript": {
  48. "code": "",
  49. "html": ""
  50. },
  51. "textScript": {
  52. "code": "",
  53. "html": ""
  54. },
  55. "clickScript": {
  56. "code": "",
  57. "html": ""
  58. }
  59. },
  60. appendChild: function(obj){
  61. var treeNode = new MWF.xApplication.process.FormDesigner.widget.ElCarouselContent.Tree.Node(this, obj);
  62. if (this.children.length){
  63. treeNode.previousSibling = this.children[this.children.length-1];
  64. treeNode.previousSibling.nextSibling = treeNode;
  65. }else{
  66. this.firstChild = treeNode;
  67. }
  68. treeNode.level = 0;
  69. treeNode.load();
  70. treeNode.node.inject(this.node);
  71. this.children.push(treeNode);
  72. return treeNode;
  73. }
  74. });
  75. MWF.xApplication.process.FormDesigner.widget.ElCarouselContent.Tree.Node = new Class({
  76. Extends: MWF.xApplication.process.FormDesigner.widget.ElTreeEditor.Tree.Node,
  77. options: {
  78. "expand": true
  79. },
  80. getTitle: function(){
  81. if( this.data.type === "img" ){
  82. return "图片";
  83. }else if( this.data.type === "text" ){
  84. return "文本";
  85. }else{
  86. return "";
  87. }
  88. },
  89. setTitle : function(){
  90. this.textDivNode.set("text", this.getTitle());
  91. },
  92. createTextNode: function(){
  93. this.textNode = new Element("td",{
  94. "styles": this.tree.css.textNode
  95. }).inject(this.nodeArea);
  96. var textDivNode = this.textDivNode = new Element("div", {
  97. "styles": {"display": "inline-block"},
  98. "text": this.getTitle()
  99. });
  100. textDivNode.setStyles(this.tree.css.textDivNode);
  101. textDivNode.addEvent("click", function(e){
  102. this.clickNode(e);
  103. }.bind(this));
  104. textDivNode.inject(this.textNode);
  105. },
  106. selectNode: function(){
  107. this.tree.fireEvent("beforeSelect", [this]);
  108. if (this.tree.currentNode){
  109. this.tree.currentNode.fireEvent("unselect");
  110. var textDivNode = this.tree.currentNode.textNode.getElement("div");
  111. textDivNode.setStyles(this.tree.css.textDivNode);
  112. }
  113. var textDivNode = this.textNode.getElement("div");
  114. // textDivNode.setStyles(this.tree.css.textDivNodeSelected);
  115. this.tree.currentNode = this;
  116. this.tree.fireEvent("afterSelect", [this]);
  117. },
  118. clickNode: function(e){
  119. this.selectNode(e);
  120. },
  121. addChild: function(){
  122. debugger;
  123. var obj = Object.clone(this.tree.nodejson);
  124. if (!this.data.children) this.data.children = [];
  125. this.data.children.push(obj);
  126. var treeNode = this.appendChild(obj);
  127. if (!this.options.expand) this.tree.expandOrCollapseNode(this);
  128. treeNode.selectNode();
  129. treeNode.showItemAction();
  130. treeNode.editItemProperties();
  131. },
  132. createItemActionNode: function(){
  133. this.actionNode = new Element("div", {
  134. "styles": this.tree.css.itemActionNode
  135. }).inject(this.itemNode);
  136. var deleteAction = new Element("div", {
  137. "styles": this.tree.css.itemDeleteActionNode,
  138. "title": o2.LP.process.formAction["delete"],
  139. "events": {
  140. "click": function(e){
  141. this.deleteItem(e);
  142. e.stopPropagation();
  143. }.bind(this)
  144. }
  145. }).inject(this.actionNode);
  146. },
  147. copyStyles: function(from){
  148. var json = this.data.styles;
  149. Object.each(from, function(style, key){
  150. json[key] = style;
  151. }.bind(this));
  152. },
  153. removeStyles: function(from){
  154. var json = this.data.styles;
  155. Object.each(from, function(style, key){
  156. if (json[key] && json[key]==style){
  157. delete json[key];
  158. }
  159. }.bind(this));
  160. },
  161. getLevelName: function(){
  162. var parentTextList = [];
  163. var parent = this;
  164. while (parent){
  165. parentTextList.push( parent.data.type==="text" ? "文本" : "图片");
  166. parent = parent.parentNode;
  167. }
  168. return parentTextList.reverse().join(".");
  169. },
  170. editItemProperties: function(){
  171. var defaultStyles = {
  172. "img": {
  173. "height": "100%",
  174. "width":"100%"
  175. },
  176. "text": {
  177. "line-height":"30px",
  178. "height": "30px",
  179. "width": "100%",
  180. "text-align": "center",
  181. "position": "absolute",
  182. "bottom":"0px",
  183. "left":"0px",
  184. "color":"#fff",
  185. "background": "rgba(104, 104, 104, 0.5)"
  186. }
  187. };
  188. if (this.tree.currentEditNode!=this){
  189. if (this.tree.currentEditNode) this.tree.currentEditNode.completeItemProperties();
  190. this.itemNode.setStyle("background", "#DDD");
  191. if (!this.propertyArea){
  192. this.propertyArea = new Element("div", {
  193. style : "border-bottom:1px solid #666"
  194. }).inject(this.itemNode, "after");
  195. this.propertyTable = new Element("table", {
  196. "width": "100%",
  197. "border": "0",
  198. "cellpadding":"5",
  199. "cellspacing":"0",
  200. "class": "editTable"
  201. }).inject(this.propertyArea);
  202. tr = new Element("tr").inject(this.propertyTable);
  203. var td = new Element("td", { text: "类型" }).inject(tr);
  204. td = new Element("td").inject(tr);
  205. var div = new Element( "div").inject(td);
  206. var radio_type_1 = new Element( "input", {
  207. "type" : "radio",
  208. "checked" : this.data.type === "img",
  209. "events" : {
  210. "click": function () {
  211. this.data.type = "img";
  212. radio_type_2.checked = false;
  213. this.setTitle();
  214. this.srcScriptTr.setStyle("display", "");
  215. this.textScriptTr.setStyle("display", "none");
  216. this.removeStyles( defaultStyles.text );
  217. this.copyStyles( defaultStyles.img );
  218. this.maplist.reload(this.data.styles);
  219. this.tree.editor.fireEvent("change", [{
  220. compareName: "."+this.getLevelName() + ".type"
  221. }]);
  222. }.bind(this)
  223. }
  224. }).inject( div );
  225. new Element( "span", { "text" : "图片" }).inject(div);
  226. var radio_type_2 = new Element( "input", {
  227. "type" : "radio",
  228. "checked" : this.data.type === "text",
  229. "events" : {
  230. "click": function () {
  231. debugger;
  232. this.data.type = "text";
  233. radio_type_1.checked = false;
  234. this.setTitle();
  235. this.srcScriptTr.setStyle("display", "none");
  236. this.textScriptTr.setStyle("display", "");
  237. this.removeStyles( defaultStyles.img );
  238. this.copyStyles( defaultStyles.text );
  239. this.maplist.reload(this.data.styles);
  240. this.tree.editor.fireEvent("change", [{
  241. compareName: "."+this.getLevelName() + ".type"
  242. }]);
  243. }.bind(this)
  244. }
  245. }).inject( div );
  246. new Element( "span", { "text" : "文本" }).inject(div);
  247. // var tr = new Element("tr").inject(this.propertyTable);
  248. // var td = new Element("td", { text: "数据路径" }).inject(tr);
  249. // td = new Element("td").inject(tr);
  250. // this.pathInput = new Element("input", {
  251. // value: this.data.dataPath || "",
  252. // placeholder: "如: title",
  253. // events: {
  254. // blur: function () {
  255. // this.data.dataPath = this.pathInput.get("value");
  256. // // this.textNode.getElement("div").set("text", this.data.dataPath);
  257. // }.bind(this)
  258. // }
  259. // }).inject(td);
  260. //styles
  261. debugger;
  262. if( !Object.keys(this.data.styles).length ){
  263. this.data.styles = Object.clone( defaultStyles[ this.data.type ] );
  264. }
  265. var tr = new Element("tr").inject(this.propertyTable);
  266. td = new Element("td", { "colspan": "2" }).inject(tr);
  267. MWF.require("MWF.widget.Maplist", function() {
  268. var maplist = this.maplist = new MWF.widget.Maplist(td, {
  269. "title": "样式",
  270. "collapse": false,
  271. "onChange": function () {
  272. this.data.styles = maplist.toJson();
  273. this.tree.editor.fireEvent("change", [{
  274. compareName: "."+this.getLevelName() + ".styles"
  275. }]);
  276. }.bind(this),
  277. "onDelete": function (key) {
  278. if (this.data.styles && this.data.styles[key]) {
  279. delete this.data.styles[key];
  280. }
  281. this.tree.editor.fireEvent("change", [{
  282. compareName: "."+this.getLevelName() + ".styles"
  283. }]);
  284. }.bind(this),
  285. "isProperty": false
  286. });
  287. maplist.load(this.data.styles);
  288. }.bind(this));
  289. //srcScript
  290. var tr = new Element("div").inject(this.propertyArea);
  291. this.srcScriptTr = tr;
  292. new Element("div", {
  293. "text" : "通过this.event可以获得当前条目的数据,最终返回图片资源地址文本。" +
  294. "系统通用图片获取方法为o2.xDesktop.getImageSrc(imgId);该方法可用于图片编辑器、html编辑上传的图片;附件、资源文件不可以用本方法。"
  295. }).inject( tr );
  296. MWF.require("MWF.widget.ScriptArea", function(){
  297. this.srcScriptEditor = new MWF.widget.ScriptArea(tr, {
  298. "title": "图片资源(src)脚本",
  299. "isbind": false,
  300. "mode": "javascript",
  301. "maxObj": this.tree.editor.options.maxObj,
  302. "onChange": function(){
  303. var json = this.srcScriptEditor.toJson();
  304. this.data.srcScript.code = json.code;
  305. this.tree.editor.fireEvent("change", [{
  306. compareName: "."+this.getLevelName() + ".srcScript.code"
  307. }]);
  308. //this.data[name].html = json.html;
  309. }.bind(this),
  310. "onSave": function(){
  311. //this.designer.saveForm();
  312. }.bind(this),
  313. "style": "default",
  314. "runtime": "web"
  315. });
  316. this.srcScriptEditor.load(this.data.srcScript);
  317. }.bind(this));
  318. if( this.data.type !== "img"){
  319. this.srcScriptTr.hide();
  320. }
  321. //textScript
  322. if( !this.data.textScript )this.data.textScript = {
  323. "code": "",
  324. "html": ""
  325. };
  326. var tr = new Element("div").inject(this.propertyArea);
  327. this.textScriptTr = tr;
  328. new Element("div", {
  329. "text" : "通过this.event可以获得当前条目的数据,最终返回图片文本内容文本。"
  330. }).inject( tr );
  331. MWF.require("MWF.widget.ScriptArea", function(){
  332. this.textScriptEditor = new MWF.widget.ScriptArea(tr, {
  333. "title": "文本内容脚本",
  334. "isbind": false,
  335. "mode": "javascript",
  336. "maxObj": this.tree.editor.options.maxObj,
  337. "onChange": function(){
  338. var json = this.textScriptEditor.toJson();
  339. this.data.textScript.code = json.code;
  340. this.tree.editor.fireEvent("change", [{
  341. compareName: "."+this.getLevelName() + ".textScript.code"
  342. }]);
  343. //this.data[name].html = json.html;
  344. }.bind(this),
  345. "onSave": function(){
  346. //this.designer.saveForm();
  347. }.bind(this),
  348. "style": "default",
  349. "runtime": "web"
  350. });
  351. this.textScriptEditor.load(this.data.textScript);
  352. }.bind(this));
  353. if( this.data.type === "img"){
  354. this.textScriptTr.hide();
  355. }
  356. //clickScript
  357. var tr = new Element("div").inject(this.propertyArea);
  358. new Element("div", {
  359. "text" : "通过this.event[0]可以获得当前条目的数据,通过this.event[1]可获取Event对象。"
  360. }).inject( tr );
  361. MWF.require("MWF.widget.ScriptArea", function(){
  362. this.clickScriptEditor = new MWF.widget.ScriptArea(tr, {
  363. "title": "点击事件脚本",
  364. "isbind": false,
  365. "mode": "javascript",
  366. "maxObj": this.tree.editor.options.maxObj,
  367. "onChange": function(){
  368. var json = this.clickScriptEditor.toJson();
  369. this.data.clickScript.code = json.code;
  370. this.tree.editor.fireEvent("change", [{
  371. compareName: "."+this.getLevelName() + ".clickScript.code"
  372. }]);
  373. //this.data[name].html = json.html;
  374. }.bind(this),
  375. "onSave": function(){
  376. //this.designer.saveForm();
  377. }.bind(this),
  378. "style": "default",
  379. "runtime": "web"
  380. });
  381. this.clickScriptEditor.load(this.data.clickScript);
  382. }.bind(this));
  383. }
  384. this.propertyArea.setStyle("display", "block");
  385. this.propertyArea.scrollIntoView(false);
  386. this.setActionPosition();
  387. this.isEditProperty = true;
  388. this.tree.currentEditNode = this;
  389. }else{
  390. this.completeItemProperties();
  391. }
  392. }
  393. });