# HG changeset patch
# User Brian Neal
# Date 1467076277 18000
# Node ID 3f0a7e918c05bf5ed8af0c072db582fb44af905c
# Parent c245caccbbb3432198a3074258f3a090892bf076
Prepare to detach V3 post box from GCalendar.
diff -r c245caccbbb3 -r 3f0a7e918c05 core/templatetags/core_tags.py
--- a/core/templatetags/core_tags.py Mon Jun 27 18:40:59 2016 -0500
+++ b/core/templatetags/core_tags.py Mon Jun 27 20:11:17 2016 -0500
@@ -238,3 +238,10 @@
return {
'slides': slides,
}
+
+
+@register.inclusion_tag('core/v3/post_box.html')
+def post_box(form_field):
+ return {
+ 'form_field': form_field,
+ }
diff -r c245caccbbb3 -r 3f0a7e918c05 gcalendar/static/js/gcalendar.js
--- a/gcalendar/static/js/gcalendar.js Mon Jun 27 18:40:59 2016 -0500
+++ b/gcalendar/static/js/gcalendar.js Mon Jun 27 20:11:17 2016 -0500
@@ -1,46 +1,3 @@
-function editorReplaceText(textArea, i, j, newText) {
- textArea.value = textArea.value.substring(0, i) + newText +
- textArea.value.substring(j);
-}
-
-function editorWrapSelection(textArea, wrapText) {
- if (wrapText.length == 0) return;
- var i = textArea.selectionStart;
- var j = textArea.selectionEnd;
- if (i == j) return;
- var selection = textArea.value.substring(i, j);
- var newText = wrapText + selection + wrapText;
- editorReplaceText(textArea, i, j, newText);
- textArea.focus();
- textArea.setSelectionRange(i, j + 2 * wrapText.length);
-}
-
-function editorPrependLines(textArea, s) {
- if (s.length == 0) return;
- var i = textArea.selectionStart;
- var j = textArea.selectionEnd;
- var newText = s;
- var selection = textArea.value.substring(i, j);
- newText += selection.replace(/\n/gm, '\n' + s);
- editorReplaceText(textArea, i, j, newText);
-}
-
-function editorLink(textArea) {
- var i = textArea.selectionStart;
- var j = textArea.selectionEnd;
- var url = window.prompt("Please enter a URL:", "http://");
- if (!url) return;
- var link;
- if (i == j) {
- link = '[Link](' + url + ')';
- } else {
- var selection = textArea.value.substring(i, j);
- link = '[' + selection + '](' + url + ')';
- }
- editorReplaceText(textArea, i, j, link);
- textArea.focus();
-}
-
$(document).ready(function() {
$('#id_start_date').datepicker({constrainInput: true,
dateFormat: 'mm/dd/yy',
@@ -68,178 +25,4 @@
$('#id_all_day').click(function () {
$('.all-day-hide').toggle();
});
-
- var editorPanel = $('#editor-panel textarea');
- var previewPanel = $('#editor-preview-panel');
-
- $('#preview-modal').on('open.zf.reveal', function() {
- previewPanel.html('');
- previewPanel.scrollTop(0);
- // TODO:
- // Clear preview panel and/or show spinner
- // If there is any text in editor panel {
- $.ajax({
- url: '/comments/markdown/v3/',
- method: 'POST',
- data: {'data': editorPanel[0].value},
- dataType: 'html',
- success: function(data, textStatus) {
- previewPanel.html(data);
- },
- error: function (xhr, textStatus, ex) {
- alert('Oops, an error occurred: ' + xhr.statusText + ' - ' +
- xhr.responseText);
- }
- });
- });
-
- // Editor stuff
- var $postBox;
- $('.v3-editor').each(function (index) {
- var $this = $(this);
- var textArea = $this.find('textarea')[0];
- $this.find('.editor-bold').click(function () {
- editorWrapSelection(textArea, '**');
- return false;
- });
- $this.find('.editor-italic').click(function () {
- editorWrapSelection(textArea, '_');
- return false;
- });
- $this.find('.editor-strike').click(function () {
- editorWrapSelection(textArea, '---');
- return false;
- });
- $this.find('.editor-link').click(function () {
- editorLink(textArea);
- return false;
- });
- $this.find('.editor-quote').click(function () {
- editorPrependLines(textArea, '> ');
- return false;
- });
- $this.find('.editor-code').click(function () {
- editorPrependLines(textArea, ' ');
- return false;
- });
- $this.find('.editor-bullet').click(function () {
- editorPrependLines(textArea, '* ');
- return false;
- });
- $this.find('.editor-number').click(function () {
- editorPrependLines(textArea, '1. ');
- return false;
- });
- $this.find('.editor-hot-link').click(function () {
- $postBox = $(textArea);
- });
- $this.find('.editor-upload').click(function () {
- $postBox = $(textArea);
- });
- });
-
- var $hotLinkForm = $('#hot-link-form');
- if ($hotLinkForm.length) {
- var $hotLinkFormSubmit = $('#hot-link-form-submit');
- var $hotLinkStatus = $('#hot-link-status');
-
- $('#hot-link-modal').on('open.zf.reveal', function() {
- $hotLinkForm.clearForm();
- });
- $('#hot-link-modal').on('closed.zf.reveal', function() {
- $hotLinkStatus.hide();
- });
-
- $hotLinkForm.ajaxForm({
- dataType: 'json',
- beforeSubmit: function(arr, $form, options) {
- var url = null;
- $.each(arr, function(index, val) {
- if (val.name == 'url') {
- url = val.value;
- }
- });
- if (!url) {
- $hotLinkStatus.removeClass('success').addClass('alert');
- $hotLinkStatus.html("Please enter a link to an image.");
- $hotLinkStatus.fadeIn(700);
- return false;
- } else {
- $hotLinkStatus.hide();
- }
- $hotLinkFormSubmit.attr('disabled', 'disabled').val('Retrieving...');
- $hotLinkFormSubmit.addClass('disabled');
- return true;
- },
- success: function(resp, statusText, xhr, $form) {
- $postBox.val($postBox.val() + '\n![image](' + resp.url + ')');
- $hotLinkStatus.removeClass('alert').addClass('success');
- $hotLinkStatus.html("Success! The image code was added to your post.");
- $hotLinkStatus.fadeIn(700);
- $hotLinkForm.clearForm();
- },
- complete: function(xhr) {
- $hotLinkFormSubmit.removeAttr('disabled').val('Hot Link');
- $hotLinkFormSubmit.removeClass('disabled');
- },
- error: function(xhr, textStatus, ex) {
- $hotLinkStatus.removeClass('success').addClass('alert');
- var resp = $.parseJSON(xhr.responseText);
- $hotLinkStatus.html("Error: " + ex + ' - ' + resp.error_msg);
- $hotLinkStatus.fadeIn(700);
- }
- });
- }
- var $photoForm = $('#photo-upload-form');
- if ($photoForm.length) {
- var $photoUploadSubmit = $('#photo-upload-submit');
- var $photoStatus = $('#photo-status');
-
- $('#upload-modal').on('open.zf.reveal', function() {
- $photoForm.clearForm();
- });
- $('#upload-modal').on('closed.zf.reveal', function() {
- $photoStatus.hide();
- });
-
- $photoForm.ajaxForm({
- dataType: 'json',
- beforeSubmit: function(arr, $form, options) {
- var fileObj = null;
- $.each(arr, function(index, val) {
- if (val.name == 'image_file') {
- fileObj = val.value;
- }
- });
- if (!fileObj) {
- $photoStatus.removeClass('success').addClass('alert');
- $photoStatus.html("Please choose a file to upload.");
- $photoStatus.fadeIn(700);
- return false;
- } else {
- $photoStatus.hide();
- }
- $photoUploadSubmit.attr('disabled', 'disabled').val('Uploading...');
- $photoUploadSubmit.addClass('disabled');
- return true;
- },
- success: function(resp, statusText, xhr, $form) {
- $postBox.val($postBox.val() + '\n![image](' + resp.url + ')');
- $photoStatus.removeClass('alert').addClass('success');
- $photoStatus.html("Success! The image code was added to your post.");
- $photoStatus.fadeIn(700);
- $photoStatus.clearForm();
- },
- complete: function(xhr) {
- $photoUploadSubmit.removeAttr('disabled').val('Upload photo');
- $photoUploadSubmit.removeClass('disabled');
- },
- error: function(xhr, textStatus, ex) {
- $photoStatus.removeClass('success').addClass('alert');
- var resp = $.parseJSON(xhr.responseText);
- $photoStatus.html("Error: " + ex + ' - ' + resp.error_msg);
- $photoStatus.fadeIn(700);
- }
- });
- }
});
diff -r c245caccbbb3 -r 3f0a7e918c05 sg101/static/js/v3/post_box.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sg101/static/js/v3/post_box.js Mon Jun 27 20:11:17 2016 -0500
@@ -0,0 +1,218 @@
+function editorReplaceText(textArea, i, j, newText) {
+ textArea.value = textArea.value.substring(0, i) + newText +
+ textArea.value.substring(j);
+}
+
+function editorWrapSelection(textArea, wrapText) {
+ if (wrapText.length == 0) return;
+ var i = textArea.selectionStart;
+ var j = textArea.selectionEnd;
+ if (i == j) return;
+ var selection = textArea.value.substring(i, j);
+ var newText = wrapText + selection + wrapText;
+ editorReplaceText(textArea, i, j, newText);
+ textArea.focus();
+ textArea.setSelectionRange(i, j + 2 * wrapText.length);
+}
+
+function editorPrependLines(textArea, s) {
+ if (s.length == 0) return;
+ var i = textArea.selectionStart;
+ var j = textArea.selectionEnd;
+ var newText = s;
+ var selection = textArea.value.substring(i, j);
+ newText += selection.replace(/\n/gm, '\n' + s);
+ editorReplaceText(textArea, i, j, newText);
+}
+
+function editorLink(textArea) {
+ var i = textArea.selectionStart;
+ var j = textArea.selectionEnd;
+ var url = window.prompt("Please enter a URL:", "http://");
+ if (!url) return;
+ var link;
+ if (i == j) {
+ link = '[Link](' + url + ')';
+ } else {
+ var selection = textArea.value.substring(i, j);
+ link = '[' + selection + '](' + url + ')';
+ }
+ editorReplaceText(textArea, i, j, link);
+ textArea.focus();
+}
+
+$(document).ready(function() {
+ var editorPanel = $('#editor-panel textarea');
+ var previewPanel = $('#editor-preview-panel');
+
+ $('#preview-modal').on('open.zf.reveal', function() {
+ previewPanel.html('');
+ previewPanel.scrollTop(0);
+ // TODO:
+ // Clear preview panel and/or show spinner
+ // If there is any text in editor panel {
+ $.ajax({
+ url: '/comments/markdown/v3/',
+ method: 'POST',
+ data: {'data': editorPanel[0].value},
+ dataType: 'html',
+ success: function(data, textStatus) {
+ previewPanel.html(data);
+ },
+ error: function (xhr, textStatus, ex) {
+ alert('Oops, an error occurred: ' + xhr.statusText + ' - ' +
+ xhr.responseText);
+ }
+ });
+ });
+
+ // Editor stuff
+ var $postBox;
+ $('.v3-editor').each(function (index) {
+ var $this = $(this);
+ var textArea = $this.find('textarea')[0];
+ $this.find('.editor-bold').click(function () {
+ editorWrapSelection(textArea, '**');
+ return false;
+ });
+ $this.find('.editor-italic').click(function () {
+ editorWrapSelection(textArea, '_');
+ return false;
+ });
+ $this.find('.editor-strike').click(function () {
+ editorWrapSelection(textArea, '---');
+ return false;
+ });
+ $this.find('.editor-link').click(function () {
+ editorLink(textArea);
+ return false;
+ });
+ $this.find('.editor-quote').click(function () {
+ editorPrependLines(textArea, '> ');
+ return false;
+ });
+ $this.find('.editor-code').click(function () {
+ editorPrependLines(textArea, ' ');
+ return false;
+ });
+ $this.find('.editor-bullet').click(function () {
+ editorPrependLines(textArea, '* ');
+ return false;
+ });
+ $this.find('.editor-number').click(function () {
+ editorPrependLines(textArea, '1. ');
+ return false;
+ });
+ $this.find('.editor-hot-link').click(function () {
+ $postBox = $(textArea);
+ });
+ $this.find('.editor-upload').click(function () {
+ $postBox = $(textArea);
+ });
+ });
+
+ var $hotLinkForm = $('#hot-link-form');
+ if ($hotLinkForm.length) {
+ var $hotLinkFormSubmit = $('#hot-link-form-submit');
+ var $hotLinkStatus = $('#hot-link-status');
+
+ $('#hot-link-modal').on('open.zf.reveal', function() {
+ $hotLinkForm.clearForm();
+ });
+ $('#hot-link-modal').on('closed.zf.reveal', function() {
+ $hotLinkStatus.hide();
+ });
+
+ $hotLinkForm.ajaxForm({
+ dataType: 'json',
+ beforeSubmit: function(arr, $form, options) {
+ var url = null;
+ $.each(arr, function(index, val) {
+ if (val.name == 'url') {
+ url = val.value;
+ }
+ });
+ if (!url) {
+ $hotLinkStatus.removeClass('success').addClass('alert');
+ $hotLinkStatus.html("Please enter a link to an image.");
+ $hotLinkStatus.fadeIn(700);
+ return false;
+ } else {
+ $hotLinkStatus.hide();
+ }
+ $hotLinkFormSubmit.attr('disabled', 'disabled').val('Retrieving...');
+ $hotLinkFormSubmit.addClass('disabled');
+ return true;
+ },
+ success: function(resp, statusText, xhr, $form) {
+ $postBox.val($postBox.val() + '\n![image](' + resp.url + ')');
+ $hotLinkStatus.removeClass('alert').addClass('success');
+ $hotLinkStatus.html("Success! The image code was added to your post.");
+ $hotLinkStatus.fadeIn(700);
+ $hotLinkForm.clearForm();
+ },
+ complete: function(xhr) {
+ $hotLinkFormSubmit.removeAttr('disabled').val('Hot Link');
+ $hotLinkFormSubmit.removeClass('disabled');
+ },
+ error: function(xhr, textStatus, ex) {
+ $hotLinkStatus.removeClass('success').addClass('alert');
+ var resp = $.parseJSON(xhr.responseText);
+ $hotLinkStatus.html("Error: " + ex + ' - ' + resp.error_msg);
+ $hotLinkStatus.fadeIn(700);
+ }
+ });
+ }
+ var $photoForm = $('#photo-upload-form');
+ if ($photoForm.length) {
+ var $photoUploadSubmit = $('#photo-upload-submit');
+ var $photoStatus = $('#photo-status');
+
+ $('#upload-modal').on('open.zf.reveal', function() {
+ $photoForm.clearForm();
+ });
+ $('#upload-modal').on('closed.zf.reveal', function() {
+ $photoStatus.hide();
+ });
+
+ $photoForm.ajaxForm({
+ dataType: 'json',
+ beforeSubmit: function(arr, $form, options) {
+ var fileObj = null;
+ $.each(arr, function(index, val) {
+ if (val.name == 'image_file') {
+ fileObj = val.value;
+ }
+ });
+ if (!fileObj) {
+ $photoStatus.removeClass('success').addClass('alert');
+ $photoStatus.html("Please choose a file to upload.");
+ $photoStatus.fadeIn(700);
+ return false;
+ } else {
+ $photoStatus.hide();
+ }
+ $photoUploadSubmit.attr('disabled', 'disabled').val('Uploading...');
+ $photoUploadSubmit.addClass('disabled');
+ return true;
+ },
+ success: function(resp, statusText, xhr, $form) {
+ $postBox.val($postBox.val() + '\n![image](' + resp.url + ')');
+ $photoStatus.removeClass('alert').addClass('success');
+ $photoStatus.html("Success! The image code was added to your post.");
+ $photoStatus.fadeIn(700);
+ $photoStatus.clearForm();
+ },
+ complete: function(xhr) {
+ $photoUploadSubmit.removeAttr('disabled').val('Upload photo');
+ $photoUploadSubmit.removeClass('disabled');
+ },
+ error: function(xhr, textStatus, ex) {
+ $photoStatus.removeClass('success').addClass('alert');
+ var resp = $.parseJSON(xhr.responseText);
+ $photoStatus.html("Error: " + ex + ' - ' + resp.error_msg);
+ $photoStatus.fadeIn(700);
+ }
+ });
+ }
+});
diff -r c245caccbbb3 -r 3f0a7e918c05 sg101/templates/core/v3/post_box.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sg101/templates/core/v3/post_box.html Mon Jun 27 20:11:17 2016 -0500
@@ -0,0 +1,27 @@
+{{ form_field.errors }}
+
+
+
{{ form_field.label }}
+
+
+ {{ form_field }}
+
+
+
diff -r c245caccbbb3 -r 3f0a7e918c05 sg101/templates/core/v3/post_box_modals.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sg101/templates/core/v3/post_box_modals.html Mon Jun 27 20:11:17 2016 -0500
@@ -0,0 +1,218 @@
+
+
+ ×
+
+
+
+
+
+ To add an image already on the Internet to your post, copy & paste the
+ image address to the box below and click "Hot-Link". An image code will be placed
+ in your post after the image is processed.
+
+
+
+
+
+
+
+
+ ×
+
+
+
+
+
+ You can upload an image directly from your computer or device with this
+ form. After the image is uploaded it will be resized and an image code will be
+ placed your post.
+
+
+
+
+
+
+
+
+
diff -r c245caccbbb3 -r 3f0a7e918c05 sg101/templates/gcalendar/event.html
--- a/sg101/templates/gcalendar/event.html Mon Jun 27 18:40:59 2016 -0500
+++ b/sg101/templates/gcalendar/event.html Mon Jun 27 20:11:17 2016 -0500
@@ -114,33 +114,7 @@
- {{ form.description.errors }}
-
-
-
{{ form.description.label }}
-
-
- {{ form.description }}
-
-
-
+ {% post_box form.description %}
{% if form.create_forum_thread %}
{{ form.create_forum_thread.errors }}
@@ -157,230 +131,13 @@
value="{% if is_new %}Add{% else %}Update{% endif %} Event"
class="primary button" />
-
-
-
- ×
-
-
-
-
-
- To add an image already on the Internet to your post, copy & paste the
- image address to the box below and click "Hot-Link". An image code will be placed
- in your post after the image is processed.
-
-
-
-
-
-
-
-
- ×
-
-
-
-
-
- You can upload an image directly from your computer or device with this
- form. After the image is uploaded it will be resized and an image code will be
- placed your post.
-
-
-
-
-
-
-
-
-
+{% include 'core/v3/post_box_modals.html' %}
{% endblock %}
{% block custom_js %}
{% js_tags 'jquery-ui' %}
+
{% endblock %}