rename models and associates, isolate botanic with shop

This commit is contained in:
Ludovic CANDELLIER
2020-04-21 00:09:32 +02:00
parent c80b0f1edf
commit 4ad1f18310
234 changed files with 13899 additions and 3230 deletions

View File

@@ -0,0 +1,15 @@
function initAnimate()
{
/*
var wew = new Wew({
target: '.wow',
keyword: 'wow',
});
wew.init();
*/
wow = new WOW({animateClass: 'animated', live: true});
wow.init();
}

77
build/js/include/app.js Normal file
View File

@@ -0,0 +1,77 @@
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
(function($) {
"use strict"; // Start of use strict
// Toggle the side navigation
$("#sidebarToggle, #sidebarToggleTop").on('click', function(e) {
$("body").toggleClass("sidebar-toggled");
$(".sidebar").toggleClass("toggled");
if ($(".sidebar").hasClass("toggled")) {
$('.sidebar .collapse').collapse('hide');
};
});
// Close any open menu accordions when window is resized below 768px
$(window).resize(function() {
if ($(window).width() < 768) {
$('.sidebar .collapse').collapse('hide');
};
});
// Prevent the content wrapper from scrolling when the fixed side navigation hovered over
$('body.fixed-nav .sidebar').on('mousewheel DOMMouseScroll wheel', function(e) {
if ($(window).width() > 768) {
var e0 = e.originalEvent,
delta = e0.wheelDelta || -e0.detail;
this.scrollTop += (delta < 0 ? 1 : -1) * 30;
e.preventDefault();
}
});
// Scroll to top button appear
$(document).on('scroll', function() {
var scrollDistance = $(this).scrollTop();
if (scrollDistance > 100) {
$('.scroll-to-top').fadeIn();
} else {
$('.scroll-to-top').fadeOut();
}
});
// Smooth scrolling using jQuery easing
$(document).on('click', 'a.scroll-to-top', function(e) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: ($($anchor.attr('href')).offset().top)
}, 1000, 'easeInOutExpo');
e.preventDefault();
});
$('#changePassword-submit').click(function(e){
e.preventDefault();
$.ajax({
url: '/changePassword',
data: $('#password-form-data').serialize(),
method : 'POST',
success: function(resp){
if (resp.success) {
$('#changePasswordMessage').html(resp.message);
// await sleep(1000);
$('#changepasswordModal').modal('hide');
$('#password-form-data').each(function(){
this.reset();
});
} else {
$('#changePasswordMessage').html(resp.message);
}
}
});
});
numeral.locale('fr');
})(jQuery); // End of use strict

View 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));

View File

@@ -0,0 +1,5 @@
function loadCache(file, callback) {
file += '?v=' + cache_versions[file];
loadScript(file, callback);
}

View File

@@ -0,0 +1,27 @@
function checkCollapsedFields(selector)
{
var selector = selector + ' input,textarea,select';
var nb_fields = $(selector).length();
var nb_required = $(selector).filter('[required]').length();
var nb_filled = 0;
var nb_necessary = 0;
$(selector).each(function(i, Field){
if ($(Field).val() != '')
{
nb_filled++;
}
});
$(selector).filter('[required]').each(function(i, required){
if ($(required).val() != '')
{
nb_necessary++;
}
});
result = nb_filled + " / " + nb_fields;
result + " | " + nb_necessary + " / " + nb_required;
$(selector + ' .check').html(result);
}

View File

@@ -0,0 +1,14 @@
function initChosen()
{
$(".chosen-select").chosen({ no_results_text: translate.getText.no_result });
$(".chosen-search").append('<i class="glyph-icon icon-search"></i>');
$(".chosen-single div").html('<i class="glyph-icon icon-caret-down"></i>');
$(".chosen-container-single").addClass('styled');
}
function resetChosen()
{
$('.chosen-select').each(function() {
$(this).val("").trigger("chosen:updated");
});
}

View File

