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 answering questions or 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");
56 $('.accept_answer').not('.karma_required').on('click', function (ev) {
58 var $link = $(ev.currentTarget);
59 openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
61 if (data['error'] == 'anonymous_user') {
62 var $warning = $('<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
63 '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
64 'Sorry, anonymous users cannot choose correct answer.'+
67 correct_answer_alert = $link.parent().find("#correct_answer_alert");
68 if (correct_answer_alert.length == 0) {
69 $link.parent().append($warning);
73 $link.addClass("oe_answer_true").removeClass('oe_answer_false');
75 $link.removeClass("oe_answer_true").addClass('oe_answer_false');
82 $('.favourite_question').on('click', function (ev) {
84 var $link = $(ev.currentTarget);
85 openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
87 $link.addClass("forum_favourite_question")
89 $link.removeClass("forum_favourite_question")
95 $('.comment_delete').on('click', function (ev) {
97 var $link = $(ev.currentTarget);
98 openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
99 $link.parents('.comment').first().remove();
104 $('.notification_close').on('click', function (ev) {
106 var $link = $(ev.currentTarget);
107 openerp.jsonRpc("/forum/notification_read", 'call', {
108 'notification_id': $link.attr("id")})
112 $('.js_close_intro').on('click', function (ev) {
114 document.cookie = "no_introduction_message = false";
118 $('.link_url').on('change', function (ev) {
120 var $link = $(ev.currentTarget);
121 if ($link.attr("value").search("^http(s?)://.*")) {
122 var $warning = $('<div class="alert alert-danger alert-dismissable" style="position:absolute; margin-top: -180px; margin-left: 90px;">'+
123 '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
124 'Please enter valid URl.'+
126 $link.parent().append($warning);
127 $link.parent().find("button#btn_post_your_article")[0].disabled = true;
128 $link.parent().find("input[name='content']")[0].value = '';
130 openerp.jsonRpc("/forum/get_url_title", 'call', {'url': $link.attr("value")}).then(function (data) {
131 $link.parent().find("input[name='content']")[0].value = data;
132 $('button').prop('disabled', false);
133 $('input').prop('readonly', false);
138 if($('input.load_tags').length){
139 var tags = $("input.load_tags").val();
140 $("input.load_tags").val("");
144 function set_tags(tags) {
145 $("input.load_tags").textext({
146 plugins: 'tags focus autocomplete ajax',
149 onSetSuggestions : function(e, data) {
152 suggestions = self._suggestions = data.result;
153 if(data.showHideDropdown !== false)
154 self.trigger(suggestions === null || suggestions.length === 0 && val.length === 0 ? "hideDropdown" : "showDropdown");
156 renderSuggestions: function(suggestions) {
160 $.each(suggestions || [], function(index, item) {
161 self.addSuggestion(item);
163 var lowerCasesuggestions = $.map(suggestions, function(n,i){return n.toLowerCase();});
164 if(jQuery.inArray(val.toLowerCase(), lowerCasesuggestions) ==-1) {
165 self.addSuggestion("Create '" + val + "'");
170 onEnterKeyPress: function(e) {
173 tag = self.itemManager().stringToItem(val);
175 if(self.isTagAllowed(tag)) {
176 tag = tag.replace(/Create\ '|\'|'/g,'');
177 self.addTags([ tag ]);
178 // refocus the textarea just in case it lost the focus
179 self.core().focusInput();
184 tagsItems: tags.split(","),
185 //Note: The following list of keyboard keys is added. All entries are default except {32 : 'whitespace!'}.
186 keys: {8: 'backspace', 9: 'tab', 13: 'enter!', 27: 'escape!', 37: 'left', 38: 'up!', 39: 'right',
187 40: 'down!', 46: 'delete', 108: 'numpadEnter', 32: 'whitespace'},
189 url: '/forum/get_tags',
195 $("input.load_tags").on('isTagAllowed', function(e, data) {
196 if (_.indexOf($(this).textext()[0].tags()._formData, data.tag) != -1) {
202 if ($('textarea.load_editor').length) {
203 $('textarea.load_editor').each(function () {
205 CKEDITOR.replace(this['id']).on('instanceReady', CKEDITORLoadComplete);
213 function IsKarmaValid(eventNumber,minKarma){
215 if(parseInt($("#karma").val()) >= minKarma){
216 CKEDITOR.tools.callFunction(eventNumber,this);
219 alert("Sorry you need more than " + minKarma + " Karma.");
223 function CKEDITORLoadComplete(){
225 $('.cke_button__link').attr('onclick','IsKarmaValid(33,30)');
226 $('.cke_button__unlink').attr('onclick','IsKarmaValid(37,30)');
227 $('.cke_button__image').attr('onclick','IsKarmaValid(41,30)');