aboutsummaryrefslogtreecommitdiffstats
path: root/view/tpl/wiki_page_list.tpl
blob: bd6d2d759cfaa01beaed095f863f8f48b8166c95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{{if $not_refresh}}<div id="wiki_page_list_container" {{if $hide}} style="display: none;" {{/if}}>{{/if}}
<div id="wiki_page_list" class="widget" >
	<h3>{{$header}}</h3>
	<ul class="nav nav-pills nav-stacked">
		{{if $pages}}
		{{foreach $pages as $page}}
		<li id="{{$page.link_id}}">
			{{if $page.resource_id && $canadd}}
			<i class="widget-nav-pills-icons fa fa-trash-o drop-icons" onclick="wiki_delete_page('{{$page.title}}', '{{$page.url}}', '{{$page.resource_id}}', '{{$page.link_id}}')"></i>
			{{/if}}
			<a href="/wiki/{{$channel}}/{{$wikiname}}/{{$page.url}}">{{$page.title}}</a>
		</li>
		{{/foreach}}
		{{/if}}
		{{if $canadd}}
		<li><a href="#" onclick="wiki_show_new_page_form(); return false;"><i class="fa fa-plus-circle"></i>&nbsp;{{$addnew}}</a></li>
		{{/if}}
	</ul>
	{{if $canadd}}
	<div id="new-page-form-wrapper" class="sub-menu" style="display:none;">
		<form id="new-page-form" action="wiki/{{$channel}}/create/page" method="post" >
			{{include file="field_input.tpl" field=$pageName}}
			<button id="new-page-submit" class="btn btn-primary" type="submit" name="submit" >Submit</button>
		</form>
	</div>
	{{/if}}
</div>
{{if $not_refresh}}</div>{{/if}}

<script>
	$('#new-page-submit').click(function (ev) {
		if (window.wiki_resource_id === '') {
			window.console.log('You must have a wiki open in order to create pages.');
			ev.preventDefault();
			return false;
		}
		$.post("wiki/{{$channel}}/create/page", {name: $('#id_pageName').val(), resource_id: window.wiki_resource_id}, 
		function (data) {
			if (data.success) {
			window.location = data.url;
			} else {
			window.console.log('Error creating page.');
			}
		}, 'json');
		ev.preventDefault();
	});

	function wiki_delete_page(wiki_page_name, wiki_page_url, wiki_resource_id, wiki_link_id) {
		if(!confirm('Are you sure you want to delete the page: ' + wiki_page_name)) {
			return;
		}
		$.post("wiki/{{$channel}}/delete/page", {name: wiki_page_url, resource_id: wiki_resource_id},
		function (data) {
			if (data.success) {
				window.console.log('Page deleted successfully.');
				if(wiki_page_url == window.wiki_page_name) {
					var url = window.location.href;
					if(url.substr(-1) == '/')
						url = url.substr(0, url.length - 2);
					url = url.split('/');
					url.pop();
					window.location = url.join('/');
				}
				else {
					$('#' + wiki_link_id).remove();
				}
			} else {
				alert('Error deleting page.'); // TODO: Replace alerts with auto-timeout popups
				window.console.log('Error deleting page.');
			}
		}, 'json');
		return false;
	}
</script>