PageRenderTime 41ms CodeModel.GetById 12ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 1ms

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