@@ -0,0 +1,75 @@
var confirm_delete_options = {
title: "Etes-vous sur ?",
text: "Cet enregistrement sera effacé.",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Oui !",
cancelButtonText: "Annuler"
};
function confirm_delete(id, route,callback) {
console.log(route);
Swal.fire(confirm_delete_options).then(function(result) {
if (result.value) {
$.ajax({
url : route,
method : 'DELETE',
data: {id:id},
success : function(resp){
if (resp.success) {
console.log(resp);
callback();
Swal.fire("Supprimé !", "L'enregistrement a été supprimé.", "success");
} else {
Swal.fire("Erreur!", "L'enregistrement n'a pu être supprimé pour les raisons suivantes : "+resp.message, "danger");
if(resp.code == 401){
location.reload();
}
}
}
});
} else if (result.dismiss === Swal.DismissReason.cancel) {
}
})
}
function confirm(route,options,callback) {
var confirm_options = {
title: options.title,
text: options.text,
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Oui !",
cancelButtonText: "Annuler",
success: options.success ? options.success : "L'enregistrement a été supprimé.",
notsuccess: options.notsuccess ? options.notsuccess : "L'enregistrement n'a pu être supprimé pour les raisons suivantes : "
};
console.log(route);
Swal.fire(confirm_options).then(function(result) {
if (result.value) {
$.ajax({
url : route,
method : 'GET',
success : function(resp){
if (resp.success) {
console.log(resp);
callback();
Swal.fire("Supprimé !", confirm_options.success, "success");
} else {
Swal.fire("Erreur!", confirm_options.notsuccess + resp.message, "danger");
if(resp.code == 401){
location.reload();
}
}
}
});
} else if (result.dismiss === Swal.DismissReason.cancel) {
}
})
}

View File

@@ -0,0 +1,147 @@
function getDatatablesSelector(module) {
return '#' + module + '-table';
}
function getDataTables(options,route,module, nobuttons) {
var params = {
ajax: {
url: route,
data: function ( d ) {
d.where = $('#where').val();
}
},
buttons: (!nobuttons) ? getDatatablesButtons() : [],
responsive: false,
keys: false,
autoWidth: true,
processing: true,
serverSide: true,
lengthChange: true,
lengthMenu: [
[ 10, 25, 50, 100, -1],
[ '10 lignes', '25 lignes', '50 lignes', '100 lignes', 'Tous']
],
deferRender: true,
stateSave: false,
sDom: options['dom'] ? options['dom'] : getDatatablesDomDefault(),
fixedHeader: false,
fixedColumns: options['fixedColumns'],
colReorder: false,
scrollX: true,
scrollY: "70vh",
scrollCollapse: true,
searchDelay: 300,
select: false,
columns: options['columns'],
language: datatables_lang,
rowId: 'id',
};
/* // DOM Position key index //
l - Length changing (dropdown)
f - Filtering input (search)
t - The Table! (datatable)
i - Information (records)
p - Pagination (paging)
r - pRocessing
< and > - div elements
<"#id" and > - div with an id
<"class" and > - div with a class
<"#id.class" and > - div with an id and class
Also see: http://legacy.datatables.net/usage/features
*/
if (options['order']) {
params.order = options['order'];
}
// console.log(params);
var Table = $('#'+module+'-table').DataTable(params);
handleDataTablesFilter(Table,module);
// Table.buttons().container().appendTo( $('.col-sm-6:eq(0)'));
return Table;
}
function handleDataTablesFilter(Table) {
$(Table.table().container()).on('change keyup', 'thead input', function() {
Table.column( $(this).parent().index()+':visible' ).search( this.value ).draw();
});
$(Table.table().container()).on('change', 'thead select', function() {
Table.column( $(this).parent().index()+':visible' ).search( this.value ).draw();
});
$('[data-toggle="popover"]').popover({html: true});
};
function getDatatablesButtons() {
return ['pageLength',
{
extend: 'copyHtml5',
exportOptions: {
columns: ':visible'
},
text: '<i class="fa fa-files-o fa-lg"></i>',
titleAttr: 'Copier',
className: 'hidden-xs',
},
{
extend: 'excelHtml5',
exportOptions: {
columns: ':visible'
},
text: '<i class="fa fa-file-excel-o fa-lg"></i>',
titleAttr: 'Excel',
className: 'hidden-xs',
},
{
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'A4',
exportOptions: {
columns: ':visible'
},
text: '<i class="fa fa-file-pdf-o fa-lg"></i>',
titleAttr: 'PDF',
className: 'hidden-xs',
},
{
extend: 'print',
text: '<i class="fa fa-print fa-lg"></i>',
titleAttr: 'Imprimer',
className: 'hidden-xs',
},
{
extend: 'colvis',
text: '<i class="fa fa-columns fa-lg"></i>',
titleAttr: 'Colonnes',
columns: ':not(.fixed)'
}
];
}
function getDatatablesDomDefault(nobuttons) {
dom = (!nobuttons) ? getDatatablesHeaderDefault() : '';
dom += "t";
dom += getDatatablesFooterDefault();
return dom;
}
function getDatatablesHeaderDefault() {
return "<' row dt-toolbar-header'<'col-md-4 tool'B><'col-md-4'<'toolbar'>><'col-md-4 text-right add'>r>";
}
function getDatatablesFooterDefault() {
return "<'row dt-toolbar-footer'<'col-md-6'i><'col-md-6'p>>";
}
function getDatatableLang() {
return "/assets/plugins/datatables_lang/" + getLang() + '.json';
}

