update voting js liveUpdate

This commit is contained in:
Thibault GUILLAUME 2015-09-17 16:54:46 +02:00
parent 9005ac1bbd
commit f367e06de2
5 changed files with 26 additions and 40 deletions

View File

@ -168,7 +168,7 @@ class CmsPsPost extends ObjectModel {
} elseif ($type_relation == 'postcms_product') {
return (bool) Db::getInstance()->delete('cmsps_posts_relation_product', 'id_post = '. $this->id);
} elseif ($type_relation == 'postcms_pack') {
return (bool) Db::getInstance()->delete('cmsps_posts_relation_pack', 'id_post = '. $this->id);
return (bool) Db::getInstance()->delete('cmsps_posts_relation_pack', 'id_post = '. $this->id);
}
}

View File

@ -356,54 +356,39 @@ class AdminCmsPsPostsController extends ModuleAdminController {
switch ($type) {
case 'cms_extrafields_1':
$relations = Tools::getValue('input-posts-cms_extrafields_1', array());
if ($relations) {
if ($this->object->deleteRelations($type, 1)) {
foreach ($relations as $key => $relation) {
$this->object->addRelation($relation, $type, 1);
}
}
$this->object->deleteRelations($type, 1);
foreach ($relations as $key => $relation) {
$this->object->addRelation($relation, $type, 1);
}
break;
case 'cms_extrafields_2':
$relations = Tools::getValue('input-posts-cms_extrafields_2', array());
if ($relations) {
if ($this->object->deleteRelations($type, 2)) {
foreach ($relations as $key => $relation) {
$this->object->addRelation($relation, $type, 2);
}
}
$this->object->deleteRelations($type, 2);
foreach ($relations as $key => $relation) {
$this->object->addRelation($relation, $type, 2);
}
break;
case 'postcms':
$relations = Tools::getValue('input-posts-cms', array());
if ($relations) {
if ($this->object->deleteRelations($type)) {
foreach ($relations as $key => $relation) {
$this->object->addRelation($relation, $type);
}
}
$this->object->deleteRelations($type);
foreach ($relations as $key => $relation) {
$this->object->addRelation($relation, $type);
}
break;
case 'postcms_product':
$relations = Tools::getValue('input-posts-cms-product', array());
if ($relations) {
if ($this->object->deleteRelations($type)) {
foreach ($relations as $key => $relation) {
$this->object->addRelation($relation, $type);
}
}
$this->object->deleteRelations($type);
foreach ($relations as $key => $relation) {
$this->object->addRelation($relation, $type);
}
break;
case 'postcms_pack':
$relations = Tools::getValue('input-posts-cms-pack', array());
if ($relations) {
if ($this->object->deleteRelations($type)) {
foreach ($relations as $key => $relation) {
$this->object->addRelation($relation, $type);
}
}
$this->object->deleteRelations($type);
foreach ($relations as $key => $relation) {
$this->object->addRelation($relation, $type);
}
break;
break;
default:
return FALSE;
break;
@ -435,7 +420,7 @@ class AdminCmsPsPostsController extends ModuleAdminController {
&& !empty($this->object->id) ) {
$dir_dst = _CMS_POST_IMG_DIR_.$this->object->id;
$this->_createDirectoryImage($dir_dst);
$this->createDirectoryImage($dir_dst);
foreach ($_FILES as $key => $file) {
foreach ($this->object->img_size as $key => $img) {
$dest = $dir_dst.'/'.$img['name'].'.jpg';
@ -445,11 +430,10 @@ class AdminCmsPsPostsController extends ModuleAdminController {
}
}
private function _createDirectoryImage($dir_dst) {
private function createDirectoryImage($dir_dst) {
if (!is_dir($dir_dst)) {
mkdir($dir_dst);
}
}
}

View File

@ -3,7 +3,6 @@ $( document ).ready(function() {
var boxes = $(this).parent('.vote_box');
var id_post = $(this).data('id');
var uri = baseUri+'modules/cmsps/ajax_voting.php';
var nb_vote = $(boxes).children('.nb_vote');
$.ajax({
url : uri,
@ -21,7 +20,10 @@ $( document ).ready(function() {
if($(boxes).children('.already_vote').length == 0) {
$(boxes).append('<span class="already_vote">Merci</span>');
}
$(nb_vote).html(json.nb_vote);
$('.nb_vote_'+id_post).each(function(index) {
$(this).html(json.nb_vote);
});
}
}
},
@ -30,4 +32,4 @@ $( document ).ready(function() {
},
});
});
});
});

View File

@ -17,7 +17,7 @@
<div class="col-md-3 col-xs-3 pl0">
<div class="vote_box">
<span class="vote" data-id="{$post->id}"><i class="icon-thumb"></i></span>
<span class="nb_vote">{$post->note}</span>
<span class="nb_vote nb_vote_{$post->id}">{$post->note}</span>
</div>
</div>
</div>

View File

@ -20,7 +20,7 @@
<div class="col-md-3 col-xs-3 pl0">
<div class="vote_box">
<span class="vote" data-id="{$post->id}"><i class="icon-thumb"></i></span>
<span class="nb_vote">{$post->note}</span>
<span class="nb_vote nb_vote_{$post->id}">{$post->note}</span>
</div>
</div>
</div>