ElCarouselContent.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. var obj = Object.clone(this.tree.nodejson);
  123. if (!this.data.children) this.data.children = [];
  124. this.data.children.push(obj);
  125. var treeNode = this.appendChild(obj);
  126. if (!this.options.expand) this.tree.expandOrCollapseNode(this);
  127. treeNode.selectNode();
  128. treeNode.showItemAction();
  129. treeNode.editItemProperties();
  130. },
  131. createItemActionNode: function(){
  132. this.actionNode = new Element("div", {
  133. "styles": this.tree.css.itemActionNode
  134. }).inject(this.itemNode);
  135. var deleteAction = new Element("div", {
  136. "styles": this.tree.css.itemDeleteActionNode,
  137. "title": o2.LP.process.formAction["delete"],
  138. "events": {
  139. "click": function(e){
  140. this.deleteItem(e);
  141. e.stopPropagation();
  142. }.bind(this)
  143. }
  144. }).inject(this.actionNode);
  145. },
  146. copyStyles: function(from){
  147. var json = this.data.styles;
  148. Object.each(from, function(style, key){
  149. json[key] = style;
  150. }.bind(this));
  151. },
  152. removeStyles: function(from){
  153. var json = this.data.styles;
  154. Object.each(from, function(style, key){
  155. if (json[key] && json[key]==style){
  156. delete json[key];
  157. }
  158. }.bind(this));
  159. },
  160. getLevelName: function(){
  161. var parentTextList = [];
  162. var parent = this;
  163. while (parent){
  164. parentTextList.push( parent.data.type==="text" ? "文本" : "图片");
  165. parent = parent.parentNode;
  166. }
  167. return parentTextList.reverse().join(".");
  168. },
  169. editItemProperties: function(){
  170. var defaultStyles = {
  171. "img": {
  172. "height": "100%",
  173. "width":"100%"
  174. },
  175. "text": {
  176. "line-height":"30px",
  177. "height": "30px",
  178. "width": "100%",
  179. "text-align": "center",
  180. "position": "absolute",
  181. "bottom":"0px",
  182. "left":"0px",
  183. "color":"#fff",
  184. "background": "rgba(104, 104, 104, 0.5)"
  185. }
  186. };
  187. if (this.tree.currentEditNode!=this){
  188. if (this.tree.currentEditNode) this.tree.currentEditNode.completeItemProperties();
  189. this.itemNode.setStyle("background", "#DDD");
  190. if (!this.propertyArea){
  191. this.propertyArea = new Element("div", {
  192. style : "border-bottom:1px solid #666"
  193. }).inject(this.itemNode, "after");
  194. this.propertyTable = new Element("table", {
  195. "width": "100%",
  196. "border": "0",
  197. "cellpadding":"5",
  198. "cellspacing":"0",
  199. "class": "editTable"
  200. }).inject(this.propertyArea);
  201. tr = new Element("tr").inject(this.propertyTable);
  202. var td = new Element("td", { text: "类型" }).inject(tr);
  203. td = new Element("td").inject(tr);
  204. var div = new Element( "div").inject(td);
  205. var radio_type_1 = new Element( "input", {
  206. "type" : "radio",
  207. "checked" : this.data.type === "img",
  208. "events" : {
  209. "click": function () {
  210. this.data.type = "img";
  211. radio_type_2.checked = false;
  212. this.setTitle();
  213. this.srcScriptTr.setStyle("display", "");
  214. this.textScriptTr.setStyle("display", "none");
  215. this.removeStyles( defaultStyles.text );
  216. this.copyStyles( defaultStyles.img );
  217. this.maplist.reload(this.data.styles);
  218. this.tree.editor.fireEvent("change", [{
  219. compareName: "."+this.getLevelName() + ".type"
  220. }]);
  221. }.bind(this)
  222. }
  223. }).inject( div );
  224. new Element( "span", { "text" : "图片" }).inject(div);
  225. var radio_type_2 = new Element( "input", {
  226. "type" : "radio",
  227. "checked" : this.data.type === "text",
  228. "events" : {
  229. "click": function () {
  230. this.data.type = "text";
  231. radio_type_1.checked = false;
  232. this.setTitle();
  233. this.srcScriptTr.setStyle("display", "none");
  234. this.textScriptTr.setStyle("display", "");
  235. this.removeStyles( defaultStyles.img );
  236. this.copyStyles( defaultStyles.text );
  237. this.maplist.reload(this.data.styles);
  238. this.tree.editor.fireEvent("change", [{
  239. compareName: "."+this.getLevelName() + ".type"
  240. }]);
  241. }.bind(this)
  242. }
  243. }).inject( div );
  244. new Element( "span", { "text" : "文本" }).inject(div);
  245. // var tr = new Element("tr").inject(this.propertyTable);
  246. // var td = new Element("td", { text: "数据路径" }).inject(tr);
  247. // td = new Element("td").inject(tr);
  248. // this.pathInput = new Element("input", {
  249. // value: this.data.dataPath || "",
  250. // placeholder: "如: title",
  251. // events: {
  252. // blur: function () {
  253. // this.data.dataPath = this.pathInput.get("value");
  254. // // this.textNode.getElement("div").set("text", this.data.dataPath);
  255. // }.bind(this)
  256. // }
  257. // }).inject(td);
  258. //styles
  259. if( !Object.keys(this.data.styles).length ){
  260. this.data.styles = Object.clone( defaultStyles[ this.data.type ] );
  261. }
  262. var tr = new Element("tr").inject(this.propertyTable);
  263. td = new Element("td", { "colspan": "2" }).inject(tr);
  264. MWF.require("MWF.widget.Maplist", function() {
  265. var maplist = this.maplist = new MWF.widget.Maplist(td, {
  266. "title": "样式",
  267. "collapse": false,
  268. "onChange": function () {
  269. this.data.styles = maplist.toJson();
  270. this.tree.editor.fireEvent("change", [{
  271. compareName: "."+this.getLevelName() + ".styles"
  272. }]);
  273. }.bind(this),
  274. "onDelete": function (key) {
  275. if (this.data.styles && this.data.styles[key]) {
  276. delete this.data.styles[key];
  277. }
  278. this.tree.editor.fireEvent("change", [{
  279. compareName: "."+this.getLevelName() + ".styles"
  280. }]);
  281. }.bind(this),
  282. "isProperty": false
  283. });
  284. maplist.load(this.data.styles);
  285. }.bind(this));
  286. //srcScript
  287. var tr = new Element("div").inject(this.propertyArea);
  288. this.srcScriptTr = tr;
  289. new Element("div", {
  290. "text" : "通过this.event可以获得当前条目的数据,最终返回图片资源地址文本。" +
  291. "系统通用图片获取方法为o2.xDesktop.getImageSrc(imgId);该方法可用于图片编辑器、html编辑上传的图片;附件、资源文件不可以用本方法。"
  292. }).inject( tr );
  293. MWF.require("MWF.widget.ScriptArea", function(){
  294. this.srcScriptEditor = new MWF.widget.ScriptArea(tr, {
  295. "title": "图片资源(src)脚本",
  296. "isbind": false,
  297. "mode": "javascript",
  298. "maxObj": this.tree.editor.options.maxObj,
  299. "onChange": function(){
  300. var json = this.srcScriptEditor.toJson();
  301. this.data.srcScript.code = json.code;
  302. this.tree.editor.fireEvent("change", [{
  303. compareName: "."+this.getLevelName() + ".srcScript.code"
  304. }]);
  305. //this.data[name].html = json.html;
  306. }.bind(this),
  307. "onSave": function(){
  308. //this.designer.saveForm();
  309. }.bind(this),
  310. "style": "default",
  311. "runtime": "web"
  312. });
  313. this.srcScriptEditor.load(this.data.srcScript);
  314. }.bind(this));
  315. if( this.data.type !== "img"){
  316. this.srcScriptTr.hide();
  317. }
  318. //textScript
  319. if( !this.data.textScript )this.data.textScript = {
  320. "code": "",
  321. "html": ""
  322. };
  323. var tr = new Element("div").inject(this.propertyArea);
  324. this.textScriptTr = tr;
  325. new Element("div", {
  326. "text" : "通过this.event可以获得当前条目的数据,最终返回图片文本内容文本。"
  327. }).inject( tr );
  328. MWF.require("MWF.widget.ScriptArea", function(){
  329. this.textScriptEditor = new MWF.widget.ScriptArea(tr, {
  330. "title": "文本内容脚本",
  331. "isbind": false,
  332. "mode": "javascript",
  333. "maxObj": this.tree.editor.options.maxObj,
  334. "onChange": function(){
  335. var json = this.textScriptEditor.toJson();
  336. this.data.textScript.code = json.code;
  337. this.tree.editor.fireEvent("change", [{
  338. compareName: "."+this.getLevelName() + ".textScript.code"
  339. }]);
  340. //this.data[name].html = json.html;
  341. }.bind(this),
  342. "onSave": function(){
  343. //this.designer.saveForm();
  344. }.bind(this),
  345. "style": "default",
  346. "runtime": "web"
  347. });
  348. this.textScriptEditor.load(this.data.textScript);
  349. }.bind(this));
  350. if( this.data.type === "img"){
  351. this.textScriptTr.hide();
  352. }
  353. //clickScript
  354. var tr = new Element("div").inject(this.propertyArea);
  355. new Element("div", {
  356. "text" : "通过this.event[0]可以获得当前条目的数据,通过this.event[1]可获取Event对象。"
  357. }).inject( tr );
  358. MWF.require("MWF.widget.ScriptArea", function(){
  359. this.clickScriptEditor = new MWF.widget.ScriptArea(tr, {
  360. "title": "点击事件脚本",
  361. "isbind": false,
  362. "mode": "javascript",
  363. "maxObj": this.tree.editor.options.maxObj,
  364. "onChange": function(){
  365. var json = this.clickScriptEditor.toJson();
  366. this.data.clickScript.code = json.code;
  367. this.tree.editor.fireEvent("change", [{
  368. compareName: "."+this.getLevelName() + ".clickScript.code"
  369. }]);
  370. //this.data[name].html = json.html;
  371. }.bind(this),
  372. "onSave": function(){
  373. //this.designer.saveForm();
  374. }.bind(this),
  375. "style": "default",
  376. "runtime": "web"
  377. });
  378. this.clickScriptEditor.load(this.data.clickScript);
  379. }.bind(this));
  380. }
  381. this.propertyArea.setStyle("display", "block");
  382. this.propertyArea.scrollIntoView(false);
  383. this.setActionPosition();
  384. this.isEditProperty = true;
  385. this.tree.currentEditNode = this;
  386. }else{
  387. this.completeItemProperties();
  388. }
  389. }
  390. });