View File

@@ -0,0 +1,67 @@
function initDatepicker() {
var lang = getLang();
loadScript('assets/plugins/datepicker/bootstrap-datepicker.' + lang + '.min.js', function() {
$(".datepicker").datepicker({
language: lang
});
});
}
function initDaterangePicker() {
var lang = getLang();
loadScript('assets/plugins/daterangepicker/' + lang + '.js');
}
function initMomentLang() {
var lang = getLang();
loadScript('assets/plugins/moment/' + lang + '.js');
}
function getDaterangePicker(selector, startDate, parentEl, endDate) {
// console.log('getDaterangePicker');
if (typeof(parentEL) == 'undefined') {
parentEl = 'file_effect_date_selection';
}
if (typeof(startDate) == 'undefined') {
startDate = moment().format(dateRangePickerLanguage.format);
}
// console.log("selector : ", selector);
// console.log("StartDate : ", startDate);
var options = {
autoUpdateInput: false,
autoApply: true,
singleDatePicker: true,
format: dateRangePickerLanguage.format,
opens: 'left',
showDropdowns: true,
showWeekNumbers: true,
alwaysShowCalendars: true,
startDate: startDate,
separator: dateRangePickerLanguage.separator,
locale: dateRangePickerLanguage.locale,
buttonClasses: 'btn btn-light uppercase weight-900',
parentEl: '.' +parentEl
};
if (typeof(endDate) != 'undefined') {
options.endDate = endDate;
options.ranges = dateRangePickerLanguage.ranges;
};
$('#files_selection').parent().parent().parent().parent().parent().parent().parent().parent().parent().removeClass(parentEl).addClass(parentEl);
var picker = $(selector).daterangepicker(options, function(start, end, label) {
//console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
});
$(selector + ' .daterangepicker').removeClass('light').addClass('light');
$(selector).next('span.add-on').off('click').on('click', function() {
$(selector).trigger('click');
});
$(selector).on('apply.daterangepicker', function(ev, picker) {
$(this).val(picker.startDate.format(dateRangePickerLanguage.format));
});
return picker;
}

View File

@@ -0,0 +1,27 @@
function initializeAutocomplete(id) {
var element = document.getElementById(id);
if (element) {
var autocomplete = new google.maps.places.Autocomplete(element, { types: ['geocode'] });
google.maps.event.addListener(autocomplete, 'place_changed', onPlaceChanged);
}
}
function onPlaceChanged() {
var place = this.getPlace();
// console.log(place); // Uncomment this line to view the full object returned by Google API.
for (var i in place.address_components) {
var component = place.address_components[i];
for (var j in component.types) { // Some types are ["country", "political"]
var type_element = document.getElementById(component.types[j]);
if (type_element) {
type_element.value = component.long_name;
}
}
}
}
google.maps.event.addDomListener(window, 'load', function() {
initializeAutocomplete('adresse');
});

View File

@@ -0,0 +1,67 @@
function renderContractDriveTPL(filename, data, selector) {
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);
}
}

167
build/js/include/modal.js Normal file
View File

