diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-04-25 19:57:22 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-04-25 19:57:22 -0400 |
commit | a78a6f0c7ae03d0460b72762d89cb5a55b527de6 (patch) | |
tree | f565a499a2fd3e1f40a954f135507fdfaf50ff07 | |
parent | 21b5afd54940d7bb2aba071281d213ff9315530a (diff) | |
download | askbot-a78a6f0c7ae03d0460b72762d89cb5a55b527de6.tar.gz askbot-a78a6f0c7ae03d0460b72762d89cb5a55b527de6.tar.bz2 askbot-a78a6f0c7ae03d0460b72762d89cb5a55b527de6.zip |
improved the tag wiki editor and made the WMD editor and the previewer work for the TagWikiEditor class
-rw-r--r-- | askbot/skins/common/media/js/post.js | 119 | ||||
-rw-r--r-- | askbot/skins/common/media/js/wmd/wmd.js | 8 | ||||
-rw-r--r-- | askbot/skins/default/media/style/style.less | 28 | ||||
-rw-r--r-- | askbot/skins/default/templates/groups.html | 2 | ||||
-rw-r--r-- | askbot/skins/default/templates/meta/bottom_scripts.html | 1 | ||||
-rw-r--r-- | askbot/skins/default/templates/meta/html_head_stylesheets.html | 1 | ||||
-rw-r--r-- | askbot/skins/default/templates/user_profile/user_inbox.html | 4 | ||||
-rw-r--r-- | askbot/skins/default/templates/users.html | 90 | ||||
-rw-r--r-- | askbot/urls.py | 5 | ||||
-rw-r--r-- | askbot/views/commands.py | 17 |
10 files changed, 212 insertions, 63 deletions
diff --git a/askbot/skins/common/media/js/post.js b/askbot/skins/common/media/js/post.js index 4c25c551..f221536a 100644 --- a/askbot/skins/common/media/js/post.js +++ b/askbot/skins/common/media/js/post.js @@ -1957,7 +1957,7 @@ WMD.prototype.getMarkdown = function(){ }; WMD.prototype.start = function(){ - Attacklab.Util.startEditor(); + Attacklab.Util.startEditor(true); this._textarea.keyup(makeKeyHandler(27, this._escape_handler)); }; @@ -1968,6 +1968,7 @@ var TagWikiEditor = function(){ WrappedElement.call(this); this._state = 'display';//'edit' or 'display' this._content_backup = ''; + this._is_editor_loaded = false; }; inherits(TagWikiEditor, WrappedElement); @@ -1986,11 +1987,13 @@ TagWikiEditor.prototype.setState = function(state){ this._edit_btn.hide(); this._cancel_btn.show(); this._save_btn.show(); + this._cancel_sep.show(); } else if (state === 'display'){ this._state = state; this._edit_btn.show(); this._cancel_btn.hide(); - this._save_btn.(); + this._cancel_sep.hide(); + this._save_btn.hide(); } }; @@ -2006,6 +2009,14 @@ TagWikiEditor.prototype.getTagId = function(){ return this._tag_id; }; +TagWikiEditor.prototype.isEditorLoaded = function(){ + return this._is_editor_loaded; +}; + +TagWikiEditor.prototype.setEditorLoaded = function(){ + return this._is_editor_loaded = true; +}; + /** * loads initial data for the editor input and activates * the editor @@ -2023,18 +2034,22 @@ TagWikiEditor.prototype.startActivatingEditor = function(){ editor.setMarkdown(data); me.setContent(editor.getElement()); me.setState('edit'); - editor.start(); + if (me.isEditorLoaded() === false){ + editor.start(); + me.setEditorLoaded(); + } } }); }; -TagWikiEditor.prototype.saveData = function(markdown){ +TagWikiEditor.prototype.saveData = function(){ var me = this; + var text = this._editor.getMarkdown(); $.ajax({ type: 'POST', dataType: 'json', url: askbot['urls']['save_tag_wiki_text'], - data: {tag_id: me.getTagId(), text: markdown}, + data: {tag_id: me.getTagId(), text: text}, cache: false, success: function(data){ if (data['success']){ @@ -2048,43 +2063,52 @@ TagWikiEditor.prototype.saveData = function(markdown){ }; TagWikiEditor.prototype.cancelEdit = function(){ - me.restoreContent(); - me.setState('display'); + this.restoreContent(); + this.setState('display'); }; TagWikiEditor.prototype.decorate = function(element){ //expect <div id='group-wiki-{{id}}'><div class="content"/><a class="edit"/></div> this._element = element; - var edit_btn = element.find('.edit'); + var edit_btn = element.find('.edit-description'); this._edit_btn = edit_btn; + //adding two buttons... var save_btn = this.makeElement('a'); - save_btn.addClass('btn'); save_btn.html(gettext('save')); edit_btn.after(save_btn); save_btn.hide(); this._save_btn = save_btn; var cancel_btn = this.makeElement('a'); - cancel_btn.addClass('btn'); cancel_btn.html(gettext('cancel')); save_btn.after(cancel_btn); cancel_btn.hide(); this._cancel_btn = cancel_btn; + this._cancel_sep = $('<span> | </span>'); + cancel_btn.before(this._cancel_sep); + this._cancel_sep.hide(); + this._content_box = element.find('.content'); this._tag_id = element.attr('id').split('-').pop(); var me = this; var editor = new WMD(); editor.setEscapeHandler(function(){me.cancelEdit()}); + this._editor = editor; setupButtonEventHandlers(edit_btn, function(){ me.startActivatingEditor() }); setupButtonEventHandlers(cancel_btn, function(){me.cancelEdit()}); + setupButtonEventHandlers(save_btn, function(){me.saveData()}); }; var ImageChanger = function(){ WrappedElement.call(this); this._image_element = undefined; + this._delete_button = undefined; + this._save_url = undefined; + this._delete_url = undefined; + this._messages = undefined; }; inherits(ImageChanger, WrappedElement); @@ -2092,16 +2116,50 @@ ImageChanger.prototype.setImageElement = function(image_element){ this._image_element = image_element; }; +ImageChanger.prototype.setMessages = function(messages){ + this._messages = messages; +}; + +ImageChanger.prototype.setDeleteButton = function(delete_button){ + this._delete_button = delete_button; +}; + ImageChanger.prototype.setSaveUrl = function(url){ this._save_url = url; }; +ImageChanger.prototype.setDeleteUrl = function(url){ + this._delete_url = url; +}; + ImageChanger.prototype.setAjaxData = function(data){ this._ajax_data = data; }; ImageChanger.prototype.showImage = function(image_url){ this._image_element.attr('src', image_url); + this._image_element.show(); +}; + +ImageChanger.prototype.deleteImage = function(){ + this._image_element.attr('src', ''); + this._image_element.css('display', 'none'); + + var me = this; + var delete_url = this._delete_url; + var data = this._ajax_data; + $.ajax({ + type: 'POST', + dataType: 'json', + url: delete_url, + data: data, + cache: false, + success: function(data){ + if (data['success'] === true){ + showMessage(me.getElement(), data['message'], 'after'); + } + } + }); }; ImageChanger.prototype.saveImageUrl = function(image_url){ @@ -2126,6 +2184,8 @@ ImageChanger.prototype.saveImageUrl = function(image_url){ ImageChanger.prototype.startDialog = function(){ //reusing the wmd's file uploader var me = this; + var change_image_text = this._messages['change_image']; + var change_image_button = this._element; Attacklab.Util.prompt( "<h3>" + gettext('Enter the logo url or upload an image') + '</h3>', 'http://', @@ -2133,12 +2193,36 @@ ImageChanger.prototype.startDialog = function(){ if (image_url){ me.saveImageUrl(image_url); me.showImage(image_url); + change_image_button.html(change_image_text); + me.showDeleteButton(); } }, 'image' ); }; +ImageChanger.prototype.showDeleteButton = function(){ + this._delete_button.show(); + this._delete_button.prev().show(); +}; + +ImageChanger.prototype.hideDeleteButton = function(){ + this._delete_button.hide(); + this._delete_button.prev().hide(); +}; + + +ImageChanger.prototype.startDeleting = function(){ + if (confirm(gettext('Do you really want to remove the image?'))){ + this.deleteImage(); + this._element.html(this._messages['add_image']); + this.hideDeleteButton(); + this._delete_button.hide(); + var sep = this._delete_button.prev(); + sep.hide(); + }; +}; + /** * decorates an element that will serve as the image changer button */ @@ -2151,6 +2235,12 @@ ImageChanger.prototype.decorate = function(element){ me.startDialog(); } ); + setupButtonEventHandlers( + this._delete_button, + function(){ + me.startDeleting(); + } + ) }; var UserGroupProfileEditor = function(){ @@ -2160,7 +2250,7 @@ inherits(UserGroupProfileEditor, TagWikiEditor); UserGroupProfileEditor.prototype.decorate = function(element){ UserGroupProfileEditor.superClass_.decorate.call(this, element); - var change_logo_btn = element.find('.change_logo'); + var change_logo_btn = element.find('.change-logo'); this._change_logo_btn = change_logo_btn; var logo_changer = new ImageChanger(); @@ -2169,6 +2259,13 @@ UserGroupProfileEditor.prototype.decorate = function(element){ group_id: this.getTagId() }); logo_changer.setSaveUrl(askbot['urls']['save_group_logo_url']); + logo_changer.setDeleteUrl(askbot['urls']['delete_group_logo_url']); + logo_changer.setMessages({ + change_image: gettext('change logo'), + add_image: gettext('add logo') + }); + var delete_logo_btn = element.find('.delete-logo'); + logo_changer.setDeleteButton(delete_logo_btn); logo_changer.decorate(change_logo_btn); }; diff --git a/askbot/skins/common/media/js/wmd/wmd.js b/askbot/skins/common/media/js/wmd/wmd.js index 9f941855..90b59a56 100644 --- a/askbot/skins/common/media/js/wmd/wmd.js +++ b/askbot/skins/common/media/js/wmd/wmd.js @@ -1817,7 +1817,7 @@ util.prompt = function(text, defaultInputText, makeLinkMarkdown, dialogType){ wmd.wmd.previewManager = wmd.previewManager; }; - util.startEditor = function(){ + util.startEditor = function(start_now){ if (wmd.wmd_env.autostart === false) { util.makeAPI(); @@ -1841,7 +1841,11 @@ util.prompt = function(text, defaultInputText, makeLinkMarkdown, dialogType){ }; - util.addEvent(top, "load", loadListener); + if (start_now){ + loadListener(); + } else { + util.addEvent(top, "load", loadListener); + } }; wmd.previewManager = function(){ diff --git a/askbot/skins/default/media/style/style.less b/askbot/skins/default/media/style/style.less index 5b24a15c..be53f4f8 100644 --- a/askbot/skins/default/media/style/style.less +++ b/askbot/skins/default/media/style/style.less @@ -151,7 +151,7 @@ a:hover { h1 { font-size: 24px; - padding: 10px 0 5px 0px; + padding: 0px 0 5px 0px; } /* ----- Extra space above for messages ----- */ @@ -866,6 +866,10 @@ ul#searchTags { width: 100%; } +.main-page #question-list { + margin-top: 10px; +} + .short-summary { position: relative; filter: inherit; @@ -2250,13 +2254,11 @@ ul#related-tags li { }*/ .user { - padding: 5px; + padding: 5px 10px 5px 0; line-height: 140%; width: 166px; height: 32px; - border:#eee 1px solid; margin-bottom:5px; - .rounded-corners(3px); .user-micro-info{ color:@info-text-dark; } @@ -3073,8 +3075,11 @@ button::-moz-focus-inner { -webkit-border-radius: 5px; } -.list-table td { - vertical-align: top; +.list-table { + td { + vertical-align: top; + } + border-spacing: 0; } /* these need to go */ @@ -3410,10 +3415,6 @@ body.anon.lang-es { } .users-page { - #editor { - border: 2px #CCE6EC solid; - padding: 0px; - } .wmd-prompt-dialog { background: #ccc; } @@ -3422,10 +3423,15 @@ body.anon.lang-es { .group-wiki { .content { float: left; - margin-bottom: -12px; + p:last-child { + margin-bottom: 5px; + } } .group-logo { float: left; margin: 0 5px 3px 0; } + .controls { + margin: 0 0 10px 0; + } } diff --git a/askbot/skins/default/templates/groups.html b/askbot/skins/default/templates/groups.html index 9ca49c85..23deb177 100644 --- a/askbot/skins/default/templates/groups.html +++ b/askbot/skins/default/templates/groups.html @@ -1,7 +1,7 @@ {% extends 'one_column_body.html' %} {% block title %}{% trans %}Groups{% endtrans %}{% endblock %} {% block content %} - <h1>{% trans %}Groups{% endtrans %}</h1> + <h1 class="section-title">{% trans %}Groups{% endtrans %}</h1> {% if can_edit %} <p id="group-add-tip"> {% trans %}Tip: to create a new group - please go to some user profile and add the new group there. That user will be the first member of the group{% endtrans %} diff --git a/askbot/skins/default/templates/meta/bottom_scripts.html b/askbot/skins/default/templates/meta/bottom_scripts.html index 776735f5..2603ec31 100644 --- a/askbot/skins/default/templates/meta/bottom_scripts.html +++ b/askbot/skins/default/templates/meta/bottom_scripts.html @@ -32,7 +32,6 @@ <script type='text/javascript' src="{{"/js/jquery.history.js"|media }}"></script> <script type="text/javascript" src="{% url django.views.i18n.javascript_catalog %}"></script> <script type='text/javascript' src="{{"/js/utils.js"|media }}"></script> -<script type="text/javascript" src="{{'/bootstrap/js/bootstrap.js'|media}}" /> {% if settings.ENABLE_MATHJAX %} <script type='text/javascript' src="{{settings.MATHJAX_BASE_URL}}/MathJax.js"> MathJax.Hub.Config({ diff --git a/askbot/skins/default/templates/meta/html_head_stylesheets.html b/askbot/skins/default/templates/meta/html_head_stylesheets.html index 86fcee7f..14f3c106 100644 --- a/askbot/skins/default/templates/meta/html_head_stylesheets.html +++ b/askbot/skins/default/templates/meta/html_head_stylesheets.html @@ -1,6 +1,5 @@ {% if settings.ASKBOT_CSS_DEVEL == False %} <link href="{{"/style/style.css"|media }}" rel="stylesheet" type="text/css" /> -<link href="{{'/bootstrap/css/bootstrap.min.css'|media}}" rel="stylesheet" type="text/css" /> {% else %} <link href="{{"/style/style.less"|media }}" rel="stylesheet/less" type="text/css" /> <script type="text/javascript" src="{{"/js/less.min.js"|media}}"></script> diff --git a/askbot/skins/default/templates/user_profile/user_inbox.html b/askbot/skins/default/templates/user_profile/user_inbox.html index 2c4d1e23..8d1a75fd 100644 --- a/askbot/skins/default/templates/user_profile/user_inbox.html +++ b/askbot/skins/default/templates/user_profile/user_inbox.html @@ -1,5 +1,8 @@ {% extends "user_profile/user.html" %} {% import "macros.html" as macros %} +{% block forestyle %} + <link href="{{'/bootstrap/css/bootstrap.min.css'|media}}" rel="stylesheet" type="text/css" /> +{% endblock %} <!-- user_responses.html --> {# This template accepts a list of response list @@ -134,5 +137,6 @@ inbox_section - forum|flags ) {% endfor %} </script> + <script type="text/javascript" src="{{'/bootstrap/js/bootstrap.js'|media}}" /> <!-- end user_responses.html --> {% endblock %} diff --git a/askbot/skins/default/templates/users.html b/askbot/skins/default/templates/users.html index 41bb50cf..de0d5e54 100644 --- a/askbot/skins/default/templates/users.html +++ b/askbot/skins/default/templates/users.html @@ -2,6 +2,9 @@ {% import "macros.html" as macros %} <!-- users.html --> {% block title %}{% spaceless %}{% trans %}Users{% endtrans %}{% endspaceless %}{% endblock %} +{% block forestyle %} + <link rel="stylesheet" type="text/css" href="{{"/js/wmd/wmd.css"|media}}" /> +{% endblock %} {% block content %} <h1 class="section-title"> {% if group %} @@ -42,19 +45,19 @@ </div> </div> <div class="clean"></div> -<p> - {% if suser %} - {% trans %}users matching query {{suser}}:{% endtrans %} - {% endif %} - {% if not users.object_list %} - <span>{% trans %}Nothing found.{% endtrans %}</span> - {% endif %} -</p> +{% if suser %} + <p>{% trans %}users matching query {{suser}}:{% endtrans %}</p> +{% endif %} +{% if not users.object_list %} + <p><span>{% trans %}Nothing found.{% endtrans %}</span></p> +{% endif %} {% if group %} <div id="group-wiki-{{group.id}}" class="group-wiki"> <img class="group-logo" {% if group.group_profile.logo_url %} src="{{ group.group_profile.logo_url }}" + {% else %} + style="display:none" {% endif %} /> <div class="content"> @@ -64,12 +67,22 @@ </div> <div class="clearfix"></div> {% if request.user.is_authenticated() and request.user.is_administrator_or_moderator() %} - <a class="edit btn"> - {% trans %}edit group description{% endtrans %} - </a> - <a class="change_logo btn"> - {% trans %}change logo{% endtrans %} - </a> + <div class="controls"> + <a class="edit-description" + >{% trans %}edit description{% endtrans %}</a> + {% if group.group_profile.logo_url %} + <span>|</span> + <a class="change-logo" + >{% trans %}change logo{% endtrans %}</a> + <span>|</span> + <a class="delete-logo">{% trans %}delete logo{% endtrans %}</a> + {% else %} + <span>|</span> + <a class="change-logo" + >{% trans %}add logo{% endtrans %}</a> + {% endif %} + + </div> {% endif %} </div> {% endif %} @@ -90,6 +103,7 @@ askbot['urls']['load_tag_wiki_text'] = '{% url load_tag_wiki_text %}'; askbot['urls']['save_tag_wiki_text'] = '{% url save_tag_wiki_text %}'; askbot['urls']['save_group_logo_url'] = '{% url save_group_logo_url %}'; + askbot['urls']['delete_group_logo_url'] = '{% url delete_group_logo %}'; </script> <script type='text/javascript' src='{{"/js/editor.js"|media}}'></script> <script type='text/javascript' src='{{"/js/wmd/showdown.js"|media}}'></script> @@ -98,33 +112,37 @@ <script src='{{"/js/post.js"|media}}' type='text/javascript'></script> <script type="text/javascript"> //todo move javascript out + {% if settings.ENABLE_MATHJAX or settings.MARKUP_CODE_FRIENDLY %} + var codeFriendlyMarkdown = true; + {% else %} + var codeFriendlyMarkdown = false; + {% endif %} $().ready(function(){ if (askbot['data']['userIsAdminOrMod'] === true){ //todo: this is kind of Attacklab.init ... should not be here - Attacklab.loadEnv = function() - { - var mergeEnv = function(env) - { - if(!env) - { - return; - } - - for(var key in env) - { - Attacklab.wmd_env[key] = env[key]; - } + Attacklab.wmd = function(){ + Attacklab.loadEnv = function(){ + var mergeEnv = function(env){ + if(!env){ + return; + } + + for(var key in env){ + Attacklab.wmd_env[key] = env[key]; + } + }; + + mergeEnv(Attacklab.wmd_defaults); + mergeEnv(Attacklab.account_options); + mergeEnv(top["wmd_options"]); + Attacklab.full = true; + + var defaultButtons = "bold italic link blockquote code image ol ul heading hr"; + Attacklab.wmd_env.buttons = Attacklab.wmd_env.buttons || defaultButtons; }; - - mergeEnv(Attacklab.wmd_defaults); - mergeEnv(Attacklab.account_options); - mergeEnv(top["wmd_options"]); - Attacklab.full = true; - - var defaultButtons = "bold italic link blockquote code image ol ul heading hr"; - Attacklab.wmd_env.buttons = Attacklab.wmd_env.buttons || defaultButtons; + Attacklab.loadEnv(); }; - Attacklab.loadEnv(); + Attacklab.wmd(); Attacklab.wmdBase(); var group_editor = new UserGroupProfileEditor(); group_editor.decorate($('#group-wiki-{{group.id}}')); diff --git a/askbot/urls.py b/askbot/urls.py index 6ebdaf67..fac98b08 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -207,6 +207,11 @@ urlpatterns = patterns('', views.commands.save_group_logo_url, name = 'save_group_logo_url' ), + url(#ajax only + r'^delete-group-logo/', + views.commands.delete_group_logo, + name = 'delete_group_logo' + ), url( r'^get-groups-list/', views.commands.get_groups_list, diff --git a/askbot/views/commands.py b/askbot/views/commands.py index 5d694d6c..9a416609 100644 --- a/askbot/views/commands.py +++ b/askbot/views/commands.py @@ -769,3 +769,20 @@ def save_group_logo_url(request): else: raise ValueError('invalid data found when saving group logo') + +@csrf.csrf_exempt +@decorators.ajax_only +@decorators.post_only +def delete_group_logo(request): + if request.user.is_anonymous(): + raise exceptions.PermissionDenied() + + if not request.user.is_administrator_or_moderator(): + raise exceptions.PermissionDenied( + _('Only moderators and administrators can change user groups') + ) + from django.forms import IntegerField + group_id = IntegerField().clean(int(request.POST['group_id'])) + group = models.Tag.group_tags.get(id = group_id) + group.group_profile.logo_url = None + group.group_profile.save() |