1 $(document).ready(function () {
2 if ($('.website_forum').length){
3 $('.karma_required').on('click', function (ev) {
4 var karma = $(ev.currentTarget).data('karma');
7 var $warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="karma_alert">'+
8 '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
9 karma + ' karma is required to perform this action. You can earn karma by having '+
10 'your answers upvoted by the community.</div>');
11 var vote_alert = $(ev.currentTarget).parent().find("#vote_alert");
12 if (vote_alert.length == 0) {
13 $(ev.currentTarget).parent().append($warning);
18 $('.vote_up,.vote_down').not('.karma_required').on('click', function (ev) {
20 var $link = $(ev.currentTarget);
21 openerp.jsonRpc($link.data('href'), 'call', {})
22 .then(function (data) {
24 if (data['error'] == 'own_post'){
25 var $warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="vote_alert">'+
26 '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
27 'Sorry, you cannot vote for your own posts'+
29 } else if (data['error'] == 'anonymous_user'){
30 var $warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="vote_alert">'+
31 '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
32 'Sorry you must be logged to vote'+
35 vote_alert = $link.parent().find("#vote_alert");
36 if (vote_alert.length == 0) {
37 $link.parent().append($warning);
40 $link.parent().find("#vote_count").html(data['vote_count']);
41 if (data['user_vote'] == 0) {
42 $link.parent().find(".text-success").removeClass("text-success");
43 $link.parent().find(".text-warning").removeClass("text-warning");
45 if (data['user_vote'] == 1) {
46 $link.addClass("text-success");
48 $link.addClass("text-warning");
55 $('.accept_answer').not('.karma_required').on('click', function (ev) {
57 var $link = $(ev.currentTarget);
58 openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
60 if (data['error'] == 'anonymous_user') {
61 var $warning = $('<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
62 '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
63 'Sorry, anonymous users cannot choose correct answer.'+
66 correct_answer_alert = $link.parent().find("#correct_answer_alert");
67 if (correct_answer_alert.length == 0) {
68 $link.parent().append($warning);
72 $link.addClass("oe_answer_true").removeClass('oe_answer_false');
74 $link.removeClass("oe_answer_true").addClass('oe_answer_false');
80 $('.favourite_question').on('click', function (ev) {
82 var $link = $(ev.currentTarget);
83 openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
85 $link.addClass("forum_favourite_question")
87 $link.removeClass("forum_favourite_question")
92 $('.comment_delete').on('click', function (ev) {
94 var $link = $(ev.currentTarget);
95 openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
96 $link.parents('.comment').first().remove();
100 $('.notification_close').on('click', function (ev) {
102 var $link = $(ev.currentTarget);
103 openerp.jsonRpc("/forum/notification_read", 'call', {
104 'notification_id': $link.attr("id")});
107 $('.send_validation_email').on('click', function (ev) {
109 var $link = $(ev.currentTarget);
110 openerp.jsonRpc("/forum/send_validation_email", 'call', {
111 'forum_id': $link.attr('forum-id'),
112 }).then(function (data) {
114 $('button.validation_email_close').click();
119 $('.validated_email_close').on('click', function (ev) {
120 openerp.jsonRpc("/forum/validate_email/close", 'call', {});
123 $('.js_close_intro').on('click', function (ev) {
125 document.cookie = "no_introduction_message = false";
129 $('.link_url').on('change', function (ev) {
131 var $link = $(ev.currentTarget);
132 if ($link.attr("value").search("^http(s?)://.*")) {
133 var $warning = $('<div class="alert alert-danger alert-dismissable" style="position:absolute; margin-top: -180px; margin-left: 90px;">'+
134 '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
135 'Please enter valid URl.'+
137 $link.parent().append($warning);
138 $link.parent().find("button#btn_post_your_article")[0].disabled = true;
139 $link.parent().find("input[name='content']")[0].value = '';
141 openerp.jsonRpc("/forum/get_url_title", 'call', {'url': $link.attr("value")}).then(function (data) {
142 $link.parent().find("input[name='content']")[0].value = data;
143 $('button').prop('disabled', false);
144 $('input').prop('readonly', false);
149 if($('input.load_tags').length){
150 var tags = $("input.load_tags").val();
151 $("input.load_tags").val("");
155 function set_tags(tags) {
156 $("input.load_tags").textext({
157 plugins: 'tags focus autocomplete ajax',
160 onSetSuggestions : function(e, data) {
163 suggestions = self._suggestions = data.result;
164 if(data.showHideDropdown !== false)
165 self.trigger(suggestions === null || suggestions.length === 0 && val.length === 0 ? "hideDropdown" : "showDropdown");
167 renderSuggestions: function(suggestions) {
171 $.each(suggestions || [], function(index, item) {
172 self.addSuggestion(item);
174 var lowerCasesuggestions = $.map(suggestions, function(n,i){return n.toLowerCase();});
175 if(jQuery.inArray(val.toLowerCase(), lowerCasesuggestions) ==-1) {
176 self.addSuggestion("Create '" + val + "'");
181 onEnterKeyPress: function(e) {
184 tag = self.itemManager().stringToItem(val);
186 if(self.isTagAllowed(tag)) {
187 tag = tag.replace(/Create\ '|\'|'/g,'');
188 self.addTags([ tag ]);
189 // refocus the textarea just in case it lost the focus
190 self.core().focusInput();
195 tagsItems: tags.split(","),
196 //Note: The following list of keyboard keys is added. All entries are default except {32 : 'whitespace!'}.
197 keys: {8: 'backspace', 9: 'tab', 13: 'enter!', 27: 'escape!', 37: 'left', 38: 'up!', 39: 'right',
198 40: 'down!', 46: 'delete', 108: 'numpadEnter', 32: 'whitespace'},
200 url: '/forum/get_tags',
206 $("input.load_tags").on('isTagAllowed', function(e, data) {
207 if (_.indexOf($(this).textext()[0].tags()._formData, data.tag) != -1) {
213 if ($('textarea.load_editor').length) {
214 $('textarea.load_editor').each(function () {
216 CKEDITOR.replace(this['id']).on('instanceReady', CKEDITORLoadComplete);
224 function IsKarmaValid(eventNumber,minKarma){
226 if(parseInt($("#karma").val()) >= minKarma){
227 CKEDITOR.tools.callFunction(eventNumber,this);
230 alert("Sorry you need more than " + minKarma + " Karma.");
234 function CKEDITORLoadComplete(){
236 $('.cke_button__link').attr('onclick','IsKarmaValid(33,30)');
237 $('.cke_button__unlink').attr('onclick','IsKarmaValid(37,30)');
238 $('.cke_button__image').attr('onclick','IsKarmaValid(41,30)');