Skip to content

Commit

Permalink
load
Browse files Browse the repository at this point in the history
  • Loading branch information
andrtechno committed Mar 11, 2021
1 parent f69d4e9 commit fef4d71
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 28 deletions.
99 changes: 77 additions & 22 deletions assets/admin/js/products.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,66 @@
var grid = $('#grid-product');
var pjax = '#pjax-grid-product';
var uiDialog = $('.ui-dialog');

/**
* Update selected comments status
* @param status_id
* @param el object
*/
function setProductsStatus(status_id, el) {

grid_selections = grid.yiiGridView('getSelectedRows');

if (grid_selections.length > 0) {


yii.confirm($(el).data('confirm-info'), function () {
$.ajax({
url: common.url('/admin/shop/product/update-is-active'),
type: 'POST',
dataType: 'json',
data: {
_csrf: yii.getCsrfToken(),
ids: grid_selections,
'switch': status_id
},
success: function (data) {
//if (data.success) {
common.notify(data.message, 'success');
$.pjax.reload(pjax, {timeout: false});
//} else {
// common.notify(data.message, 'error');
// }
},
error: function (XHR, textStatus, errorThrown) {
var err = '';
switch (textStatus) {
case 'timeout':
err = 'The request timed out!';
break;
case 'parsererror':
err = 'Parser error!';
break;
case 'error':
if (XHR.status && !/^\s*$/.test(XHR.status))
err = 'Error ' + XHR.status;
else
err = 'Error';
if (XHR.responseText && !/^\s*$/.test(XHR.responseText))
err = err + ': ' + XHR.responseText;
break;
}
alert(err);
}
});
}, function () {
return false;
});
}else{
common.notify('Объект не выбран.','info');
}

/*
$.ajax(common.url('/admin/shop/product/update-is-active'), {
type: "post",
dataType: "json",
Expand All @@ -33,7 +88,8 @@ function setProductsStatus(status_id, el) {
},
success: function (data) {
common.notify(data.message, 'success');
grid.yiiGridView('applyFilter');
//grid.yiiGridView('applyFilter');
$.pjax.reload(pjax, {timeout: false});
},
error: function (XHR, textStatus, errorThrown) {
var err = '';
Expand All @@ -55,7 +111,7 @@ function setProductsStatus(status_id, el) {
}
alert(err);
}
});
});*/
return false;
}

Expand All @@ -74,6 +130,7 @@ function showCategoryAssignWindow2(el_clicked) {
})

}

/**
* Display window with all categories list.
*
Expand Down Expand Up @@ -194,7 +251,7 @@ function showDuplicateProductsWindow() {
text: 'Копировать',
'class': 'btn btn-primary',
click: function () {
console.log('getSelectedRows',grid.yiiGridView('getSelectedRows'));
console.log('getSelectedRows', grid.yiiGridView('getSelectedRows'));
$.ajax(common.url('/admin/shop/product/duplicate-products'), {
type: "post",
dataType: 'json',
Expand Down Expand Up @@ -333,40 +390,38 @@ function setProductsPrice() {
});*/




