{% extends 'desktop.html' %}


{% load crispy_forms_tags %}

{% block header %}

{% endblock %}
{% block title %} Page Edit {% endblock %}

{% block content %}
<script type="text/javascript" src="{{ STATIC_URL }}tinymce/js/tinymce/jquery.tinymce.min.js"></script>
<script type="text/javascript">

function endsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

    function onComplete(id,filename,response)
{
    if (endsWith(filename.toLowerCase(),'jpg'))
	  $('#id_content').tinymce().execCommand('mceInsertContent',false,'<img src="' + response.url +  '">');
    else if (endsWith(filename.toLowerCase(),'gif'))
	  $('#id_content').tinymce().execCommand('mceInsertContent',false,'<img src="' + response.url +  '">');
    else if (endsWith(filename.toLowerCase(),'jpeg'))
	  $('#id_content').tinymce().execCommand('mceInsertContent',false,'<img src="' + response.url +  '">');
    else
	  $('#id_content').tinymce().execCommand('mceInsertContent',false,'<br /><a href="' + response.url +  '">' + filename + '</a>');

}
        $(function() {
                $('#id_content').tinymce({
                        // Location of TinyMCE script
                        script_url : '{{ STATIC_URL }}tinymce/js/tinymce/tinymce.min.js',
                         //width:"100%",
                         height:"600px",
                         extended_valid_elements : "script[type|src],iframe[src|style|width|height|scrolling|marginwidth|marginheight|frameborder]",
                         valid_children : "+body[style]" ,
                         preformatted : true,
                         removed_menuitems: 'newdocument',
                         apply_source_formatting : true,
                        // General options
						theme : "modern",
						plugins : "{{PAGE_TINYMCE_PLUGINS}},table,preview,media,searchreplace,paste,fullscreen,noneditable,visualchars,nonbreaking,link,image,code,autolink",
                        noneditable_leave_contenteditable: true,

					// Drop lists for link/image/media/template dialogs
		//			template_external_list_url : "/lists/template_list.js",
					link_list : "links?uuid={{uuid}}",
					image_list : "images?uuid={{uuid}}",
					//media_external_list_url : external_link_list_url,
					relative_urls : false,
			         noneditable_leave_contenteditable : true,
                    toolbar1  : 'undo redo | bold italic underline | ' +
                    'alignleft aligncenter alignright alignjustify  | ' +
                    'bullist numlist | outdent indent |  blockquote removeformat | link image| news feeds'

                });

        });

</script>
   <a href="/{{object.slug}}?history=1">History</a>
{% crispy form %}
<br />
{% if perms.page.delete_page %}
    <br />
	<a class="btn btn-danger" href="{% url 'page_delete' object.slug %}" > Delete Page</a>
{% endif %}

  <h2>Page Editors</h2>
	<ol>
		{% for editor in editors %}
			<li>
				{{editor.editor.get_full_name}} ({{editor.editor.username}})
				{% if perms.page.delete_editor_page %}
					<a class="btn btn-danger" href="{% url 'editor_delete' object.slug editor.pk %}" > Delete </a>
				{% endif %}
			</li>
		{% endfor %}
		{% if perms.page.add_editor_page %}
			<li><a class="btn btn-primary"  href="{% url 'editor_add' object.slug %}">Add</a></li>
		{% endif %}
	</ol>



{% endblock %}