@@ -0,0 +1,167 @@
var modal_confirm_delete_options = {
title: "Etes-vous sur ?",
text: "Cet enregistrement sera effacé.",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Oui !",
cancelButtonText: "Annuler"
};
function modal_confirm_delete(id,module,route,callback) {
// console.log(id);
var $loader = $('#loader');
Swal.fire(modal_confirm_delete_options).then(function(result) {
if (result.value) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
// console.log('/' + route +'/'+ id);
$.ajax({
url : '/' + route +'/'+ id,
method : 'DELETE',
success : function(resp){
if (resp.success) {
Swal.fire("Supprimé !", "L'enregistrement a été supprimé.", "success");
$('#'+module+'-modal').modal('hide');
callback();
} else {
Swal.fire("Erreur!", "L'enregistrement n'a pu être supprimé pour les raisons suivantes : "+resp.message, "danger");
if(resp.code == 401){
location.reload();
}
}
$loader.hide();
}
});
} else if (result.dismiss === Swal.DismissReason.cancel) {
}
})
}
function modal_save(id,route,module,callback,$button) {
var $loader = $('#loader');
var $data = $('#'+module+'-form-data').serialize();
var $method = $button.attr('data-method');
var $url = ($method == 'POST') ? '/' + route : '/' + route +'/'+ id;
$button.prop('disabled', true);
$button.html('en cours...');
$loader.show();
$.ajax({
url: $url,
data: $data,
method : $method,
success: function(resp){
$button.prop('disabled', false);
$button.html('Enregistrer');
$loader.hide();
if (resp.success) {
$('#'+module+'-form-data').each(function(){
this.reset();
});
$('#btn-'+module+'-delete').hide();
$('#'+module+'-modal').modal('hide');
callback();
} else {
swal(resp.message);
if (resp.code == 401) {
location.reload();
}
}
}
});
}
function modal_add(module, callback) {
/*
$('#'+module+'-form-data').each(function(){
this.reset();
});
*/
$('#btn-'+module+'-save').attr('data-method', 'POST');
$('#btn-'+module+'-delete').hide();
$('#'+module+'-modal').modal('show');
callback();
}
function modal_edit(id,route,module,callback) {
var $loader = $('#loader');
$loader.show();
$('#btn-'+module+'-delete').show();
$.get('/'+route+'/'+id, function(resp){
if (resp.success) {
/*
$('#'+module+'-form-data').each(function(){
this.reset();
});
*/
callback(resp.data);
$('#btn-'+module+'-save').attr('data-method', 'PUT');
$('#btn-'+module+'-delete').show();
$('#'+module+'-modal').modal('show');
} else {
if (resp.code == 401) {
location.reload();
}
}
$loader.hide();
});
}
function initModalAdmin(route,module,callback,populate,Table) {
var selector = getDatatablesSelector(model);
/*
$( selector + ' tbody').on( 'click', 'tr', function (e) {
e.preventDefault();
// $(this).toggleClass('selected');
id = Table.row(this).id();
modal_edit(id,route,module,populate);
} );
*/
/*
$('#btn-'+module+'-add').click(function(e){
e.preventDefault();
modal_add(module, populate);
});
*/
/*
$('#'+module+'-table').on('click', '.btn-'+module+'-edit', function(e){
e.preventDefault();
var id = $(this).attr('data-id');
modal_edit(id,route,module,populate);
});
*/
/*
$('#'+module+'-table').on('click', '.btn-'+module+'-delete', function(e){
e.preventDefault();
var id = $(this).attr('data-id');
modal_confirm_delete(id,route,callback);
});
*/
$('#btn-'+module+'-delete').click(function(e){
e.preventDefault();
var id = $('#id').val();
modal_confirm_delete(id,module,route,callback);
});
/*
$('#btn-'+module+'-save').click(function(e){
e.preventDefault();
var id = $('#id').val();
modal_save(id,route,module,callback,$(this));
});
*/
}

View File

