diff --git a/app/models/wiki_reference.rb b/app/models/wiki_reference.rb index 82ef95dc..6277195b 100644 --- a/app/models/wiki_reference.rb +++ b/app/models/wiki_reference.rb @@ -80,7 +80,17 @@ class WikiReference < ActiveRecord::Base row = connection.select_one(sanitize_sql([query, page_name])) row['name'].as_utf8 if row end - + + def self.page_categories(web, page_name) + query = + "SELECT referenced_name FROM wiki_references JOIN pages " + + "ON wiki_references.page_id = pages.id " + + "WHERE pages.name = ? " + + "AND wiki_references.link_type = '#{CATEGORY}' " + + "AND pages.web_id = '#{web.id}'" + names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['referenced_name'].as_utf8 } + end + def self.pages_in_category(web, category) query = "SELECT name FROM pages JOIN wiki_references " + diff --git a/app/views/wiki/edit.rhtml b/app/views/wiki/edit.rhtml index a09bb005..b9239251 100644 --- a/app/views/wiki/edit.rhtml +++ b/app/views/wiki/edit.rhtml @@ -69,5 +69,9 @@ function cleanAuthorName() { } document.forms["editForm"].elements["content"].focus(); +<%- if [:markdownMML, :markdownPNG, :markdown].include?(@web.markup) and + !WikiReference.page_categories(@web, @page.name).include?('S5-slideshow') -%> +addS5button('<%= CGI.escapeHTML(@page.name) %>'); +<%- end -%> //--> diff --git a/app/views/wiki/new.rhtml b/app/views/wiki/new.rhtml index 339fdd34..b0c7ab70 100644 --- a/app/views/wiki/new.rhtml +++ b/app/views/wiki/new.rhtml @@ -31,4 +31,7 @@ function cleanAuthorName() { } } document.forms["editForm"].elements["content"].focus(); +<%- if [:markdownMML, :markdownPNG, :markdown].include?(@web.markup) -%> +addS5button('<%= CGI.escapeHTML(@page_name) %>'); +<%- end -%> diff --git a/public/javascripts/page_helper.js b/public/javascripts/page_helper.js index c476e6a5..297ba78f 100644 --- a/public/javascripts/page_helper.js +++ b/public/javascripts/page_helper.js @@ -53,6 +53,24 @@ function mactionWorkarounds() { }); } +function addS5button(page_name) { + var f = $('MarkupHelp'); + if (f) { + var s5button = new Element('input', {id:'S5button', type:'button', value: 'Make this page an S5 slideshow'}); + f.insert({top: s5button}); + Event.observe(s5button, 'click', function(){ + var preamble = "author: " + document.getElementById('author').value + + "\ncompany: \ntitle: " + page_name + + "\nsubtitle: \nslide_theme: default\nslide_footer: \nslide_subfooter: " + + "\n\n:category: S5-slideshow\n\n" + page_name + + "\n==============\n\nMy First Slide\n-----------------\n\n"; + var content = document.getElementById('content'); + content.value = preamble + content.value; + document.getElementById('S5button').hide(); + }); + } +} + function updateSize(elt, w, h) { // adjust to the size of the user's browser area. // w and h are the original, unadjusted, width and height per row/column