[IMP] improved code to do not load tags on every page, added new website_forum.js file.
bzr revid: tpa@tinyerp.com-20140325061901-3r0a2rhq74gnt1yt
This commit is contained in:
parent
d70dc3f425
commit
f6fa645e8f
|
@ -53,6 +53,6 @@
|
|||
height: 1.2em !important;
|
||||
}
|
||||
|
||||
#question_tag{
|
||||
width: 825px !important;
|
||||
.load_tags{
|
||||
width: 845px !important;
|
||||
}
|
|
@ -29,98 +29,3 @@
|
|||
}),
|
||||
});
|
||||
})();
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$('.fa-thumbs-up ,.fa-thumbs-down').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
var value = $link.attr("value")
|
||||
openerp.jsonRpc("/forum/post_vote/", 'call', {
|
||||
'post_id': $link.attr("id"),
|
||||
'vote': value})
|
||||
.then(function (data) {
|
||||
if (data == false){
|
||||
vote_alert = $link.parents().find("#vote_alert");
|
||||
if (vote_alert.length <= 1) {
|
||||
var $warning = $('<div class="alert alert-danger alert-dismissable" id="vote_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
'Sorry, you cannot vote for your own posts'+
|
||||
'</div>');
|
||||
$link.parents().find("#post_vote").append($warning);
|
||||
}
|
||||
} else {
|
||||
$link.parent().find("#vote_count").html(data['vote_count']);
|
||||
if (data == 0) {
|
||||
$link.parent().find(".text-success").removeClass("text-success");
|
||||
$link.parent().find(".text-warning").removeClass("text-warning");
|
||||
} else {
|
||||
if (value == 1) {
|
||||
$link.addClass("text-success");
|
||||
} else {
|
||||
$link.addClass("text-warning");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
$('.delete').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/post_delete/", 'call', {
|
||||
'post_id': $link.attr("id")})
|
||||
.then(function (data) {
|
||||
$link.parents('#answer').remove();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.fa-check').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/correct_answer/", 'call', {
|
||||
'post_id': $link.attr("id")})
|
||||
.then(function (data) {
|
||||
par = $link.parents().find(".oe_answer_true")
|
||||
$link.parents().find(".oe_answer_true").removeClass("oe_answer_true").addClass('oe_answer_false')
|
||||
if (data) {
|
||||
$link.removeClass("oe_answer_false").addClass('oe_answer_true');
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.comment_delete').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/message_delete/", 'call', {
|
||||
'message_id': $link.attr("id")})
|
||||
.then(function (data) {
|
||||
$link.parents('#comment').remove();
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
$('.notification_close').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/notification_read/", 'call', {
|
||||
'notification_id': $link.attr("id")})
|
||||
return true;
|
||||
});
|
||||
|
||||
openerp.jsonRpc('/forum/get_tags/','call' ,{}).then(function(data){
|
||||
var previous_tags = $("#question_tag").val();
|
||||
$("#question_tag").val("");
|
||||
var array_of_tags = previous_tags.split(",");
|
||||
$('#question_tag').textext({
|
||||
plugins : 'tags suggestions autocomplete',
|
||||
tagsItems : array_of_tags,
|
||||
suggestions :data,
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
});
|
|
@ -0,0 +1,95 @@
|
|||
$(document).ready(function () {
|
||||
|
||||
$('.fa-thumbs-up ,.fa-thumbs-down').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
var value = $link.attr("value")
|
||||
openerp.jsonRpc("/forum/post_vote/", 'call', {
|
||||
'post_id': $link.attr("id"),
|
||||
'vote': value})
|
||||
.then(function (data) {
|
||||
if (data == false){
|
||||
vote_alert = $link.parents().find("#vote_alert");
|
||||
if (vote_alert.length <= 1) {
|
||||
var $warning = $('<div class="alert alert-danger alert-dismissable" id="vote_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
'Sorry, you cannot vote for your own posts'+
|
||||
'</div>');
|
||||
$link.parents().find("#post_vote").append($warning);
|
||||
}
|
||||
} else {
|
||||
$link.parent().find("#vote_count").html(data['vote_count']);
|
||||
if (data == 0) {
|
||||
$link.parent().find(".text-success").removeClass("text-success");
|
||||
$link.parent().find(".text-warning").removeClass("text-warning");
|
||||
} else {
|
||||
if (value == 1) {
|
||||
$link.addClass("text-success");
|
||||
} else {
|
||||
$link.addClass("text-warning");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
$('.delete').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/post_delete/", 'call', {
|
||||
'post_id': $link.attr("id")})
|
||||
.then(function (data) {
|
||||
$link.parents('#answer').remove();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.fa-check').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/correct_answer/", 'call', {
|
||||
'post_id': $link.attr("id")})
|
||||
.then(function (data) {
|
||||
par = $link.parents().find(".oe_answer_true")
|
||||
$link.parents().find(".oe_answer_true").removeClass("oe_answer_true").addClass('oe_answer_false')
|
||||
if (data) {
|
||||
$link.removeClass("oe_answer_false").addClass('oe_answer_true');
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.comment_delete').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/message_delete/", 'call', {
|
||||
'message_id': $link.attr("id")})
|
||||
.then(function (data) {
|
||||
$link.parents('#comment').remove();
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
$('.notification_close').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/notification_read/", 'call', {
|
||||
'notification_id': $link.attr("id")})
|
||||
return true;
|
||||
});
|
||||
|
||||
if($('input.load_tags').length){
|
||||
openerp.jsonRpc('/forum/get_tags/','call' ,{}).then(function(data){
|
||||
var previous_tags = $("input.load_tags").val();
|
||||
$("input.load_tags").val("");
|
||||
$("input.load_tags").textext({
|
||||
plugins : 'tags suggestions autocomplete',
|
||||
tagsItems : previous_tags.split(","),
|
||||
suggestions :data,
|
||||
});
|
||||
return true;
|
||||
})
|
||||
};
|
||||
|
||||
});
|
|
@ -6,15 +6,17 @@
|
|||
name="Event Editor">
|
||||
<xpath expr="//script[@id='website_tour_js']" position="after">
|
||||
<script type="text/javascript"
|
||||
src="/website_forum/static/src/js/website.tour.forum.js"></script>
|
||||
|
||||
src="/website_forum/static/src/js/website.tour.forum.js"/>
|
||||
<!--
|
||||
FP Note: Why do we need this ? Can we remove this code?
|
||||
The problem is that you add your script for every page, not only for the forum
|
||||
-->
|
||||
<script type="text/javascript"
|
||||
src="/website_forum/static/src/js/website_forum.editor.js"></script>
|
||||
<script type="text/javascript" src="/web/static/lib/jquery.textext/jquery.textext.js"/>
|
||||
src="/website_forum/static/src/js/website_forum.editor.js"/>
|
||||
<script type="text/javascript"
|
||||
src="/website_forum/static/src/js/website_forum.js"/>
|
||||
<script type="text/javascript"
|
||||
src="/web/static/lib/jquery.textext/jquery.textext.js"/>
|
||||
<script type="text/javascript">
|
||||
CKEDITOR.config.toolbar = [['Bold','Italic','Underline','Strike'],['NumberedList','BulletedList', 'Blockquote']
|
||||
,['Outdent','Indent','Link','Unlink'],] ;
|
||||
|
@ -247,7 +249,7 @@
|
|||
t-attf-value="#{question_content or ''}" id="textarea_ckeditor"/>
|
||||
<br/>
|
||||
<input type="text" name="question_tags" t-attf-value="#{question_tag or ''}"
|
||||
placeholder="Tags" id="question_tag" class="form-control"/>
|
||||
placeholder="Tags" class="form-control load_tags"/>
|
||||
<br/>
|
||||
<button class="btn btn-primary" id="btn_ask_your_question">Post Your Question</button>
|
||||
</form>
|
||||
|
@ -257,6 +259,52 @@
|
|||
</t>
|
||||
</template>
|
||||
|
||||
<template id="edit_question">
|
||||
<t t-call="website_forum.header">
|
||||
<h3>Edit question</h3>
|
||||
<form t-attf-action="/forum/#{ slug(forum) }/question/savequestion/" method="post" role="form">
|
||||
<input type="text" name="question_name" required="True" t-attf-value="#{post.name or ''}"
|
||||
class="form-control" placeholder="Edit your Question"/>
|
||||
<h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5>
|
||||
<textarea name="answer_content" required="True" value="content" class="form-control" id="textarea_ckeditor">
|
||||
<t t-esc="post.content"/>
|
||||
</textarea>
|
||||
<br/>
|
||||
<input type="text" name="question_tag" class="form-control col-md-9 load_tags" placeholder="Tags" t-attf-value="#{tags or ''}"/>
|
||||
<br/>
|
||||
<input name="post_id" t-att-value="post.id" type="hidden"/>
|
||||
<button class="btn btn-primary btn-lg">Save</button>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
CKEDITOR.replace("answer_content");
|
||||
</script>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="close_question">
|
||||
<t t-call="website_forum.header">
|
||||
<h3 class=""><b>Close question</b></h3><br/>
|
||||
<form t-attf-action="/forum/#{ slug(forum) }/question/close/" method="post" role="form">
|
||||
<input name="post_id" t-att-value="post.id" type="hidden"/>
|
||||
<span class="pull-left">Close the question:</span>
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post) }" t-field="post.name"/>
|
||||
<div class="mt16">
|
||||
<label class="col-md-2 control-label mb16" for="reason">Reasons:</label>
|
||||
<div class="col-md-9 mb16">
|
||||
<select class="form-control" name="reason">
|
||||
<t t-foreach="reasons or []" t-as="reason">
|
||||
<option t-att-value="reason.id" t-att-selected="reason.id == post.reason_id.id"><t t-esc="reason.name"/></option>
|
||||
</t>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button class="btn btn-primary btn-lg">Close</button>
|
||||
</div>
|
||||
</form>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="post_answer">
|
||||
<h3 class="mt10">Your answer</h3>
|
||||
<p>
|
||||
|
@ -293,52 +341,6 @@
|
|||
</t>
|
||||
</template>
|
||||
|
||||
<template id="edit_question">
|
||||
<t t-call="website_forum.header">
|
||||
<h3>Edit question</h3>
|
||||
<form t-attf-action="/forum/#{ slug(forum) }/question/savequestion/" method="post" role="form">
|
||||
<input type="text" name="question_name" required="True" t-attf-value="#{post.name or ''}"
|
||||
class="form-control" placeholder="Edit your Question"/>
|
||||
<h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5>
|
||||
<textarea name="answer_content" required="True" value="content" class="form-control" id="textarea_ckeditor">
|
||||
<t t-esc="post.content"/>
|
||||
</textarea>
|
||||
<br/>
|
||||
<input type="text" name="question_tag" id="question_tag" class="form-control" placeholder="Tags" t-attf-value="#{tags or ''}"/>
|
||||
<input name="post_id" t-att-value="post.id" type="hidden"/>
|
||||
<br/>
|
||||
<button class="btn btn-primary btn-lg">Save</button>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
CKEDITOR.replace("answer_content");
|
||||
</script>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="close_question">
|
||||
<t t-call="website_forum.header">
|
||||
<h3 class=""><b>Close question</b></h3><br/>
|
||||
<form t-attf-action="/forum/#{ slug(forum) }/question/close/" method="post" role="form">
|
||||
<input name="post_id" t-att-value="post.id" type="hidden"/>
|
||||
<span class="pull-left">Close the question:</span>
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post) }" t-field="post.name"/>
|
||||
<div class="mt16">
|
||||
<label class="col-md-2 control-label mb16" for="reason">Reasons:</label>
|
||||
<div class="col-md-9 mb16">
|
||||
<select class="form-control" name="reason">
|
||||
<t t-foreach="reasons or []" t-as="reason">
|
||||
<option t-att-value="reason.id" t-att-selected="reason.id == post.reason_id.id"><t t-esc="reason.name"/></option>
|
||||
</t>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button class="btn btn-primary btn-lg">Close</button>
|
||||
</div>
|
||||
</form>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="post_description_full" name="Question Navigation">
|
||||
<t t-call="website_forum.header">
|
||||
|
||||
|
@ -386,7 +388,7 @@
|
|||
t-attf-href="/forum/#{ slug(forum) }/close/question/#{ question.id }">close</a></li>
|
||||
<li><a class="text-muted fa fa-undo" t-if="question.state == 'close'"
|
||||
t-attf-href="/forum/#{ slug(forum) }/reopen/question/#{ question.id }">reopen</a></li>
|
||||
<li><a class="text-muted fa fa-edit"
|
||||
<li><a class="text-muted fa fa-edit"
|
||||
t-attf-href="/forum/#{ slug(forum) }/edit/question/#{ question.id }">edit</a></li>
|
||||
<li><a class="text-muted fa fa-trash-o" t-if="question.active"
|
||||
t-attf-href="/forum/#{ slug(forum) }/delete/question/#{ question.id }">delete</a></li>
|
||||
|
|
Loading…
Reference in New Issue