create.zentaomax.html.hook.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php if(isset($from) and $from == 'template'):?>
  2. <?php
  3. js::set('replaceContentTip', $this->lang->doc->replaceContentTip);
  4. js::set('baselinePriv', commonModel::hasPriv('baseline', 'template'));
  5. $templateHTML = html::select('template', '', '', "class='form-control chosen'");
  6. $templateIcon = "<a href='#' id='templateIcon' class='btn btn-link'><i class='icon-template' style='color:#2E7FFF;'></i><span class='text'> {$this->lang->doc->template}</span></a>";
  7. $confirmHTML = html::commonButton($lang->confirm, "onclick=loadContent()", "btn btn-primary btn-wide confirm-btn");
  8. $cancelHTML = html::commonButton($lang->cancel, "data-dismiss='modal'", "btn btn-wide");
  9. $modalTemplate = <<<EOD
  10. <div class='modal fade' id='modalTemplate' data-scroll-inside='true'>
  11. <div class='modal-dialog' style='width:480px;'>
  12. <div class='modal-content'>
  13. <div class='modal-body'>
  14. <button type='button' class='close' data-dismiss='modal'>
  15. <i class='icon icon-close'></i>
  16. </button>
  17. <table class='table table-form'>
  18. <tr>
  19. <th class='temp-tip'>{$lang->doc->selectTemplate}</th>
  20. <td class='templateBox'>{$templateHTML}</td>
  21. </tr>
  22. <tr>
  23. <td colspan='2' class='text-center'>
  24. {$confirmHTML}
  25. {$cancelHTML}
  26. </td>
  27. </tr>
  28. </table>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. EOD;
  34. ?>
  35. <style>
  36. #modalTemplate .modal-body {padding:50px 50px 30px 10px;}
  37. #modalTemplate .modal-body .close {position:absolute; right:15px; top:15px}
  38. #modalTemplate .confirm-btn {margin-left: 52px;}
  39. #modalTemplate .temp-tip {width: 110px; white-space: nowrap;}
  40. </style>
  41. <script>
  42. $(function()
  43. {
  44. $('#modalBasicInfo').before(<?php echo json_encode($modalTemplate)?>);
  45. $('.btn-tools').prepend(<?php echo json_encode($templateIcon)?>);
  46. loadTemplates();
  47. initDocContent();
  48. $('#templateIcon').click(function(){ $('#modalTemplate').modal(); });
  49. });
  50. /**
  51. * Load templates.
  52. *
  53. * @access public
  54. * @return void
  55. */
  56. function loadTemplates()
  57. {
  58. if(baselinePriv)
  59. {
  60. var link = createLink('baseline', 'ajaxGetTemplates', 'type=all&from=doc&contentType=html,markdown');
  61. $.post(link, function(data)
  62. {
  63. $('#modalTemplate .templateBox').html(data);
  64. $('#template').removeAttr('onchange').picker();
  65. })
  66. }
  67. else
  68. {
  69. $('#template').picker();
  70. }
  71. }
  72. /**
  73. * Init doc content.
  74. *
  75. * @access public
  76. * @return void
  77. */
  78. function initDocContent()
  79. {
  80. $('#contentType').val('html');
  81. editor['content'].html('');
  82. $('#contentBox').removeClass('hidden');
  83. $('.contenthtml').removeClass('hidden');
  84. $('.contentmarkdown').addClass('hidden');
  85. }
  86. /**
  87. * Load content.
  88. *
  89. * @access public
  90. * @return void
  91. */
  92. function loadContent()
  93. {
  94. $('#modalTemplate').modal('hide');
  95. var templateID = $('#template').val();
  96. if(templateID == '') return;
  97. var link = createLink('baseline', 'ajaxGetContent', 'templateID=' + templateID);
  98. $.post(link, function(data)
  99. {
  100. data = JSON.parse(data);
  101. if(isContentEmpty(data))
  102. {
  103. replaceContent(data);
  104. }
  105. else
  106. {
  107. bootbox.confirm(replaceContentTip, function(res)
  108. {
  109. if(res)
  110. {
  111. replaceContent(data);
  112. }
  113. });
  114. }
  115. })
  116. }
  117. /**
  118. * Check doc content is empty or not.
  119. *
  120. * @param array $data
  121. * @access public
  122. * @return boolean
  123. */
  124. function isContentEmpty(data)
  125. {
  126. if(data.type == 'html')
  127. {
  128. return editor['content'].html() == '';
  129. }
  130. else if(data.type == 'markdown')
  131. {
  132. return markdownEditor['contentMarkdown'].value() == '';
  133. }
  134. return true;
  135. }
  136. /**
  137. * Replace content.
  138. *
  139. * @param array $data
  140. * @access public
  141. * @return void
  142. */
  143. function replaceContent(data)
  144. {
  145. var type = data.type;
  146. if(type == 'html') type = 'text';
  147. $('input[id*=' + type + ']').attr('checked', 'checked');
  148. toggleEditorMode(data.type);
  149. if(data.type == 'html')
  150. {
  151. var cmd = editor['content'].edit.cmd;
  152. editor['content'].html('');
  153. cmd.inserthtml(data.content);
  154. }
  155. else if(data.type == 'markdown')
  156. {
  157. markdownEditor['contentMarkdown'].value(data.content);
  158. }
  159. }
  160. </script>
  161. <?php endif;?>