Dialog.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  2. MWF.require("MWF.widget.ImageClipper", null, false);
  3. MWF.xApplication.MinderEditor.HyperLinkForm = new Class({
  4. Extends: MPopupForm,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "report",
  8. "width": 700,
  9. //"height": 300,
  10. "height": "300",
  11. "hasTop": true,
  12. "hasIcon": false,
  13. "draggable": true,
  14. "title" : "链接"
  15. },
  16. _createTableContent: function () {
  17. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  18. "<tr><td styles='formTableTitle' lable='url' width='20%'></td>" +
  19. " <td styles='formTableValue14' item='url' colspan='3'></td></tr>" +
  20. "<tr><td styles='formTableTitle' lable='title'></td>" +
  21. " <td styles='formTableValue14' item='title' colspan='3'></td></tr>" +
  22. "</table>";
  23. this.formTableArea.set("html", html);
  24. var data = this.app.minder.queryCommandValue('HyperLink');
  25. this.form = new MForm(this.formTableArea, data, {
  26. isEdited: true,
  27. style : "report",
  28. hasColon : true,
  29. itemTemplate: {
  30. url: { text : "链接地址", notEmpty : true,
  31. validRule : { isInvalid : function( value, it ){
  32. var urlRegex = '^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$';
  33. var R_URL = new RegExp(urlRegex, 'i');
  34. return R_URL.test( value )
  35. }.bind(this)},
  36. validMessage : { isInvalid : "请输入正确的链接" },
  37. attr : { placeholder : "必填:以 http(s):// 或 ftp:// 开头" }
  38. },
  39. title: { text : "提示文本", attr : { placeholder : "选填:鼠标在链接上悬停时提示的文本" } }
  40. }
  41. }, this.app);
  42. this.form.load();
  43. },
  44. _createBottomContent: function () {
  45. if (this.isNew || this.isEdited) {
  46. this.okActionNode = new Element("button.inputOkButton", {
  47. "styles": this.css.inputOkButton,
  48. "text": "确定"
  49. }).inject(this.formBottomNode);
  50. this.okActionNode.addEvent("click", function (e) {
  51. this.save(e);
  52. }.bind(this));
  53. }
  54. this.removeAction = new Element("button.inputCancelButton", {
  55. "styles": this.css.inputCancelButton,
  56. "text": "删除链接"
  57. }).inject(this.formBottomNode);
  58. this.removeAction.addEvent("click", function (e) {
  59. this.remove(e);
  60. }.bind(this));
  61. this.cancelActionNode = new Element("button.inputCancelButton", {
  62. "styles": (this.isEdited || this.isNew || this.getEditPermission() ) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  63. "text": "关闭"
  64. }).inject(this.formBottomNode);
  65. this.cancelActionNode.addEvent("click", function (e) {
  66. this.close(e);
  67. }.bind(this));
  68. },
  69. save: function(){
  70. var data = this.form.getResult(true,null,true,false,true);
  71. if( data ){
  72. this.app.minder.execCommand('HyperLink', data.url, data.title || '');
  73. this.close();
  74. }
  75. },
  76. remove: function( ev ){
  77. this.app.minder.execCommand('HyperLink', null );
  78. this.close();
  79. }
  80. });
  81. MWF.xApplication.MinderEditor.ImageForm = new Class({
  82. Extends: MPopupForm,
  83. Implements: [Options, Events],
  84. options: {
  85. "style": "report",
  86. "width": 800,
  87. "height": 640,
  88. "hasTop": true,
  89. "hasIcon": false,
  90. "draggable": true,
  91. "title" : "图片"
  92. },
  93. createContent: function () {
  94. this.createTab();
  95. this.formContentNode = new Element("div.formContentNode", {
  96. "styles": this.css.formContentNode
  97. }).inject(this.formNode);
  98. this.formTableContainer = new Element("div.formTableContainer", {
  99. "styles": this.css.formTableContainer
  100. }).inject(this.formContentNode);
  101. this.formTableArea = new Element("div.formTableArea", {
  102. "styles": this.css.formTableArea
  103. }).inject(this.formTableContainer);
  104. this._createTableContent();
  105. },
  106. _createTableContent: function () {
  107. this.linkContainer = new Element("div.linkContainer").inject(this.formTableArea);
  108. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  109. "<tr><td styles='formTableTitle' lable='url' width='20%'></td>" +
  110. " <td styles='formTableValue14' item='url' colspan='3'></td></tr>" +
  111. "<tr><td styles='formTableTitle' lable='title'></td>" +
  112. " <td styles='formTableValue14' item='title' colspan='3'></td></tr>" +
  113. "<tr><td styles='formTableTitle'>预览:</td>" +
  114. " <td styles='formTableValue14' item='preview' colspan='3'></td></tr>" +
  115. "</table>";
  116. this.linkContainer.set("html", html);
  117. var data = this.app.minder.queryCommandValue('image');
  118. this.linkform = new MForm(this.linkContainer, data, {
  119. isEdited: true,
  120. style : "report",
  121. hasColon : true,
  122. itemTemplate: {
  123. url: { text : "图片地址", notEmpty : true,
  124. validRule : { isInvalid : function( value, it ){
  125. var R_URL = /^https?\:\/\/\w+/;
  126. return R_URL.test( value )
  127. }.bind(this)},
  128. validMessage : { isInvalid : "请输入正确的链接" },
  129. attr : { placeholder : "必填:以 http(s):// 开始" },
  130. event : { blur : function( it ){
  131. if( it.getValue() )it.form.getItem("preview").setValue( it.getValue() )
  132. }.bind(this)}
  133. },
  134. title: { text : "提示文本", attr : { placeholder : "选填:鼠标在图片上悬停时提示的文本" } },
  135. preview : { type : "img", defaultValue : data.url || "", style : { "max-width" : "400px", "max-height" : "260px" } }
  136. }
  137. }, this.app);
  138. this.linkform.load();
  139. this.uploadContainer = new Element("div.uploadContainer", { styles : {"display":"none"} }).inject( this.formTableArea );
  140. var html = "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  141. "<tr><td item='image' colspan='4' style='padding-bottom: 10px;'></td></tr>" +
  142. "<tr><td styles='formTableTitle' lable='title2' width='20%'></td>" +
  143. " <td styles='formTableValue14' item='title2' colspan='3'></td></tr>" +
  144. "</table>";
  145. this.uploadContainer.set("html", html);
  146. var data = this.app.minder.queryCommandValue('image');
  147. this.uploadform = new MForm(this.uploadContainer, data, {
  148. isEdited: true,
  149. style : "report",
  150. hasColon : true,
  151. itemTemplate: {
  152. title2: { text : "提示文本", attr : { placeholder : "选填:鼠标在图片上悬停时提示的文本" } }
  153. }
  154. }, this.app);
  155. this.uploadform.load();
  156. this.image = new MWF.widget.ImageClipper(this.uploadContainer.getElement("[item='image']"), {
  157. "aspectRatio": 0,
  158. "description" : "",
  159. "imageUrl" : "",
  160. "ratioAdjustedEnable" : true,
  161. "reference" : "1111",
  162. "referenceType": "forumDocument",
  163. "fromFileEnable" : false,
  164. "resetEnable" : true
  165. });
  166. this.image.load();
  167. },
  168. createTab: function(){
  169. var _self = this;
  170. this.tabContainer = new Element("div.formTabContainer",{
  171. styles : this.css.formTabContainer
  172. }).inject(this.formNode);
  173. var tabNode = new Element("div.formTabNode", {
  174. "styles": this.css.formTabNode,
  175. "text" : "外链图片"
  176. }).inject(this.tabContainer);
  177. tabNode.addEvents({
  178. "mouseover" : function(){ if( _self.currentTabNode != this.node)this.node.setStyles(_self.css.formTabNode_over) }.bind({node : tabNode }),
  179. "mouseout" : function(){ if( _self.currentTabNode != this.node)this.node.setStyles(_self.css.formTabNode) }.bind({node : tabNode }),
  180. "click":function(){
  181. if( _self.currentTabNode )_self.currentTabNode.setStyles(_self.css.formTabNode);
  182. _self.currentTabNode = this.node;
  183. this.node.setStyles(_self.css.formTabNode_current);
  184. _self.linkContainer.setStyle("display","");
  185. _self.uploadContainer.setStyle("display","none");
  186. }.bind({ node : tabNode })
  187. })
  188. tabNode.setStyles( this.css.formTabNode_current );
  189. _self.currentTabNode = tabNode;
  190. var tabNode = new Element("div.tabNode", {
  191. "styles": this.css.formTabNode,
  192. "text" : "上传图片"
  193. }).inject(this.tabContainer);
  194. tabNode.addEvents({
  195. "mouseover" : function(){ if( _self.currentTabNode != this.node)this.node.setStyles(_self.css.formTabNode_over) }.bind({node : tabNode }),
  196. "mouseout" : function(){ if( _self.currentTabNode != this.node)this.node.setStyles(_self.css.formTabNode) }.bind({node : tabNode }),
  197. "click":function(){
  198. if( _self.currentTabNode )_self.currentTabNode.setStyles(_self.css.formTabNode);
  199. _self.currentTabNode = this.node;
  200. this.node.setStyles(_self.css.formTabNode_current);
  201. _self.linkContainer.setStyle("display","none");
  202. _self.uploadContainer.setStyle("display","");
  203. }.bind({ node : tabNode })
  204. })
  205. },
  206. _createBottomContent: function () {
  207. if (this.isNew || this.isEdited) {
  208. this.okActionNode = new Element("button.inputOkButton", {
  209. "styles": this.css.inputOkButton,
  210. "text": "确定"
  211. }).inject(this.formBottomNode);
  212. this.okActionNode.addEvent("click", function (e) {
  213. this.save(e);
  214. }.bind(this));
  215. }
  216. this.removeAction = new Element("button.inputCancelButton", {
  217. "styles": this.css.inputCancelButton,
  218. "text": "删除图片"
  219. }).inject(this.formBottomNode);
  220. this.removeAction.addEvent("click", function (e) {
  221. this.remove(e);
  222. }.bind(this));
  223. this.cancelActionNode = new Element("button.inputCancelButton", {
  224. "styles": (this.isEdited || this.isNew || this.getEditPermission() ) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  225. "text": "关闭"
  226. }).inject(this.formBottomNode);
  227. this.cancelActionNode.addEvent("click", function (e) {
  228. this.close(e);
  229. }.bind(this));
  230. },
  231. save: function(){
  232. if( this.image.resizedImage ){
  233. this.image.uploadImage( function( json ){
  234. var data = {
  235. url : MWF.xDesktop.getImageSrc( json.id ),
  236. title : this.uploadform.getResult(true,null,true,false,true)["title2"]
  237. };
  238. this.app.minder.execCommand('image', data.url, data.title || '');
  239. this.close();
  240. }.bind(this));
  241. }else{
  242. var data = this.linkform.getResult(true,null,true,false,true);
  243. if( data ){
  244. this.app.minder.execCommand('image', data.url, data.title || '');
  245. this.close();
  246. }
  247. }
  248. },
  249. remove: function( ev ){
  250. this.app.minder.execCommand('image', '' );
  251. this.close();
  252. },
  253. setFormNodeSize: function (width, height, top, left) {
  254. if (!width)width = this.options.width ? this.options.width : "50%";
  255. if (!height)height = this.options.height ? this.options.height : "50%";
  256. if (!top) top = this.options.top ? this.options.top : 0;
  257. if (!left) left = this.options.left ? this.options.left : 0;
  258. var containerSize = this.container.getSize();
  259. if( containerSize.x < width )width = containerSize.x;
  260. if( containerSize.y < height )height = containerSize.y;
  261. var allSize = this.app.content.getSize();
  262. var limitWidth = allSize.x; //window.screen.width
  263. var limitHeight = allSize.y; //window.screen.height
  264. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  265. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  266. 300 > width && (width = 300);
  267. 220 > height && (height = 220);
  268. top = top || parseInt((limitHeight - height) / 2, 10); //+appTitleSize.y);
  269. left = left || parseInt((limitWidth - width) / 2, 10);
  270. this.formAreaNode.setStyles({
  271. "width": "" + width + "px",
  272. "height": "" + height + "px",
  273. "top": "" + top + "px",
  274. "left": "" + left + "px"
  275. });
  276. this.formNode.setStyles({
  277. "width": "" + width + "px",
  278. "height": "" + height + "px"
  279. });
  280. var iconSize = this.formIconNode ? this.formIconNode.getSize() : {x: 0, y: 0};
  281. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  282. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  283. var tabSize = this.tabContainer ? this.tabContainer.getSize() : {x: 0, y: 0};
  284. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y - tabSize.y;
  285. //var formMargin = formHeight -iconSize.y;
  286. this.formContentNode.setStyles({
  287. "height": "" + contentHeight + "px"
  288. });
  289. this.formTableContainer.setStyles({
  290. "height": "" + contentHeight + "px"
  291. });
  292. }
  293. });
  294. MWF.xApplication.MinderEditor.NoteForm = new Class({
  295. Extends: MPopupForm,
  296. Implements: [Options, Events],
  297. options: {
  298. "style": "report",
  299. "width": 300,
  300. "height": "100%",
  301. "right" : 0,
  302. "hasTop": true,
  303. "hasIcon": false,
  304. "hasMask" : false,
  305. "hasBottom" : false,
  306. "draggable": true,
  307. "resizeable": true,
  308. "maxAction" : true,
  309. "title" : "备注"
  310. },
  311. _createTableContent: function () {
  312. this.formTableContainer.setStyle("width","100%");
  313. this.formTableArea.setStyle("height","100%");
  314. var html = "<div item='content' style='height: 100%;'></div>";
  315. this.formTableArea.set("html", html);
  316. MWF.xDesktop.requireApp("Template", "MForm", function () {
  317. this.form = new MForm(this.formTableArea, {}, {
  318. style: "report",
  319. isEdited: true,
  320. itemTemplate: {
  321. content: { type : "rtf", RTFConfig : {
  322. //skin : "bootstrapck",
  323. "resize_enabled": false,
  324. toolbar : [
  325. { name: 'document', items : [ 'Preview' ] },
  326. //{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
  327. { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','-','RemoveFormat' ] },
  328. //{ name: 'paragraph', items : [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },
  329. { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
  330. { name: 'colors', items : [ 'TextColor','BGColor' ] },
  331. { name: 'links', items : [ 'Link','Unlink' ] },
  332. //{ name: 'insert', items : [ 'Image' ] },
  333. { name: 'tools', items : [ 'Maximize','-','About' ] }
  334. ]
  335. }}
  336. }
  337. }, this.app);
  338. this.form.load();
  339. }.bind(this), true);
  340. },
  341. _setNodesSize : function( width, height, formContentHeight, formTableHeight ){
  342. this.form.getItem("content").editor.resize(null,formTableHeight );
  343. }
  344. });
  345. //MWF.xApplication.MinderEditor.NoteForm = new Class({
  346. // Extends: MPopupForm,
  347. // Implements: [Options, Events],
  348. // options: {
  349. // "style": "report",
  350. // "width": 300,
  351. // "height": "100%",
  352. // "right" : 0,
  353. // "hasTop": true,
  354. // "hasIcon": false,
  355. // "hasMask" : false,
  356. // "hasBottom" : false,
  357. // "draggable": true,
  358. // "resizeable": true,
  359. // "maxAction" : true,
  360. // "title" : "备注"
  361. // },
  362. // _createTableContent: function () {
  363. // this.formTableContainer.setStyle("width","100%");
  364. // this.formTableArea.setStyle("height","100%");
  365. // var codeMirrorPath = COMMON.contentPath+"/res/framework/codemirror";
  366. // var markedPath = COMMON.contentPath+"/res/framework/marked";
  367. //
  368. // var jsModules = [
  369. // codeMirrorPath + "/lib/codemirror.js",
  370. // codeMirrorPath + "/mode/xml/xml.js",
  371. // codeMirrorPath + "/mode/javascript/javascript.js",
  372. // codeMirrorPath + "/mode/css/css.js",
  373. // codeMirrorPath + "/mode/htmlmixed/htmlmixed.js",
  374. // codeMirrorPath + "/mode/markdown/markdown.js",
  375. // codeMirrorPath + "/addon/mode/overlay.js",
  376. // codeMirrorPath + "/mode/gfm/gfm.js",
  377. // markedPath + "/lib/marked.js"
  378. // ];
  379. //
  380. // COMMON.AjaxModule.loadCss( codeMirrorPath + "/lib/codemirror.css", function () {
  381. // COMMON.AjaxModule.load( jsModules, function () {
  382. // this.textarea = new Element("textarea").inject(this.formTableArea);
  383. // var codeMirrorEditor = CodeMirror.fromTextArea(this.textarea, {
  384. // theme: "default",
  385. // gfm: true,
  386. // breaks: true,
  387. // lineWrapping : true,
  388. // mode: 'gfm',
  389. // dragDrop: false,
  390. // lineNumbers:true
  391. // });
  392. // codeMirrorEditor.setSize("100%","50%");
  393. //
  394. // this.previewer = new Element("div").inject(this.formTableArea);
  395. // marked.setOptions({
  396. // gfm: true,
  397. // tables: true,
  398. // breaks: true,
  399. // pedantic: false,
  400. // sanitize: true,
  401. // smartLists: true,
  402. // smartypants: false
  403. // });
  404. // var str = "月份|收入|支出\n"+
  405. // "----|----|---\n"+
  406. // "8 |1000|500\n"+
  407. // "9 |1200|600\n"+
  408. // "10 |1400|650\n";
  409. // this.previewer.set("html",marked(str));
  410. // }.bind(this));
  411. // }.bind(this));
  412. // },
  413. // save: function(){
  414. //
  415. // this.app.minder.execCommand('note', data.url, data.title || '');
  416. // },
  417. // remove: function( ev ){
  418. // this.app.minder.execCommand('note', null );
  419. // }
  420. //});