ajaxprinttemplates.html.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php if(empty($link)):?>
  2. <?php
  3. foreach($templates as $key => $template)
  4. {
  5. echo "<li id='tplBox$template->id' onmouseover='displayXIcon($template->id)' onmouseout='hideXIcon($template->id)'>";
  6. echo "<a title='{$lang->user->applyTemplate}' class='tpl-name' id='tplTitleBox$template->id' href='javascript:setTemplate($template->id)'>";
  7. if($template->public) echo "<span class='label label-info label-badge'>{$lang->public}</span> ";
  8. echo $template->title . "</a>";
  9. if(empty($template->public) or $template->account == $app->user->account or $app->user->admin) echo "<a href='###' onclick='deleteTemplate($template->id)' id='templateID$template->id' class='btn-delete hidden'><i class='icon-close'></i></a>";
  10. echo "<span id='template$template->id' class='hidden'>$template->content</span>";
  11. echo '</li>';
  12. }
  13. ?>
  14. <?php else:?>
  15. <style>
  16. #tplBoxWrapper {position: relative; z-index: 10;}
  17. #tplBoxWrapper > .btn-toolbar {position: absolute; right: 1px; top: 1px;}
  18. #tplBoxWrapper .btn {padding: 4px 8px; border-top:0px; border-bottom:0px;}
  19. #tplBoxWrapper #applyTplBtn {border-right:0px;}
  20. #tplBox li {position: relative;}
  21. #tplBox li .btn-delete {position: absolute; right: 0; top: -5px; display: block; width: 40px; text-align:center;}
  22. #tplBox li:hover .btn-delete {color:#fff;}
  23. #tplBox li .tpl-name {padding-right: 40px;}
  24. </style>
  25. <div id='tplBoxWrapper'>
  26. <div class='btn-toolbar'>
  27. <div class='btn-group'>
  28. <button id='saveTplBtn' type='button' class='btn btn-mini' data-toggle='saveTplModal'><?php echo $lang->user->saveTemplate?></button>
  29. <button id='applyTplBtn' type='button' class='btn btn-mini dropdown-toggle' data-toggle='dropdown'><?php echo $lang->user->applyTemplate?> <span class='caret'></span></button>
  30. <ul id='tplBox' class='dropdown-menu pull-right'>
  31. <?php
  32. foreach($templates as $key => $template)
  33. {
  34. echo "<li id='tplBox$template->id' onmouseover='displayXIcon($template->id)' onmouseout='hideXIcon($template->id)'>";
  35. echo "<a title='{$lang->user->applyTemplate}' class='tpl-name' id='tplTitleBox$template->id' href='javascript:setTemplate($template->id)'>";
  36. if($template->public) echo "<span class='label label-info label-badge'>{$lang->public}</span> ";
  37. echo $template->title . "</a>";
  38. if(empty($template->public) or $template->account == $app->user->account or $app->user->admin) echo "<a href='###' onclick='deleteTemplate($template->id)' id='templateID$template->id' class='btn-delete hidden'><i class='icon-close'></i></a>";
  39. echo "<span id='template$template->id' class='hidden'>$template->content</span>";
  40. echo '</li>';
  41. }
  42. ?>
  43. </ul>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="modal fade" id="saveTplModal" tabindex="-1" role="dialog">
  48. <div class="modal-dialog w-600px">
  49. <div class="modal-content">
  50. <div class="modal-header">
  51. <button type="button" class="close" data-dismiss="modal"><i class="icon icon-close"></i></button>
  52. <h4 class="modal-title"><?php echo $lang->user->setTemplateTitle;?></h4>
  53. </div>
  54. <div class="modal-body">
  55. <div class='input-group'>
  56. <input type="text" id="title" value="" class="form-control" autocomplete="off">
  57. <?php if(common::hasPriv('user', 'setPublicTemplate')):?>
  58. <span class="input-group-addon">
  59. <div class="checkbox-primary">
  60. <input type="checkbox" value="1" id="public" />
  61. <label for="public"><?php echo $lang->public;?></label>
  62. </div>
  63. </span>
  64. <?php endif;?>
  65. <span class='input-group-btn'><?php echo html::commonButton($lang->save, "id='templateSubmit'", 'btn btn-primary')?></span>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <script>
  72. function setTemplate(templateID)
  73. {
  74. $('#tplBox .list-group-item.active').removeClass('active');
  75. $('#tplTitleBox' + templateID).closest('.list-group-item').addClass('active');
  76. var content = $('#template' + templateID).html();
  77. var cmd = editor['<?php echo $link;?>'].edit.cmd;
  78. editor['<?php echo $link;?>'].html('');
  79. cmd.inserthtml(content);
  80. editor['<?php echo $link;?>'].templateHtml = editor['<?php echo $link;?>'].html();
  81. }
  82. function deleteTemplate(templateID)
  83. {
  84. if(!templateID) return;
  85. if(confirm(<?php echo json_encode($lang->user->confirmDeleteTemplate);?>))
  86. {
  87. hiddenwin.location.href = createLink('user', 'ajaxDeleteTemplate', 'templateID=' + templateID);
  88. $('#tplBox' + templateID).addClass('hidden');
  89. }
  90. }
  91. function displayXIcon(templateID)
  92. {
  93. $('#templateID' + templateID).removeClass('hidden');
  94. }
  95. function hideXIcon(templateID)
  96. {
  97. $('#templateID' + templateID).addClass('hidden');
  98. }
  99. $(function()
  100. {
  101. $('#saveTplModal').on('hide.zui.modal', function(){$(this).find('#title').val('');});
  102. $('#saveTplBtn').click(function()
  103. {
  104. var content = editor['<?php echo $link;?>'].html();
  105. if(!content)
  106. {
  107. bootAlert("<?php echo $lang->user->tplContentNotEmpty ?>");
  108. return;
  109. }
  110. $('#saveTplModal').modal('show');
  111. });
  112. $('#saveTplModal #templateSubmit').click(function()
  113. {
  114. var $inputGroup = $('#saveTplModal div.input-group');
  115. var $publicBox = $inputGroup.find('input#public');
  116. var title = $inputGroup.find('#title').val();
  117. var content = editor['<?php echo $link;?>'].html();
  118. var isPublic = ($publicBox.size() > 0 && $publicBox.prop('checked')) ? $publicBox.val() : 0;
  119. if(!title || !content) return;
  120. saveTemplateLink = <?php echo json_encode($this->createLink('user', 'ajaxSaveOldTemplate', "type=$type"));?>;
  121. $.post(saveTemplateLink, {title:title, content:content, public:isPublic}, function(data)
  122. {
  123. $('#tplBox').html(data);
  124. // If has error then not hide.
  125. if(data.indexOf('alert') == -1) $('#saveTplModal').modal('hide');
  126. });
  127. });
  128. })
  129. </script>
  130. <?php endif;?>