/halogy/application/modules/pages/views/admin/edit.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 325 lines · 267 code · 58 blank · 0 comment · 35 complexity · b4fdce7e7041125cfc85ce029459edd9 MD5 · raw file

  1. <?php if (!$templates): ?>
  2. <h1>Add Page</h1>
  3. <br />
  4. <div class="error">
  5. <p>You have not yet set up any templates and you will need a template in order to create a page. You can add and import templates <a href="/admin/pages/templates">here</a>.</p>
  6. </div>
  7. <?php else: ?>
  8. <!-- Encoded URI (useful for redirecting in modules)
  9. <?php echo $this->core->encode($data['uri']); ?>
  10. -->
  11. <script type="text/javascript">
  12. var published = <?php echo $data['active']; ?>;
  13. var newPage = <?php echo $data['deleted']; ?>;
  14. var changePath = false;
  15. var changingPath = false;
  16. function changeTemplate() {
  17. var templateID = ($('#templateID').val());
  18. $('#preview').attr('src', '/admin/pages/view_template/'+templateID+'/<?php echo $data['pageID']; ?>');
  19. window.frames['preview.src'] = '/admin/pages/view_template/'+templateID+'/<?php echo $data['pageID']; ?>';
  20. return true;
  21. }
  22. function saveall(el, postform){
  23. var requiredFields = 'input#pageName, input#uri';
  24. var success = true;
  25. $(requiredFields).each(function(){
  26. if (!$(this).val()) {
  27. $('div.panes').scrollTo(
  28. 0, { duration: 400, axis: 'x' }
  29. );
  30. $(this).addClass('error').prev('label').addClass('error');
  31. $(this).focus(function(){
  32. $(this).removeClass('error').prev('label').removeClass('error');
  33. });
  34. success = false;
  35. }
  36. });
  37. if (!success) return false;
  38. $('#target').val($(el).attr('name'));
  39. var blocks = ($('#preview').contents().find('a.halogycms_savebutton').length);
  40. var updated = 0;
  41. $('#preview').contents().find('a.halogycms_savebutton').each(function(){
  42. var blockElement = $(this).parent().siblings('div.halogycms_blockelement');
  43. var blockForm = $(blockElement).siblings('div.halogycms_editblock');
  44. var body = $(blockForm).find('textarea').val();
  45. $.post(this.href,{body: body}, function(data){
  46. $(blockElement).html(data);
  47. updated++;
  48. if (updated == blocks && postform){
  49. $('#editpage').submit();
  50. }
  51. });
  52. });
  53. if (blocks){
  54. return false;
  55. } else {
  56. return true;
  57. }
  58. }
  59. function setUri(){
  60. if (!changingPath){
  61. changingPath = true;
  62. var uri = $('#uri').val();
  63. var pageName = $('#pageName').val();
  64. var parentName = $('#parentID option:selected').text();
  65. if (!newPage && !changePath){
  66. if (confirm('This page is published, are you sure want to change the path to this page?')){
  67. changePath = 'yes';
  68. } else {
  69. changePath = 'no';
  70. }
  71. }
  72. if (changePath == 'yes' || newPage){
  73. var newUri = $.post('/admin/pages/generate_uri', { uri: pageName, parent: parentName }, function(data){
  74. $('#uri').val(data);
  75. $('#title').val(pageName);
  76. });
  77. }
  78. changingPath = false;
  79. }
  80. }
  81. $(function(){
  82. $('ul.innernav a').click(function(event){
  83. event.preventDefault();
  84. $(this).parent().siblings('li').removeClass('selected');
  85. $(this).parent().addClass('selected');
  86. $pos = $(this).attr('href');
  87. $.scrollTo('form', { duration: 200 });
  88. $('div.panes').scrollTo(
  89. $pos, { duration: 400, axis: 'x'}
  90. );
  91. });
  92. $('select#templateID').change(function(){
  93. saveall(null, false);
  94. changeTemplate();
  95. });
  96. $('input.save').click(function(){
  97. return saveall(this, true);
  98. });
  99. $('#pageName').keyup(function(){
  100. setUri();
  101. });
  102. $('#parentID').change(function(){
  103. setUri();
  104. });
  105. changeTemplate();
  106. $('div.panes').scrollTo(
  107. 0, { duration: 400, axis: 'x'}
  108. );
  109. });
  110. </script>
  111. <form method="post" action="<?php echo $this->uri->uri_string(); ?>" class="default" id="editpage">
  112. <input type="hidden" name="target" id="target" value="" />
  113. <h1 class="headingleft">Edit Page <small>(<a href="/admin/pages/viewall">Back to Pages</a>)</small></h1>
  114. <div class="headingright">
  115. <input type="submit" name="view" value="View Page" class="button blue save" />
  116. <input type="submit" id="save" name="save" value="Save Changes" class="button green save" />
  117. <input type="submit" name="publish" value="Publish Page" class="button save orange" />
  118. </div>
  119. <?php if ($errors = validation_errors()): ?>
  120. <div class="error clear">
  121. <?php echo $errors; ?>
  122. </div>
  123. <?php endif; ?>
  124. <?php if (isset($message)): ?>
  125. <div class="message clear">
  126. <?php echo $message; ?>
  127. </div>
  128. <?php endif; ?>
  129. <br class="clear" />
  130. <ul class="innernav">
  131. <li id="tab1" class="selected"><a href="#pane1">Details</a></li>
  132. <li id="tab2"><a href="#pane2">Content</a></li>
  133. <li id="tab3"><a href="#pane3">Versions</a></li>
  134. </ul>
  135. <div class="panes">
  136. <div class="paneslide" style="width: 5000px;">
  137. <div id="pane1" class="pane">
  138. <h2 class="underline">Basic Information</h2>
  139. <label for="pageName">Page Name:</label>
  140. <?php echo @form_input('pageName',$data['pageName'], 'id="pageName" class="formelement"'); ?>
  141. <span class="tip">This is the name of the page, for your information only.</span>
  142. <br class="clear" />
  143. <label for="parentID">Parent:</label>
  144. <?php
  145. $options = array();
  146. $options[0] = 'Top Level';
  147. if ($parents):
  148. foreach ($parents as $parent):
  149. if ($parent['pageID'] != @$data['pageID']) $options[$parent['pageID']] = $parent['pageName'];
  150. endforeach;
  151. endif;
  152. echo @form_dropdown('parentID',$options,$data['parentID'],'id="parentID" class="formelement"');
  153. ?>
  154. <span class="tip">You can nest this page under other top level pages if you want.</span>
  155. <br class="clear" />
  156. <label for="uri">Path:</label>
  157. <?php echo @form_input('uri',$data['uri'], 'id="uri" class="formelement"'); ?>
  158. <span class="tip">Enter the web path this page can be found at, e.g. `about-us` (no spaces)</span>
  159. <br class="clear" />
  160. <label for="templateID">Template:</label>
  161. <?php
  162. if ($templates):
  163. $options = array();
  164. foreach ($templates as $template):
  165. $options[$template['templateID']] = $template['templateName'];
  166. endforeach;
  167. echo @form_dropdown('templateID',$options,$data['templateID'],'id="templateID" class="formelement"');
  168. endif;
  169. ?>
  170. <span class="tip">Templates control the layout of your page.</span>
  171. <br class="clear" />
  172. <label for="redirect">Redirect Path:</label>
  173. <?php echo @form_input('redirect',set_value('redirect', $data['redirect']), 'id="redirect" class="formelement"'); ?>
  174. <span class="tip">You can optionally use this page as a redirect to another page.</span>
  175. <br class="clear" /><br />
  176. <h2 class="underline">Meta Data</h2>
  177. <label for="title">Page Title:</label>
  178. <?php echo @form_input('title',set_value('title', $data['title']), 'id="title" class="formelement"'); ?>
  179. <span class="tip">This will display in the title bar of browsers.</span>
  180. <br class="clear" />
  181. <label for="description">Meta Description:</label>
  182. <?php echo @form_input('description',set_value('description', $data['description']), 'id="description" class="formelement"'); ?>
  183. <span class="tip">Description of page for search engines.</span>
  184. <br class="clear" />
  185. <label for="keywords">Meta Keywords:</label>
  186. <?php echo @form_input('keywords',set_value('keywords', $data['keywords']), 'id="keywords" class="formelement"'); ?>
  187. <span class="tip">Meta tags for search engines.</span>
  188. <br class="clear" /><br />
  189. <h2 class="underline">Visibility and Access</h2>
  190. <label for="navigation">Show in Navigation:</label>
  191. <?php
  192. $values = array(
  193. 1 => 'Yes',
  194. 0 => 'No (hidden page)',
  195. );
  196. echo @form_dropdown('navigation',$values,$data['navigation'], 'id="navigation" class="formelement"');
  197. ?>
  198. <span class="tip">By default your page will appear on the navigation menu.</span>
  199. <br class="clear" />
  200. <label for="active">Publish Status:</label>
  201. <?php
  202. $values = array(
  203. 0 => 'Draft (visible only to administrators)',
  204. 1 => 'Publish',
  205. );
  206. echo @form_dropdown('active',$values,$data['active'], 'id="active" class="formelement"');
  207. ?>
  208. <span class="tip">Remember to set this to 'Publish' if you want to show the page.</span>
  209. <br class="clear" />
  210. <label for="groupID">Edit Group:</label>
  211. <?php
  212. $values = array(
  213. 0 => 'Administrators only',
  214. );
  215. if ($groups)
  216. {
  217. foreach($groups as $group)
  218. {
  219. $values[$group['groupID']] = $group['groupName'];
  220. }
  221. }
  222. echo @form_dropdown('groupID',$values,$data['groupID'], 'id="groupID" class="formelement"');
  223. ?>
  224. <span class="tip">Who is able to edit this page?</span>
  225. <br class="clear" /><br />
  226. </div>
  227. <div id="pane2" class="pane">
  228. <iframe name="preview" id="preview" src="about:blank" frameborder="0" marginheight="0" marginwidth="0"></iframe>
  229. </div>
  230. <div id="pane3" class="pane">
  231. <?php if ($versions): ?>
  232. <h2 class="underline">Published Versions</h2>
  233. <ul>
  234. <?php foreach($versions as $version): ?>
  235. <li>
  236. <?php if ($data['versionID'] == $version['versionID']): ?>
  237. <strong><?php echo dateFmt($version['dateCreated'], '', '', TRUE).(($user = $this->core->lookup_user($version['userID'], TRUE)) ? ' <em>(by '.$user.')</em>' : ''); ?></strong>
  238. <?php else: ?>
  239. <?php echo dateFmt($version['dateCreated'], '', '', TRUE).(($user = $this->core->lookup_user($version['userID'], TRUE)) ? ' <em>(by '.$user.')</em>' : ''); ?> - <?php echo anchor('/admin/pages/revert_version/'.$data['pageID'].'/'.$version['versionID'], 'Revert', 'onclick="return confirm(\'You will lose unsaved changes. Continue?\');"'); ?>
  240. <?php endif; ?>
  241. </li>
  242. <?php endforeach; ?>
  243. </ul>
  244. <br />
  245. <?php endif; ?>
  246. <?php if ($drafts): ?>
  247. <h2 class="underline">Drafts</h2>
  248. <ul>
  249. <?php foreach($drafts as $version): ?>
  250. <li>
  251. <?php if ($data['draftID'] == $version['versionID']): ?>
  252. <strong><?php echo dateFmt($version['dateCreated'], '', '', TRUE).(($user = $this->core->lookup_user($version['userID'], TRUE)) ? ' <em>(by '.$user.')</em>' : ''); ?></strong>
  253. <?php else: ?>
  254. <?php echo dateFmt($version['dateCreated'], '', '', TRUE).(($user = $this->core->lookup_user($version['userID'], TRUE)) ? ' <em>(by '.$user.')</em>' : ''); ?> - <?php echo anchor('/admin/pages/revert_draft/'.$data['pageID'].'/'.$version['versionID'], 'Revert', 'onclick="return confirm(\'You will lose unsaved changes. Continue?\');"'); ?>
  255. <?php endif; ?>
  256. </li>
  257. <?php endforeach; ?>
  258. </ul>
  259. <?php endif; ?>
  260. </div>
  261. </div>
  262. </div>
  263. <p style="text-align: right;">
  264. <a href="#" class="button grey" id="totop">Back to top</a>
  265. </p>
  266. </form>
  267. <?php endif; ?>