entryproxy.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. Trex.install("editor.getEntryProxy",
  2. function(editor, toolbar, sidebar, canvas, config){
  3. var _entryproxy = new Trex.EntryProxy(editor, sidebar, config);
  4. editor.getEntryProxy = function() {
  5. return _entryproxy;
  6. };
  7. }
  8. );
  9. Trex.EntryProxy =Trex.Class.create( {
  10. initialize : function(editor, sidebar, config){
  11. this.editor = editor;
  12. this.sidebar = sidebar;
  13. this.config = config;
  14. },
  15. /**
  16. * For loadEntriesAtRestore, loadEntriesAtModify
  17. */
  18. commands: {},
  19. registerCommand: function(name, command){
  20. this.commands[name] = command;
  21. },
  22. getcommand: function(name){
  23. return this.commands[name];
  24. },
  25. executeCommand: function(cmd, data){
  26. for(var i in this.commands){
  27. var command = this.commands[i];
  28. if(command[cmd]){
  29. command[cmd](data);
  30. }
  31. }
  32. },
  33. setAttachments: function(attachments, contents) { //NOTE: data format = JSON
  34. attachments = attachments || [];
  35. contents = contents || "";
  36. var _entrybox = this.editor.getAttachBox();
  37. _entrybox.empty();
  38. var _actors = this.sidebar.getAttacher();
  39. attachments.each(function(attachment){
  40. try {
  41. var _actor = _actors[attachment.attacher];
  42. if(_actor) {
  43. _actor.execReload(attachment.data, contents, attachment.type);
  44. }
  45. } catch(ignore) {
  46. // 첨부데이터 일부를 정상적으로 불러오지 못했습니다.
  47. console.error("첨부데이터 일부를 정상적으로 불러오지 못했습니다:", ignore);
  48. }
  49. });
  50. },
  51. getAttachments: function(attachments, all) {
  52. all = !!all;
  53. var _attachments = [];
  54. attachments.each(function(attachment){
  55. if(attachment.deletedMark) {
  56. return;
  57. }
  58. if(all || attachment.existStage) {
  59. _attachments.push({
  60. type: attachment.type,
  61. attacher: attachment.actor.name,
  62. existStage: attachment.existStage,
  63. data: Object.extend(attachment.data, {
  64. tmpSeq: attachment.dataSeq
  65. }) //html mode
  66. });
  67. }
  68. });
  69. return _attachments;
  70. }
  71. } );