$(document).on("click", "#collapse-grid-filter button" , function(event,k) {
$(document).on("click", "#collapse-grid-filter button", function (event, k) {
var data = $("#grid-product").yiiGridView("data");
console.log(data.settings.filterUrl,data.settings.filterSelector);
console.log(data.settings.filterUrl, data.settings.filterSelector);
$.pjax({
//url: data.settings.filterUrl,
url: "/admin/shop/product",
container: '#pjax-grid-product',
type:"GET",
push:false,
timeout:false,
scrollTo:false,
data:$("#collapse-grid-filter input, #collapse-grid-filter select").serialize()
type: "GET",
push: false,
timeout: false,
scrollTo: false,
data: $("#collapse-grid-filter input, #collapse-grid-filter select").serialize()
});
return false;
});

$(document).on("change", "#collapse-grid-filter #productsearch-type_id" , function(event,k) {
$(document).on("change", "#collapse-grid-filter #productsearch-type_id", function (event, k) {

$.getJSON(common.url("/admin/shop/product/load-attributes?type_id="+$(this).val()), function (response) {
if(Object.keys(response).length > 0){
$.getJSON(common.url("/admin/shop/product/load-attributes?type_id=" + $(this).val()), function (response) {
if (Object.keys(response).length > 0) {
$("#filter-grid-attributes").html("");
$.each(response,function(key,items){
$("#filter-grid-attributes").append("<div class=\"col-sm-3\"><div class=\"form-group\"><label for=\""+items.inputId+"\">"+items.label+"</label><select class=\"custom-select\" id=\""+items.inputId+"\" name=\""+items.inputName+"\"></select></div></div>");
$("#"+items.inputId).append($("<option>", {
$.each(response, function (key, items) {
$("#filter-grid-attributes").append("<div class=\"col-sm-3\"><div class=\"form-group\"><label for=\"" + items.inputId + "\">" + items.label + "</label><select class=\"custom-select\" id=\"" + items.inputId + "\" name=\"" + items.inputName + "\"></select></div></div>");
$("#" + items.inputId).append($("<option>", {
value: "",
text : "—"
text: "—"
}));

$.each(items.options,function(i,option){
$("#"+items.inputId).append($("<option>", {
$.each(items.options, function (i, option) {
$("#" + items.inputId).append($("<option>", {
value: option.key,
text : option.value
text: option.value
}));
});
});
Expand Down
12 changes: 6 additions & 6 deletions models/traits/ProductTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function getGridColumns()
'icon' => 'eye',
'linkOptions' => [
'onClick' => 'return setProductsStatus(1, this);',
'data-confirm' => self::t('CONFIRM_SHOW'),
'data-confirm-info' => self::t('CONFIRM_SHOW'),
'data-pjax' => 0
],
],
Expand All @@ -329,7 +329,7 @@ public function getGridColumns()
'icon' => 'eye-close',
'linkOptions' => [
'onClick' => 'return setProductsStatus(0, this);',
'data-confirm' => self::t('CONFIRM_HIDE'),
'data-confirm-info' => self::t('CONFIRM_HIDE'),
'data-pjax' => 0
],
],
Expand All @@ -339,7 +339,7 @@ public function getGridColumns()
'icon' => 'folder-open',
'linkOptions' => [
'onClick' => 'return showCategoryAssignWindow(this);',
'data-confirm' => self::t('CONFIRM_CATEGORY'),
// 'data-confirm' => self::t('CONFIRM_CATEGORY'),
'data-pjax' => 0
],
],
Expand All @@ -349,7 +349,7 @@ public function getGridColumns()
'icon' => 'copy',
'linkOptions' => [
'onClick' => 'return showDuplicateProductsWindow(this);',
'data-confirm' => self::t('CONFIRM_COPY'),
// 'data-confirm' => self::t('CONFIRM_COPY'),
'data-pjax' => 0
],
],
Expand All @@ -359,7 +359,7 @@ public function getGridColumns()
'icon' => 'currencies',
'linkOptions' => [
'onClick' => 'return setProductsPrice(this);',
'data-confirm' => self::t('CONFIRM_PRICE'),
// 'data-confirm' => self::t('CONFIRM_PRICE'),
'data-pjax' => 0
],
],
Expand All @@ -369,7 +369,7 @@ public function getGridColumns()
'icon' => 'refresh',
'linkOptions' => [
'onClick' => 'return updateProductsViews(this);',
'data-confirm' => self::t('CONFIRM_UPDATE_VIEWS'),
// 'data-confirm' => self::t('CONFIRM_UPDATE_VIEWS'),
'data-pjax' => 0
],
]
Expand Down

0 comments on commit fef4d71

Please sign in to comment.