| Current Path : /proc/thread-self/cwd/static/frontend/Magento/luma/it_IT/Webkul_BuyButton/js/ |
| Current File : //proc/thread-self/cwd/static/frontend/Magento/luma/it_IT/Webkul_BuyButton/js/start.js |
define([
'uiComponent',
'uiLayout',
'uiRegistry',
'mage/translate',
'mage/template',
'jquery',
'ko',
'Magento_Ui/js/modal/modal'
], function(
Component,
layout,
registry,
$t,
mageTemplate,
$,
ko,
modal
) {
'use strict';
return Component.extend({
defaults: {
template: "Webkul_BuyButton/start.html",
inputType: false,
productIds: ''
},
/**
* @extends
*/
initialize: function () {
var self = this;
this._super();
},
/**
* initialize observers
*/
initObservable: function () {
this._super().observe('inputType productIds');
return this;
},
initProductButton: function() {
var self = this;
self.inputType(arguments[0].productInputType?arguments[0].productInputType:false);
var options = {
autoOpen: true,
modalClass: 'bb-modal-products',
buttons: [{
text: $t("Create Button"),
class: 'button primary',
click: function() {
let productIds = $("input[name=productIds]").val();
let storeId = $(".front-store").val();
let currency = $(".allowed-currecny").val();
if (productIds) {
window.location.href = ajaxCreateUrl+"?productIds="+productIds+"&store="+storeId+"¤cy="+currency;
}
}
}],
closed: function() {
//$("body").find(".bb-modal-products").remove();
},
clickableOverlay: false,
title: $t("Select Product"),
type: "slide"
};
if ($("body").find(".bb-modal-products").length == 0) {
var gridComponentParams = {
parent: this.name,
name: this.name + '-product-grid',
displayArea: 'products-grid',
component: 'Webkul_BuyButton/js/grid-popup',
provider:this,
config: {
productData: {}
}
};
$.ajax({
url: window.ajaxProductListUrl,
type: 'GET',
dataType: 'json',
showLoader: true,
headers: {
"Content-Type": "application/json"
},
data: {
pageSize: 20,
pageNumber: 1,
filter: '',
sort:'name',
},
success: function(response) {
gridComponentParams.config.productData = response;
layout([gridComponentParams]);
},
error: function() {
console.log("error");
}
});
}
this._isElementLoaded(".bb-grid-popup-container", function() {
let modalHtml = $('.bb-grid-popup-container');
var popup = modal(options, modalHtml);
popup.openModal();
});
},
_isElementLoaded: function ($element, callback) {
var self = this;
setTimeout(function() {
if ($($element).is(':visible')) {
callback();
} else {
self._isElementLoaded($element, callback);
}
}, 50);
},
initCollectionButton: function () {
this.initProductButton({productInputType:true});
}
});
});