Fix some enhancements & new features
This commit is contained in:
75
build/js/include/core/appender.js
Normal file
75
build/js/include/core/appender.js
Normal file
@@ -0,0 +1,75 @@
|
||||
(function ($) {
|
||||
$.fn.appender = function (settings) {
|
||||
let appendArea = this;
|
||||
let rowHtml = $(settings.rowSection)[0].outerHTML;
|
||||
|
||||
settings.hideSection ? $(settings.rowSection).remove() : "";
|
||||
|
||||
let rowCounter = 1;
|
||||
|
||||
if (settings.rowNumberStart) {
|
||||
rowCounter = Number(settings.rowNumberStart);
|
||||
}
|
||||
|
||||
$(document).on('click', settings.addBtn, function (event) {
|
||||
|
||||
$(appendArea).append(rowHtml);
|
||||
|
||||
if (settings.appendEffect === 'fade') {
|
||||
$(settings.rowSection).last().hide().fadeIn();
|
||||
} else if (settings.appendEffect === 'slide') {
|
||||
$(settings.rowSection).last().hide().slideDown(200);
|
||||
}
|
||||
|
||||
$(settings.rowSection).last().addClass(settings.addClass);
|
||||
|
||||
$(settings.rowNumber).last().text(rowCounter);
|
||||
|
||||
if (settings.type) {
|
||||
type = settings.type;
|
||||
} else {
|
||||
type = settings.rowSection;
|
||||
}
|
||||
|
||||
$(type).each(function(rowIndex) {
|
||||
$(this).find('input[name]').each(function(){
|
||||
var name;
|
||||
name = $(this).attr('name');
|
||||
name = name.replace(/\[[0-9]?\]/g, '['+rowIndex+']');
|
||||
$(this).attr('name',name);
|
||||
});
|
||||
$(this).find('select[name]').each(function(){
|
||||
var name;
|
||||
name = $(this).attr('name');
|
||||
name = name.replace(/\[[0-9]?\]/g, '['+rowIndex+']');
|
||||
$(this).attr('name',name);
|
||||
});
|
||||
$(this).find('textarea[name]').each(function(){
|
||||
var name;
|
||||
name = $(this).attr('name');
|
||||
name = name.replace(/\[[0-9]?\]/g, '['+rowIndex+']');
|
||||
$(this).attr('name',name);
|
||||
});
|
||||
});
|
||||
|
||||
rowCounter++;
|
||||
|
||||
if (settings.callback) {
|
||||
settings.callback();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
if(settings.deleteBtn) {
|
||||
$(document).on('click', settings.deleteBtn, function (e) {
|
||||
$(e.target).closest(settings.rowSection).remove();
|
||||
if (settings.callback) {
|
||||
settings.callback();
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}(jQuery));
|
||||
5
build/js/include/core/cache.js
Normal file
5
build/js/include/core/cache.js
Normal file
@@ -0,0 +1,5 @@
|
||||
function loadCache(file, callback) {
|
||||
file += '?v=' + cache_versions[file];
|
||||
loadScript(file, callback);
|
||||
}
|
||||
|
||||
70
build/js/include/core/handlebars.js
Normal file
70
build/js/include/core/handlebars.js
Normal file
@@ -0,0 +1,70 @@
|
||||
function renderContractDriveTPL(filename, data, selector) {
|
||||
if (typeof(data) == 'undefined') {
|
||||
var data = {};
|
||||
}
|
||||
data.translate = translate;
|
||||
var path = '/assets/apps/ContractDrive/templates/';
|
||||
var content = getTemplate(path + filename, data);
|
||||
if (typeof(selector) == 'undefined')
|
||||
{
|
||||
return content;
|
||||
} else {
|
||||
$(selector).html(content);
|
||||
}
|
||||
}
|
||||
|
||||
function getTemplate(file, data) {
|
||||
var source = getSource(file);
|
||||
var template = Handlebars.compile(source);
|
||||
return template(data);
|
||||
}
|
||||
|
||||
function getSource(file) {
|
||||
var source = null;
|
||||
$.ajax({
|
||||
async: false,
|
||||
dataType: 'html',
|
||||
type: 'GET',
|
||||
url: file + '?' + Date.now(),
|
||||
success: function(data) {
|
||||
source = data;
|
||||
}
|
||||
});
|
||||
return source;
|
||||
}
|
||||
|
||||
function view(template_id, data) {
|
||||
// console.log(template_id);
|
||||
// console.log(data);
|
||||
var source = document.getElementById(template_id).innerHTML;
|
||||
var template = Handlebars.compile(source);
|
||||
return template(data);
|
||||
}
|
||||
|
||||
function helperSelect(name, items, selected, options) {
|
||||
|
||||
// If the selected value is an array, then convert the
|
||||
// select to a multiple select
|
||||
if (selected instanceof Array) {
|
||||
options.hash.multiple = 'multiple';
|
||||
}
|
||||
|
||||
// Generate the list of options
|
||||
var optionsHtml = '';
|
||||
for (var i = 0, j = items.length; i < j; i++) {
|
||||
|
||||
// <option> attributes
|
||||
var attr = {
|
||||
value: items[i].value
|
||||
};
|
||||
|
||||
// We can specify which options are selected by using either:
|
||||
// * an array of selected values or
|
||||
// * a single selected value
|
||||
if ((selected instanceof Array && indexOf(selected, items[i].value) !== -1) || (selected === items[i].value)) {
|
||||
attr.selected = 'selected';
|
||||
}
|
||||
|
||||
optionsHtml += createElement('option', true, attr, items[i].text);
|
||||
}
|
||||
}
|
||||
12
build/js/include/core/lang.js
Normal file
12
build/js/include/core/lang.js
Normal file
@@ -0,0 +1,12 @@
|
||||
function initLangSelector() {
|
||||
$('.language-choice').click(function() {
|
||||
var lang = $(this).data('lang');
|
||||
var url = laroute.route('language', {lang:lang});
|
||||
window.location = url;
|
||||
});
|
||||
}
|
||||
|
||||
function getLang() {
|
||||
return $('#language-btn').attr('data-current-lang');
|
||||
}
|
||||
|
||||
5
build/js/include/core/objectLength.js
Normal file
5
build/js/include/core/objectLength.js
Normal file
@@ -0,0 +1,5 @@
|
||||
function objectLength(list)
|
||||
{
|
||||
return ( typeof(list) == 'Array' ) ? list.length : Object.keys(list).length;
|
||||
}
|
||||
|
||||
6
build/js/include/core/session.js
Normal file
6
build/js/include/core/session.js
Normal file
@@ -0,0 +1,6 @@
|
||||
function initAjaxCheckSession() {
|
||||
$( document ).ajaxError(function( event, jqxhr, settings, thrownError ) {
|
||||
alert("Session expired. You'll be take to the login page");
|
||||
location.href = "/login";
|
||||
});
|
||||
}
|
||||
4
build/js/include/core/url.js
Normal file
4
build/js/include/core/url.js
Normal file
@@ -0,0 +1,4 @@
|
||||
function openURL(url) {
|
||||
window.location = url;
|
||||
}
|
||||
|
||||
29
build/js/include/core/user.js
Normal file
29
build/js/include/core/user.js
Normal file
@@ -0,0 +1,29 @@
|
||||
function getCurrentUser() {
|
||||
var user = $('#current_user').html();
|
||||
return (typeof(user) != 'undefined') ? user : false;
|
||||
}
|
||||
|
||||
function isConnected() {
|
||||
return getCurrentUser() ? true : false;
|
||||
}
|
||||
|
||||
function hasRole(str) {
|
||||
return checkRole('admin') ? true : checkRole(str);
|
||||
}
|
||||
|
||||
function checkRole(str) {
|
||||
return (global.roles.indexOf(str) == -1 ) ? false : true;
|
||||
}
|
||||
|
||||
function isAdmin() {
|
||||
return hasRole('admin');
|
||||
}
|
||||
|
||||
function hasPermission(str) {
|
||||
if (isAdmin()) {
|
||||
return true;
|
||||
} else {
|
||||
return (global.permissions.indexOf(str) == -1 ) ? false : true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user