attacher.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. * @filewoverview
  3. * attacher.js - 첨부 관련 source로 이 소스에서 존재하는 Attacher들을 직접 생성한다.
  4. * Editor가 생성될때 initialize된다.
  5. */
  6. TrexMessage.addMsg({
  7. '@attacher.can.modify.alert': "기존에 등록된 #{title}을(를) 수정할 수 있는 화면으로 이동합니다.",
  8. '@attacher.can.modify.confirm': "#{title}은(는) 하나만 등록이 가능합니다.\n다시 올리시면 기존의 #{title}이(가) 삭제됩니다. 계속하시겠습니까?",
  9. '@attacher.insert.alert': "에디터 상태에서만 삽입할 수 있습니다.",
  10. '@attacher.capacity.alert': "용량을 초과하였습니다.",
  11. '@attacher.size.alert': "용량을 초과하여 더이상 등록할 수 없습니다."
  12. });
  13. Trex.install("sidebar.getAttacher & sidebar.getUploadAdaptor",
  14. function(editor, toolbar, sidebar) {
  15. var _attachers = sidebar.attachers = {};
  16. /**
  17. * memberOf Trex.Sidebar.prototype
  18. * @param {Object} name
  19. */
  20. sidebar.getAttacher = function(name) {
  21. if(_attachers[name] != _NULL) {
  22. return _attachers[name];
  23. } else if(arguments.length == 0){
  24. return _attachers;
  25. }else{
  26. return _NULL;
  27. }
  28. };
  29. }
  30. );
  31. Trex.register("new attachers",
  32. function(editor, toolbar, sidebar, canvas, config) {
  33. var _attachBox = editor.getAttachBox();
  34. var _attachers = sidebar.attachers;
  35. for(var i in Trex.Attacher) {
  36. var _name = Trex.Attacher[i]['__Identity'];
  37. if(_name){
  38. _attachers[_name] = new Trex.Attacher[i](editor, _attachBox, config);
  39. }
  40. }
  41. if (_attachers["file"]) {
  42. sidebar.getUploadAdaptor = function(){
  43. return _attachers["file"].getAdaptor();
  44. };
  45. }
  46. }
  47. );
  48. /**
  49. * Class Trex.Attacher
  50. *
  51. * @abstract
  52. * @class
  53. * @extends Trex.Actor
  54. * @param {Object} editor
  55. * @param {Object} entryBox
  56. * @param {Object} config
  57. */
  58. Trex.Attacher = Trex.Class.draft(/** @lends Trex.Attacher.prototype */{
  59. /** @ignore */
  60. $extend: Trex.Actor,
  61. canModified: _FALSE,
  62. canResized: _FALSE,
  63. initialize: function(editor, entryBox, config) {
  64. this.editor = editor;
  65. this.canvas = editor.getCanvas();
  66. this.entryBox = entryBox;
  67. var _config = this.config = TrexConfig.getAttacher(this.constructor.__Identity, config);
  68. if(config.pvpage && !!_config.usepvpage) {
  69. this.pvUrl = TrexConfig.getUrl(config.pvpage, { "pvname": this.name });
  70. }
  71. this.boxonly = ((_config.boxonly != _NULL)? _config.boxonly: _FALSE);
  72. this.isMultiple = ((_config.multiple != _NULL)? _config.multiple: _FALSE);
  73. this.isCheckSize = ((_config.checksize != _NULL)? _config.checksize: _FALSE);
  74. this.wysiwygonly = ((_config.wysiwygonly != _NULL)? _config.wysiwygonly: _TRUE);
  75. this.pastescope = _config.pastescope;
  76. if (this.oninitialized) {
  77. this.oninitialized(config);
  78. }
  79. this.attachHandler = this.attachHandler.bind(this);
  80. },
  81. /**
  82. * Attacher를 실행, 첨부를 하기 위한 popup window를 띄워주거나 필요한 action을 수행한다.
  83. * @param {String} param - 팝업을 띄울때 추가할 파라미터 문자열
  84. * @function
  85. */
  86. execute: function(param) {
  87. if(this.wysiwygonly && !this.canvas.isWYSIWYG()) {
  88. alert(TXMSG("@attacher.insert.alert"));
  89. return;
  90. }
  91. if(this.isCheckSize && !this.entryBox.checkAvailableCapacity()) {
  92. alert(TXMSG("@attacher.capacity.alert"));
  93. return;
  94. }
  95. if(!this.checkInsertable()) {
  96. if(this.canModified) {
  97. var _jstObj = new Template( TXMSG("@attacher.can.modify.alert") );
  98. alert( _jstObj.evaluate( {title : this.title}));
  99. } else {
  100. var _jstObj = new Template( TXMSG("@attacher.can.modify.confirm") );
  101. if(!confirm(_jstObj.evaluate({ title : this.title }))) {
  102. return;
  103. }
  104. }
  105. }
  106. if(this.clickHandler) {
  107. this.clickHandler();
  108. } else {
  109. try {
  110. var _url = this.config.popPageUrl;
  111. if(param) {
  112. _url = _url + ((_url.indexOf("?") > -1) ? "&" : "?") + param;
  113. }
  114. var isDocumentDomainDeclaredExplicitly = (document.location.hostname != document.domain);
  115. if (isDocumentDomainDeclaredExplicitly) {
  116. _url = _url + ((_url.indexOf("?") > -1) ? "&" : "?") + "xssDomain=" + document.domain;
  117. }
  118. _url = (this.pvUrl? this.pvUrl + ((this.pvUrl.indexOf("?") > -1) ? "&" : "?") + "u="+escape(_url): _url);
  119. var win = _WIN.open(_url, "at" + this.name, this.config.features);
  120. win.focus();
  121. } catch (e) {}
  122. }
  123. },
  124. /**
  125. * Argument의 data를 이용해서 editor에 첨부하며, Attacher type에 때라 data의 format은 다르다.
  126. * @function
  127. * @param {Object} data
  128. * @param {Object} attachmentType - optional
  129. */
  130. attachHandler: function(data, attachmentType) {
  131. if(this.checkInsertable()) {
  132. if(this.isCheckSize && !this.entryBox.checkInsertableSize(data.filesize)) {
  133. alert(TXMSG("@attacher.size.alert"));
  134. return;
  135. }
  136. this.execAttach(data, attachmentType);
  137. } else {
  138. this.execReattach(data, attachmentType);
  139. }
  140. },
  141. createEntry: function(data, type) {
  142. return this.createAttachment(data, type);
  143. },
  144. createAttachment: function(data, type) {
  145. var _attachmentType = this.constructor.__Identity;
  146. if(type){
  147. _attachmentType = type;
  148. }
  149. return new Trex.Attachment[_attachmentType.capitalize()](this, data);
  150. },
  151. checkInsertable: function() {
  152. if (this.isMultiple) {
  153. return _TRUE;
  154. }
  155. var list = this.getDatalist().findAll(function(entry) {
  156. return entry.deletedMark != _TRUE;
  157. });
  158. return list.length === 0;
  159. }
  160. });