233 lines
7.0 KiB
JavaScript
233 lines
7.0 KiB
JavaScript
var x13Import = (function ($, module) {
|
|
|
|
$(function() {
|
|
$(document).on('keyup x-cast', '.x-cast', function() {
|
|
$(this).val(module.castNumber($(this).val()));
|
|
});
|
|
|
|
$(document).on('focusout x-cast', '.x-cast', function() {
|
|
var value = $(this).val();
|
|
|
|
if (!value.length) {
|
|
value = 0;
|
|
}
|
|
|
|
if ($(this).hasClass('x-cast-float')) {
|
|
value = module.castFloat(value);
|
|
} else {
|
|
value = module.castInt(value);
|
|
}
|
|
|
|
if ($(this).hasClass('x-cast-blank') && (value === 0 || value === '0.00')) {
|
|
value = '';
|
|
}
|
|
|
|
$(this).val(value);
|
|
});
|
|
|
|
$('.x-cast').trigger('x-cast');
|
|
});
|
|
|
|
module.getWholesalers = function (callback) {
|
|
var ajaxData = {
|
|
action: 'getWholesalers'
|
|
};
|
|
|
|
x13Import.ajax(
|
|
ajaxData,
|
|
null,
|
|
function(json) {
|
|
json.wholesalers.forEach(function(value) {
|
|
x13Import.progressBlock.wholesaler(value);
|
|
});
|
|
|
|
callback(json.wholesalers);
|
|
},
|
|
function() {
|
|
callback([]);
|
|
}
|
|
);
|
|
}
|
|
|
|
module.disableButton = function(button) {
|
|
button.addClass('disabled').attr('disabled', 'disabled');
|
|
button.find('i').attr('data-class', button.find('i').attr('class')).attr('class', 'process-icon-loading');
|
|
}
|
|
|
|
module.enableButton = function(button) {
|
|
button.removeClass('disabled').removeAttr('disabled');
|
|
button.find('i').attr('class', button.find('i').attr('data-class')).removeAttr('data-class');
|
|
}
|
|
|
|
module.castNumber = function(value) {
|
|
return value.replace(/[^0-9,.\-]/g, '').replace(',', '.');
|
|
}
|
|
|
|
module.castInt = function(value) {
|
|
return parseInt(value);
|
|
}
|
|
|
|
module.castFloat = function(value) {
|
|
value = parseFloat(value).toFixed(10);
|
|
|
|
var pow = Math.pow(10, 2);
|
|
value *= pow;
|
|
|
|
var nextDigit = Math.floor(value * 10) - 10 * Math.floor(value);
|
|
value = (nextDigit >= 5 ? Math.ceil(value) : Math.floor(value));
|
|
|
|
return (value / pow).toFixed(2);
|
|
}
|
|
|
|
module.redirect = function(controller, params) {
|
|
var ajaxData = {
|
|
action: 'getRedirectLink',
|
|
linkController: controller,
|
|
linkParams: params
|
|
};
|
|
|
|
this.ajax(
|
|
ajaxData,
|
|
null,
|
|
function(json) {
|
|
if (json.redirectLink) {
|
|
setTimeout(function() {
|
|
location.replace(json.redirectLink);
|
|
}, 1000);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
module.ajax = function(data, beforeSend, success, error) {
|
|
var defaultData = {
|
|
token: x13importToken,
|
|
ajax: true
|
|
};
|
|
|
|
$.ajax({
|
|
url: currentIndex,
|
|
method: 'POST',
|
|
async: true,
|
|
dataType: 'json',
|
|
data: $.extend(defaultData, data),
|
|
beforeSend: beforeSend,
|
|
success: function(json) {
|
|
if (success) {
|
|
success(json);
|
|
}
|
|
},
|
|
error: error
|
|
});
|
|
}
|
|
|
|
return module;
|
|
|
|
}(jQuery, x13Import || {}));
|
|
|
|
x13Import.progressBlock = (function ($) {
|
|
|
|
var progressBlockElement,
|
|
progressBlockPattern;
|
|
|
|
$(function() {
|
|
progressBlockElement = $('#ximport_progress_block');
|
|
progressBlockPattern = $('#_pattern_ximport_progress_block');
|
|
|
|
progressBlockElement.find('.x-close a').on('click', function (e) {
|
|
e.preventDefault();
|
|
progressBlockElement.slideUp('slow');
|
|
});
|
|
});
|
|
|
|
var progressBlock = {};
|
|
progressBlock.wholesalerActionProcess = 'badge';
|
|
progressBlock.wholesalerActionSuccess = 'badge badge-success';
|
|
progressBlock.wholesalerActionError = 'badge badge-danger';
|
|
|
|
progressBlock.init = function (header, description)
|
|
{
|
|
progressBlockElement.find('.x-header').text(header);
|
|
progressBlockElement.find('.x-description').text((description ? description : ''));
|
|
progressBlockElement.find('.x-bar').hide();
|
|
progressBlockElement.find('.x-bar-visual > div').css('width', 0);
|
|
progressBlockElement.find('.x-form').empty();
|
|
progressBlockElement.find('.x-content').html(progressBlockPattern.find('#_pattern_content').html());
|
|
progressBlockElement.find('.x-close').hide();
|
|
progressBlockElement.slideDown('slow');
|
|
}
|
|
|
|
progressBlock.description = function (description) {
|
|
if (description === undefined) {
|
|
progressBlockElement.find('.x-description').hide();
|
|
} else {
|
|
progressBlockElement.find('.x-description').text(description).show();
|
|
}
|
|
}
|
|
|
|
progressBlock.bar = function (value) {
|
|
if (value === undefined) {
|
|
progressBlockElement.find('.x-bar').hide();
|
|
} else {
|
|
progressBlockElement.find('.x-bar').show();
|
|
progressBlockElement.find('.x-bar-visual > div').css('width', value + '%');
|
|
}
|
|
}
|
|
|
|
progressBlock.messageBefore = function (message) {
|
|
if (message === undefined) {
|
|
progressBlockElement.find('.x-message-before').hide();
|
|
} else {
|
|
progressBlockElement.find('.x-message-before').text(message).show();
|
|
}
|
|
}
|
|
|
|
progressBlock.messageAfter = function (message) {
|
|
if (message === undefined) {
|
|
progressBlockElement.find('.x-message-after').hide();
|
|
} else {
|
|
progressBlockElement.find('.x-message-after').text(message).show();
|
|
}
|
|
}
|
|
|
|
progressBlock.form = function (html) {
|
|
if (html === undefined) {
|
|
progressBlockElement.find('.x-form').hide();
|
|
} else {
|
|
progressBlockElement.find('.x-form').html(html).show();
|
|
}
|
|
}
|
|
|
|
progressBlock.refreshButton = function (message) {
|
|
if (message === undefined) {
|
|
progressBlockElement.find('.x-refresh-button').hide();
|
|
} else {
|
|
progressBlockElement.find('.x-refresh-button').show().find('a').append(' ' + message);
|
|
}
|
|
}
|
|
|
|
progressBlock.wholesaler = function (wholesalerName) {
|
|
var block = progressBlockPattern.find('#_pattern_list_wholesalers > li').clone();
|
|
|
|
$('.x-list-wholesaler', block).text(wholesalerName);
|
|
block.attr('id', 'wholesaler' + wholesalerName);
|
|
block.appendTo(progressBlockElement.find('.x-list'));
|
|
}
|
|
|
|
progressBlock.wholesalerAction = function (wholesalerName, action, message) {
|
|
var wholesalerElement = progressBlockElement.find('.x-list #wholesaler' + wholesalerName).find('.x-list-wholesaler-action');
|
|
wholesalerElement.addClass(action);
|
|
|
|
if (message !== undefined) {
|
|
wholesalerElement.text(message);
|
|
}
|
|
}
|
|
|
|
progressBlock.close = function () {
|
|
progressBlockElement.find('.x-close').show();
|
|
}
|
|
|
|
return progressBlock;
|
|
|
|
}(jQuery));
|