@@ -0,0 +1,37 @@
# Google Place Autocomplete
This sample code show you how to quickly use the Places Autocomplete javascript
API from Google.
[See demo right now](http://lewagon.github.io/google-place-autocomplete)
## Code
Look at the [index.html](index.html) file, you'll see a very standard form.
The input with id `user_input_autocomplete_address` is very important as it
is bound to an `autocomplete` object in the `autocomplete.js` code.
The code you see is not dependent on jQuery, also the `initializeAutocomplete`
method has to be called when `google` is ready, not just when the DOM is ready.
## API Key
In order to get a lot of requests for free to the API, you need to create a
new project under the [Google API Console](https://code.google.com/apis/console).
For this project, enable the Google Maps Javascript API v3:
![](readme-images/enable-api.png)
Then, for this project, create a new "Browser Key", the one you'll put in the
`index.html` file when calling the `https://maps.googleapis.com/maps/api/js` script.
![](readme-images/create-new-browser-key.png)
Make sure to specify referers so that **only you** can use this key! Remember,
you API calls are limited per day.
![](readme-images/key-referers.png)
## Documentation
[Full Reference](https://developers.google.com/maps/documentation/javascript/places-autocomplete)

View File

@@ -0,0 +1,27 @@
function initializeAutocomplete(id) {
var element = document.getElementById(id);
if (element) {
var autocomplete = new google.maps.places.Autocomplete(element, { types: ['geocode'] });
google.maps.event.addListener(autocomplete, 'place_changed', onPlaceChanged);
}
}
function onPlaceChanged() {
var place = this.getPlace();
// console.log(place); // Uncomment this line to view the full object returned by Google API.
for (var i in place.address_components) {
var component = place.address_components[i];
for (var j in component.types) { // Some types are ["country", "political"]
var type_element = document.getElementById(component.types[j]);
if (type_element) {
type_element.value = component.long_name;
}
}
}
}
google.maps.event.addDomListener(window, 'load', function() {
initializeAutocomplete('user_input_autocomplete_address');
});

View File

@@ -0,0 +1,83 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Google Place Autocomplete</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<h1>Google Place Autocomplete exemple</h1>
<a href="https://github.com/lewagon/google-place-autocomplete">Source</a>
<hr>
<form role="form" class="form-horizontal">
<fieldset>
<div class="form-group">
<label class="col-sm-4 control-label">Address</label>
<div class="col-sm-8">
<input id="user_input_autocomplete_address" name="user_input_autocomplete_address"
class="form-control" placeholder="Start typing your address...">
</div>
</div>
</fieldset>
<fieldset class="disabled">
<div class="form-group">
<label class="col-sm-4 control-label"><code>street_number</code></label>
<div class="col-sm-8">
<input id="street_number" name="street_number" disabled="true" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><code>route</code></label>
<div class="col-sm-8">
<input id="route" name="route" disabled="true" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><code>locality</code></label>
<div class="col-sm-8">
<input id="locality" name="locality" disabled="true" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><code>administrative_area_level_1</code></label>
<div class="col-sm-8">
<input id="administrative_area_level_1" name="administrative_area_level_1" disabled="true" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><code>postal_code</code></label>
<div class="col-sm-8">
<input id="postal_code" name="postal_code" disabled="true" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label"><code>country</code></label>
<div class="col-sm-8">
<input id="country" name="country" disabled="true" class="form-control">
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<!-- Include Google Maps JS API -->
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?libraries=places&amp;key=AIzaSyDANjx3bosEtIyzJaoWs50Wnt6nt_1rmxU "></script>
<!-- Custom JS code to bind to Autocomplete API -->
<script type="text/javascript" src="autocomplete.js"></script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@@ -0,0 +1,20 @@
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;
}
}

View File

@@ -0,0 +1,18 @@
function setOptions(selector,data,selected,all) {
// console.log(data);
var $el = $(selector);
$el.empty(); // remove old options
if (all) {
$el.append($("<option></option>").attr("value",'').text('Tous'));
}
$.each(data, function(key, name) {
// console.log(name);
if (key != null) {
if (key == selected) {
$el.append($("<option selected='selected'></option>").attr("value", key).text(name));
} else {
$el.append($("<option></option>").attr("value", key).text(name));
}
}
});
}

View File

@@ -0,0 +1,11 @@
// Javascript to enable link to tab
var url = document.location.toString();
if (url.match('#')) {
$('.nav-tabs a[href="#' + url.split('#')[1] + '"]').tab('show');
}
// Change hash for page-reload
$('.nav-tabs a').on('shown.bs.tab', function (e) {
window.location.hash = e.target.hash;
$(window).scrollTop(0);
})

29
build/js/include/user.js Normal file
View 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;
}
}

View File

@@ -0,0 +1,17 @@
function initValidator()
{
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
}

9140
build/js/theme.js Normal file

File diff suppressed because one or more lines are too long