123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- //CHARGEMENT DE LA PAGE
- var isProcessing = false;
- function init_plugin_export(){
- switch($.urlParam('page')){
- case 'sheet':
- // export_exportmodel_list_dataset();
- export_exportmodel_get_dataset($('#dataset'));
- break;
- default:
- break;
- }
- }
- //Init des settings
- function init_setting_export(parameter){
- switch(parameter.section){
- case 'export':
- break;
- }
- $('#exportmodels').sortable_table({
- onSort : export_exportmodel_search
- });
- }
- //Initialisation du composant d'export modèle
- function init_components_export_model(input){
- var cbLoaded = input.attr('data-callback') ? input.attr('data-callback') : '';
- var cbParams = input.attr('data-params') ? input.attr('data-params').split(',') : [];
- var parameters = JSON.parse(input.attr('data-parameters'));
- $(document).ready(function(e){
- input.on('click', function(e){
- $.ajax({
- type: 'GET',
- url: 'plugin/export/modal.export.model.php',
- async: true,
- success : function(modal){
- if(cbLoaded) window[cbLoaded].apply(null,cbParams);
- }
- }).done(function(modalContent){
- if(!$('#export-modal').length)
- $('body').append(modalContent);
- var modal = $('#export-modal');
- reset_inputs(modal);
- $.action({
- action: 'export_exportmodel_search',
- params: parameters
- }, function(r){
- if(r.rows){
- var selectExport = $('#exportModel');
- selectExport.find('option:not([value="none"])').remove();
- $.each(r.rows,function(i, option){
- selectExport.append('<option value="'+option.id+'">'+option.label+' - '+option.description+'</option>');
- });
- }
- modal.modal('show');
- init_components($('#export-modal'));
- $('#exportmodel-form').attr('data-parameters', JSON.stringify(parameters));
- });
- });
- });
- });
- }
- /* EXPORTMODELE */
- //Récuperation d'une liste de exportmodel dans le tableau #exportmodels
- function export_exportmodel_search(callback){
- $('#exportmodels').fill({
- action:'export_exportmodel_search',
- filters : $('#filters').filters(),
- sort : $('#exportmodels').sortable_table('get')
- }, function(){
- if(callback!=null) callback();
- });
- }
- //Ajout ou modification d'élément exportmodel
- function export_exportmodel_save(){
- var data = $('#exportmodel-form').toJson();
- $.action(data,function(r){
- $('#exportmodel-form').attr('data-id',r.id);
- $('#document_temporary').val('');
- $('#exportmodel-form [data-type="dropzone"] ul > li').attr('data-path', r.relativePath);
- $('#exportmodel-form [data-type="dropzone"] ul > li > a').attr('href', r.filePath);
- $('#exportmodel-form [data-type="dropzone"] ul > li > i.fa-times').attr('onclick', 'export_exportmodel_delete_document(this)');
- $('.options-box').load(document.URL + ' .options-box');
- $.message('success','Export modèle enregistré');
- });
- }
- //Récuperation ou edition d'élément exportmodel
- function export_exportmodel_edit(element){
- var line = $(element).closest('tr');
- $.action({
- action:'export_exportmodel_edit',
- id:line.attr('data-id')
- },function(r){
- $.setForm('#exportmodel-form',r);
- $('#exportmodel-form').attr('data-id',r.id);
- });
- }
- //Suppression d'élement exportmodel
- function export_exportmodel_delete(element){
- if(!confirm('Êtes-vous sûr de vouloir supprimer cet item ?')) return;
- var line = $(element).closest('tr');
- $.action({
- action : 'export_exportmodel_delete',
- id : line.attr('data-id')
- },function(r){
- line.remove();
- $.message('info','Export modèle supprimé');
- });
- }
- //Ajout de document
- function export_exportmodel_add_document(files){
- var form = $('#exportmodel-form');
- var exportmodelId = form.attr('data-id');
- $.action({
- action : 'export_exportmodel_add_document',
- id: exportmodelId,
- files : files,
- plugin: $('#plugin').val()
- }, function(r){
- form.attr('data-id', r.id);
- $.each(r.files, function(i, file){
- var line = $('li[data-path="'+file.oldPath+'"]', form);
- line.attr('data-path', file.relative);
- line.find('a').attr('href', file.url);
- line.find('i.pointer').attr('onclick', 'export_exportmodel_delete_document(this)');
- $('[data-type="dropzone"] input:not(:visible)', form).val('');
-
- $.message('success', 'Fichier "'+file.name+'" sauvegardé');
- });
- $('.options-box').load(document.URL + ' .options-box>*');
- });
- }
- //Suppression de document
- function export_exportmodel_delete_document(element){
- if(!confirm("Êtes-vous sûr de vouloir supprimer ce fichier ?")) return;
- var line = $(element).closest('li');
- $.action({
- action : 'export_exportmodel_delete_document',
- path : line.attr('data-path')
- },function(r){
- $('.options-box').load(document.URL + ' .options-box>*');
- line.remove();
- $.message('info','Élement supprimé');
- });
- }
- //Permet de récupérer les jeux de
- //données associés au plugin choisi
- function export_exportmodel_list_dataset(){
- var parameters = {
- plugin: $('#plugin').val()
- }
- $.action({
- action: 'export_exportmodel_list_dataset',
- params: parameters
- }, function(r){
- var datasetSelect = $('#dataset');
- var tpl = datasetSelect.find('option.hidden').get(0).outerHTML;
- datasetSelect.find('option:not(.template)').remove();
- datasetSelect.val('');
- $.each(r.rows, function(slug, dataset){
- var option = $(Mustache.render(tpl, dataset));
- option.removeClass('hidden template');
- datasetSelect.find('option.hidden').before(option);
- });
- export_exportmodel_get_dataset($('#dataset'));
- });
- }
- //Récupération du jeu de données
- //associé à l'élément exportmodel
- function export_exportmodel_get_dataset(element){
- var container = $('#dataset-container');
- container.addClass('hidden');
- $('#empty-files').show();
- $('li:not(.template)', container).remove();
- var datasetSelect = $(element);
- var curVal = datasetSelect.val();
- var pluginVal = $('#plugin').val();
- if(!curVal || !pluginVal) return;
- var parameters = {
- dataset: curVal,
- plugin: pluginVal
- }
-
- $.action({
- action: 'export_exportmodel_get_dataset',
- params: parameters
- }, function(r){
- container.removeClass('hidden');
- if(r.dataset){
- var showcase = $('.dataset-showcase');
- var tpl = $('li.hidden',showcase).get(0).outerHTML;
- $.each(r.dataset, function(macro, info){
- var datas = {
- macro: (info.type == 'list')?'{{#'+macro+'}}{{/'+macro+'}}':'{{'+macro+'}}',
- description:info.desc,
- type:info.type,
- badge: (info.type == 'list')?'Liste':'Valeur'
- };
- if(info.type == 'photo') datas.badge = 'Photo';
- var li = $(Mustache.render(tpl, datas));
- if(info.subitems) {
- var ul = $('<ul class="subitems"></ul>');
- $.each(info.subitems, function(tag, val){
- var subDatas = {
- macro: '{{'+tag+'}}',
- description: val !== null && typeof val === 'object' ? val.desc : val,
- type: val.type ? val.type : 'value',
- badge: val.type == 'photo' ? 'Photo' : 'Valeur'
- };
- var subLi = $(Mustache.render(tpl, subDatas));
- subLi.removeClass('hidden template');
- ul.append(subLi);
- });
- li.append(ul);
- }
- li.removeClass('hidden template');
- $('> ul', showcase).append(li);
- });
- }
- if(r.files && r.files.length){
- var exampleFiles = $('.dataset-example-files');
- $('#empty-files').hide();
- var aTpl = $('li.hidden',exampleFiles).get(0).outerHTML;
- $.each(r.files, function(i, file){
- var a = $(Mustache.render(aTpl, file));
- a.removeClass('hidden template');
- $('ul', exampleFiles).append(a);
- });
- }
- });
- }
- //Suppression de document
- function export_exportmodel_export(element){
- if(isProcessing) return;
- var exportmodelId = $('#exportModel').val();
- if(exportmodelId=='none') {
- $.message('error', 'Il faut choisir un modèle d\'export');
- return;
- }
- var parameters = $('#exportmodel-form').attr('data-parameters');
- var url = window.location.href;
- var previousUrl = url.substring(url.lastIndexOf('/')+1);
- isProcessing = true;
- // overlay_preloader();
- // toggle_preloader('#send-offer-form', true);
- var exportUrl = 'action.php?action=export_exportmodel_export&exportmodel=';
- window.location = exportUrl+btoa(exportmodelId)+'¶ms='+btoa(parameters)+'&url='+btoa(previousUrl);
- isProcessing = false;
- }
|