From f5ad1dfbc521223be5ca97f0b878d9267cffabb3 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Mon, 14 Nov 2016 19:58:43 -0500 Subject: Moved new wiki and new page buttons to widgets --- view/tpl/wiki.tpl | 729 +++++++++++++++++++++++--------------------- view/tpl/wiki_page_list.tpl | 4 +- view/tpl/wikilist.tpl | 6 +- 3 files changed, 391 insertions(+), 348 deletions(-) diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl index c26ffd64a..bba35a0fc 100644 --- a/view/tpl/wiki.tpl +++ b/view/tpl/wiki.tpl @@ -15,24 +15,12 @@
- {{if $showNewWikiButton || $showPageControls}} + {{if $showPageControls}}
@@ -87,6 +75,17 @@
+ +
+ + }); + + $('#wiki-get-history').click(function (ev) { + $.post("wiki/{{$channel}}/history/page", {name: window.wiki_page_name, resource_id: window.wiki_resource_id}, function (data) { + if (data.success) { + $('#page-history-list').html(data.historyHTML); + } else { + window.console.log('Error getting page history.'); + } + }, 'json'); + ev.preventDefault(); + }); + + function wiki_delete_wiki(wikiHtmlName, resource_id) { + if(!confirm('Are you sure you want to delete the entire wiki: ' + JSON.stringify(wikiHtmlName))) { + return; + } + $.post("wiki/{{$channel}}/delete/wiki", {resource_id: resource_id}, function (data) { + if (data.success) { + window.console.log('Wiki deleted'); + // Refresh list and redirect page as necessary + window.location = 'wiki/{{$channel}}'; + } else { + alert('Error deleting wiki!'); + window.console.log('Error deleting wiki.'); + } + }, 'json'); + } + + + function wiki_download_wiki(resource_id) { + window.location = "wiki/{{$channel}}/download/wiki/" + resource_id; + } + + $('#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_refresh_page_list() { + if (window.wiki_resource_id === '') { + return false; + } + $.post("wiki/{{$channel}}/get/page/list/", {resource_id: window.wiki_resource_id}, function (data) { + if (data.success) { + $('#wiki_page_list_container').html(data.pages); + $('#wiki_page_list_container').show(); + } else { + alert('Error fetching page list!'); + window.console.log('Error fetching page list!'); + } + }, 'json'); + return false; + } + + $('#save-page').click(function (ev) { + if (window.wiki_resource_id === '' || window.wiki_page_name === '') { + window.console.log('You must have a wiki page open in order to edit pages.'); + ev.preventDefault(); + return false; + } + var currentContent = editor.getValue(); + if (window.wiki_page_content === currentContent) { + window.console.log('No edits to save.'); + ev.preventDefault(); + return false; + } + $.post("wiki/{{$channel}}/save/page", + { content: currentContent, + commitMsg: $('#id_commitMsg').val(), + name: window.wiki_page_name, + resource_id: window.wiki_resource_id + }, + function (data) { + if (data.success) { + window.console.log('Page saved successfully.'); + window.wiki_page_content = currentContent; + $('#id_commitMsg').val(''); // Clear the commit message box + $('#wiki-get-history').click(); + } else { + alert('Error saving page.'); // TODO: Replace alerts with auto-timeout popups + window.console.log('Error saving page.'); + } + }, 'json'); + ev.preventDefault(); + }); + + $('#delete-page').click(function (ev) { + if (window.wiki_resource_id === '' || window.wiki_page_name === '' || window.wiki_page_name === 'Home') { + window.console.log('You must have a wiki page open in order to delete pages.'); + ev.preventDefault(); + return false; + } + if(!confirm('Are you sure you want to delete the page: ' + window.wiki_page_name)) { + ev.preventDefault(); + return; + } + $.post("wiki/{{$channel}}/delete/page", {name: window.wiki_page_name, resource_id: window.wiki_resource_id}, + function (data) { + if (data.success) { + window.console.log('Page deleted successfully.'); + 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 { + alert('Error deleting page.'); // TODO: Replace alerts with auto-timeout popups + window.console.log('Error deleting page.'); + } + }, 'json'); + ev.preventDefault(); + }); + + function wiki_revert_page(commitHash) { + if (window.wiki_resource_id === '' || window.wiki_page_name === '') { + window.console.log('You must have a wiki page open in order to revert pages.'); + return false; + } + $.post("wiki/{{$channel}}/revert/page", {commitHash: commitHash, name: window.wiki_page_name, resource_id: window.wiki_resource_id}, + function (data) { + if (data.success) { + $('button[id^=revert-]').removeClass('btn-success'); + $('button[id^=revert-]').addClass('btn-danger'); + $('button[id^=revert-]').html('Revert'); + $('#revert-'+commitHash).removeClass('btn-danger'); + $('#revert-'+commitHash).addClass('btn-success'); + $('#revert-'+commitHash).html('Page reverted
but not saved'); + window.wiki_page_commit = commitHash; + // put contents in editor + editor.getSession().setValue(data.content); + } else { + window.console.log('Error reverting page.'); + } + }, 'json'); + } + + function wiki_compare_page(compareCommit) { + if (window.wiki_resource_id === '' || window.wiki_page_name === '' || window.wiki_page_commit === '') { + window.console.log('You must have a wiki page open in order to revert pages.'); + return false; + } + $.post("wiki/{{$channel}}/compare/page", + { + compareCommit: compareCommit, + currentCommit: window.wiki_page_commit, + name: window.wiki_page_name, + resource_id: window.wiki_resource_id + }, + function (data) { + if (data.success) { + var modalBody = $('#generic-modal-body-{{$wikiModalID}}'); + modalBody.html('
'+data.diff+'
'); + $('.modal-dialog').width('80%'); + $("#generic-modal-ok-{{$wikiModalID}}").off('click'); + $("#generic-modal-ok-{{$wikiModalID}}").click(function () { + wiki_revert_page(compareCommit); + $('#generic-modal-{{$wikiModalID}}').modal('hide'); + }); + $('#generic-modal-{{$wikiModalID}}').modal(); + } else { + window.console.log('Error comparing page.'); + } + }, 'json'); + } + + $('#embed-image').click(function (ev) { + initializeEmbedPhotoDialog(); + ev.preventDefault(); + }); + + + var initializeEmbedPhotoDialog = function () { + $('.embed-photo-selected-photo').each(function (index) { + $(this).removeClass('embed-photo-selected-photo'); + }); + getPhotoAlbumList(); + $('#embedPhotoModalBodyAlbumDialog').off('click'); + $('#embedPhotoModal').modal(); + }; + + var choosePhotoFromAlbum = function (album) { + $.post("embedphotos/album", {name: album}, + function(data) { + if (data['status']) { + $('#embedPhotoModalLabel').html('{{$modalchooseimages}}'); + $('#embedPhotoModalBodyAlbumDialog').html('\ +

') + $('#embedPhotoModalBodyAlbumDialog').append(data['content']); + $('#embedPhotoModalBodyAlbumDialog').click(function (evt) { + evt.preventDefault(); + var image = document.getElementById(evt.target.id); + if (typeof($(image).parent()[0]) !== 'undefined') { + var imageparent = document.getElementById($(image).parent()[0].id); + $(imageparent).toggleClass('embed-photo-selected-photo'); + } + }); + $('#embedPhotoModalBodyAlbumListDialog').addClass('hide'); + $('#embedPhotoModalBodyAlbumDialog').removeClass('hide'); + $('#embed-photo-OKButton').click(function () { + $('.embed-photo-selected-photo').each(function (index) { + var href = $(this).attr('href'); + $.post("embedphotos/photolink", {href: href}, + function(ddata) { + if (ddata['status']) { + var imgURL = ddata['photolink'].replace( /\[.*\]\[.*\](.*)\[.*\]\[.*\]/, '\n![image]($1)' ) + editor.getSession().insert(editor.getCursorPosition(), imgURL) + } else { + window.console.log('{{$modalerrorlink}}' + ':' + ddata['errormsg']); + } + return false; + }, + 'json'); + }); + $('#embedPhotoModalBodyAlbumDialog').html(''); + $('#embedPhotoModalBodyAlbumDialog').off('click'); + $('#embedPhotoModal').modal('hide'); + }); + } else { + window.console.log('{{$modalerroralbum}} ' + JSON.stringify(album) + ':' + data['errormsg']); + } + return false; + }, + 'json'); + }; + + var getPhotoAlbumList = function () { + $.post("embedphotos/albumlist", {}, + function(data) { + if (data['status']) { + var albums = data['albumlist']; //JSON.parse(data['albumlist']); + $('#embedPhotoModalLabel').html('{{$modalchoosealbum}}'); + $('#embedPhotoModalBodyAlbumList').html(''); + for(var i=0; i' + albumName + ''; + albumLink += ''; + $('#embedPhotoModalBodyAlbumList').find('ul').append(albumLink); + } + $('#embedPhotoModalBodyAlbumDialog').addClass('hide'); + $('#embedPhotoModalBodyAlbumListDialog').removeClass('hide'); + } else { + window.console.log('{{$modalerrorlist}}' + ':' + data['errormsg']); + } + return false; + }, + 'json'); + }; + + function wiki_hide_forms() { + $('#new-page-form-wrapper').hide(); + $('#edit-wiki-form-wrapper').hide(); + $('#new-wiki-form-wrapper').hide(); + } + + function wiki_show_new_wiki_form() { + wiki_hide_forms(); + openClose('new-wiki-form-wrapper'); + return false; + } + + function wiki_show_new_page_form() { + wiki_hide_forms(); + openClose('new-page-form-wrapper'); + return false; + } + + function wiki_show_edit_wiki_form() { + wiki_hide_forms(); + openClose('edit-wiki-form-wrapper'); + return false; + } + + + $(document).ready(function () { + {{if $showNewWikiButton}} + $('#new-wiki-button').show(); + {{else}} + $('#new-wiki-button').hide(); + {{/if}} + {{if $showNewPageButton}} + $('#new-page-button').show(); + {{else}} + $('#new-page-button').hide(); + {{/if}} + }); + \ No newline at end of file diff --git a/view/tpl/wiki_page_list.tpl b/view/tpl/wiki_page_list.tpl index 1c3254465..c5f3ec9a0 100644 --- a/view/tpl/wiki_page_list.tpl +++ b/view/tpl/wiki_page_list.tpl @@ -1,6 +1,8 @@ {{if $not_refresh}}