Module AdminComment (pour rajout de notes sur les produits, non visibles des clients)
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<script type="text/javascript">
|
||||
var adminCommentConfig = {
|
||||
'key': '{$key}',
|
||||
'id': {$id},
|
||||
'urlList': "{url path="/admin/module/AdminComment/list/$key/$id"}"
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,94 @@
|
||||
<div id="admin-comment-wrapper" class="container hidden">
|
||||
<div class="row">
|
||||
<div class="col-md-12 general-block-decorator">
|
||||
<div>
|
||||
<div class="title">
|
||||
{intl l="Admin Comments" d="admincomment.bo.default"}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
{form name="admin_comment_create_form"}
|
||||
<form id="admin-comment-form" method="post" action="{url path="/admin/module/AdminComment/create"}" {form_enctype form=$form}>
|
||||
|
||||
{form_hidden_fields form=$form}
|
||||
|
||||
{form_field form=$form field="admin_id"}
|
||||
<input type="hidden" name="{$name}" value="{admin attr="id"}">
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form field="element_key"}
|
||||
<input type="hidden" id="admin-comment-form-key" name="{$name}" value="">
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form field="element_id"}
|
||||
<input type="hidden" id="admin-comment-form-id" name="{$name}" value="">
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form field="comment"}
|
||||
<div class="form-group">
|
||||
<textarea id="admin-comment-form-comment" name="{$name}" class="form-control">{$value}</textarea>
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary">{intl l="Save" d="admincomment.bo.default"}</button>
|
||||
</div>
|
||||
</form>
|
||||
{/form}
|
||||
|
||||
<div id="admin-comment-list" class="list-group">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{* JS Templates *}
|
||||
<script id="tpl-admin-comment" type="text/html">
|
||||
<div class="list-group-item" data-id="<%= comment.id %>">
|
||||
<h4 class="list-group-item-heading u-no-padding"><%= comment.admin %> (<%= comment.date %>)</h4>
|
||||
<p class="list-group-item-text u-padding-bottom">
|
||||
<%= comment.comment %>
|
||||
</p>
|
||||
<% if (comment.canChange) { %>
|
||||
<div class="list-group-item-form hidden">
|
||||
{form name="admin_comment_update_form"}
|
||||
<form class="admin-comment-form" method="post" action="{url path="/admin/module/AdminComment/save"}" {form_enctype form=$form}>
|
||||
|
||||
{form_hidden_fields form=$form}
|
||||
|
||||
{form_field form=$form field="id"}
|
||||
<input type="hidden" name="{$name}" value="<%= comment.id %>">
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form field="comment"}
|
||||
<div class="form-group">
|
||||
<textarea name="{$name}" class="form-control"><%= comment.comment %></textarea>
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary">{intl l="Save" d="admincomment.bo.default"}</button>
|
||||
</div>
|
||||
</form>
|
||||
{/form}
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<a class="btn btn-default btn-xs js-admincomment-edit" title="{intl d='admincomment.bo.default' l='Edit this comment'}">
|
||||
<span class="glyphicon glyphicon-pencil"></span>
|
||||
</a>
|
||||
<a class="btn btn-default btn-xs js-admincomment-delete" data-id="<%= comment.id %>" data-action="{url path="/admin/module/AdminComment/delete"}" title="{intl d='admincomment.bo.default' l='Delete this comment'}" >
|
||||
<span class="glyphicon glyphicon-trash"></span>
|
||||
</a>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
{include
|
||||
file = "includes/generic-warning-dialog.html"
|
||||
|
||||
dialog_id = "admin_comment_dialog"
|
||||
dialog_title = {intl d='admincomment.bo.default' l="Message"}
|
||||
dialog_body = ""
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
if (typeof window._ == 'undefined') {
|
||||
{javascripts file='assets/js/libs/underscore-min.js'}
|
||||
console.log("underscore");
|
||||
document.write(unescape("%3Cscript src='{$asset_url}' %3E%3C/script%3E"));
|
||||
{/javascripts}
|
||||
}
|
||||
|
||||
{literal}
|
||||
(function ($, undefined) {
|
||||
$(document).ready(function () {
|
||||
if (window.adminCommentConfig === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $container = $('#admin-comment-wrapper'),
|
||||
$list = $('#admin-comment-list'),
|
||||
$form = $('#admin-comment-form'),
|
||||
$inputComment = $('#admin-comment-form-comment'),
|
||||
$inputKey = $('#admin-comment-form-key'),
|
||||
$inputId = $('#admin-comment-form-id'),
|
||||
tplComment = _.template($("#tpl-admin-comment").html())
|
||||
;
|
||||
|
||||
$container.removeClass("hidden");
|
||||
$inputKey.val(window.adminCommentConfig.key);
|
||||
$inputId.val(window.adminCommentConfig.id);
|
||||
|
||||
var showMessage = function showMessage(message) {
|
||||
$('#admin_comment_dialog')
|
||||
.find('.modal-body')
|
||||
.html(message)
|
||||
.end()
|
||||
.modal("show");
|
||||
};
|
||||
|
||||
var listComment = function listComment() {
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: 'json',
|
||||
url: window.adminCommentConfig.urlList
|
||||
}).done(function(data, textStatus, jqXHR){
|
||||
var html = '';
|
||||
if (data.success) {
|
||||
$list.html("");
|
||||
for (var i = 0 ; i < data.data.length ; i++) {
|
||||
html += tplComment({comment: data.data[i]});
|
||||
}
|
||||
$list.html(html);
|
||||
} else {
|
||||
showMessage(data.message);
|
||||
}
|
||||
}).fail(function(jqXHR, textStatus, errorThrown){
|
||||
showMessage(textStatus);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
$form.on('submit', function (ev) {
|
||||
|
||||
ev.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
data: $(this).serialize(),
|
||||
url: $(this).attr('action')
|
||||
}).done(function(data, textStatus, jqXHR){
|
||||
if (data.success) {
|
||||
$list.prepend(tplComment({comment: data.data}));
|
||||
$inputComment.val("");
|
||||
} else {
|
||||
showMessage(data.message);
|
||||
}
|
||||
}).fail(function(jqXHR, textStatus, errorThrown){
|
||||
showMessage(textStatus);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$list.on('click', '.js-admincomment-delete', function(ev){
|
||||
|
||||
var $deleteButton = $(this);
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
data: {id: $deleteButton.data('id')},
|
||||
url: $deleteButton.data("action")
|
||||
}).done(function(data, textStatus, jqXHR){
|
||||
if (data.success) {
|
||||
$deleteButton.parents('.list-group-item').remove();
|
||||
} else {
|
||||
showMessage(data.message);
|
||||
}
|
||||
}).fail(function(jqXHR, textStatus, errorThrown){
|
||||
showMessage(textStatus);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$list.on('click', '.js-admincomment-edit', function(ev){
|
||||
var $listItem = $(this).parents('.list-group-item');
|
||||
$listItem.find('.list-group-item-text').addClass('hidden');
|
||||
$listItem.find('.list-group-item-form').removeClass('hidden');
|
||||
});
|
||||
|
||||
$list.on('submit', '.admin-comment-form', function (ev) {
|
||||
|
||||
ev.preventDefault();
|
||||
|
||||
var $editForm = $(this),
|
||||
$listItem = $editForm.parents(".list-group-item").first();
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
data: $editForm.serialize(),
|
||||
url: $editForm.attr('action')
|
||||
}).done(function(data, textStatus, jqXHR){
|
||||
if (data.success) {
|
||||
$listItem.find('.list-group-item-text').html(data.data.comment).removeClass('hidden');
|
||||
$listItem.find('.list-group-item-form').addClass('hidden');
|
||||
} else {
|
||||
showMessage(data.message);
|
||||
}
|
||||
}).fail(function(jqXHR, textStatus, errorThrown){
|
||||
showMessage(textStatus);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
listComment();
|
||||
|
||||
});
|
||||
})(jQuery);
|
||||
{/literal}
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user