main.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //CHARGEMENT DE LA PAGE
  2. var isProcessing = false;
  3. function init_plugin_export(){
  4. switch($.urlParam('page')){
  5. case 'sheet':
  6. // export_exportmodel_list_dataset();
  7. export_exportmodel_get_dataset($('#dataset'));
  8. break;
  9. default:
  10. break;
  11. }
  12. }
  13. //Init des settings
  14. function init_setting_export(parameter){
  15. switch(parameter.section){
  16. case 'export':
  17. break;
  18. }
  19. $('#exportmodels').sortable_table({
  20. onSort : export_exportmodel_search
  21. });
  22. }
  23. /* EXPORTMODELE */
  24. //Récuperation d'une liste de exportmodel dans le tableau #exportmodels
  25. function export_exportmodel_search(callback){
  26. $('#exportmodels').fill({
  27. action:'export_exportmodel_search',
  28. filters : $('#filters').filters(),
  29. sort : $('#exportmodels').sortable_table('get')
  30. }, function(){
  31. if(callback!=null) callback();
  32. });
  33. }
  34. //Ajout ou modification d'élément exportmodel
  35. function export_exportmodel_save(){
  36. var data = $('#exportmodel-form').toJson();
  37. $.action(data,function(r){
  38. $('#exportmodel-form').attr('data-id',r.id);
  39. $('#document_temporary').val('');
  40. $('#exportmodel-form [data-type="dropzone"] ul > li').attr('data-path', r.relativePath);
  41. $('#exportmodel-form [data-type="dropzone"] ul > li > a').attr('href', r.filePath);
  42. $('#exportmodel-form [data-type="dropzone"] ul > li > i.fa-times').attr('onclick', 'export_exportmodel_delete_document(this)');
  43. $('.options-box').load(document.URL + ' .options-box>*');
  44. $.message('success','Export modèle enregistré');
  45. });
  46. }
  47. //Récuperation ou edition d'élément exportmodel
  48. function export_exportmodel_edit(element){
  49. var line = $(element).closest('tr');
  50. $.action({
  51. action:'export_exportmodel_edit',
  52. id:line.attr('data-id')
  53. },function(r){
  54. $.setForm('#exportmodel-form',r);
  55. $('#exportmodel-form').attr('data-id',r.id);
  56. });
  57. }
  58. //Suppression d'élement exportmodel
  59. function export_exportmodel_delete(element){
  60. if(!confirm('Êtes-vous sûr de vouloir supprimer cet item ?')) return;
  61. var line = $(element).closest('tr');
  62. $.action({
  63. action : 'export_exportmodel_delete',
  64. id : line.attr('data-id')
  65. },function(r){
  66. line.remove();
  67. $.message('info','Export modèle supprimé');
  68. });
  69. }
  70. //Ajout de document
  71. function export_exportmodel_add_document(files){
  72. var form = $('#exportmodel-form');
  73. var exportmodelId = form.attr('data-id');
  74. $.action({
  75. action : 'export_exportmodel_add_document',
  76. id: exportmodelId,
  77. files : files,
  78. plugin: $('#plugin').val()
  79. }, function(r){
  80. form.attr('data-id', r.id);
  81. $.each(r.files, function(i, file){
  82. var line = $('li[data-path="'+file.oldPath+'"]', form);
  83. line.attr('data-path', file.relative);
  84. line.find('a').attr('href', file.url);
  85. line.find('i.pointer').attr('onclick', 'export_exportmodel_delete_document(this)');
  86. $('[data-type="dropzone"] input:not(:visible)', form).val('');
  87. $.message('success', 'Fichier "'+file.name+'" sauvegardé');
  88. });
  89. $('.options-box').load(document.URL + ' .options-box>*');
  90. });
  91. }
  92. //Suppression de document
  93. function export_exportmodel_delete_document(element){
  94. if(!confirm("Êtes-vous sûr de vouloir supprimer ce fichier ?")) return;
  95. var line = $(element).closest('li');
  96. $.action({
  97. action : 'export_exportmodel_delete_document',
  98. path : line.attr('data-path')
  99. },function(r){
  100. $('.options-box').load(document.URL + ' .options-box>*');
  101. line.remove();
  102. $.message('info','Élement supprimé');
  103. });
  104. }
  105. //Permet de récupérer les jeux de
  106. //données associés au plugin choisi
  107. function export_exportmodel_list_dataset(){
  108. var parameters = {
  109. plugin: $('#plugin').val()
  110. }
  111. $.action({
  112. action: 'export_exportmodel_list_dataset',
  113. params: parameters
  114. }, function(r){
  115. var datasetSelect = $('#dataset');
  116. var tpl = datasetSelect.find('option.hidden').get(0).outerHTML;
  117. datasetSelect.find('option:not(.template)').remove();
  118. datasetSelect.val('');
  119. $.each(r.rows, function(slug, dataset){
  120. var option = $(Mustache.render(tpl, dataset));
  121. option.removeClass('hidden template');
  122. datasetSelect.find('option.hidden').before(option);
  123. });
  124. export_exportmodel_get_dataset($('#dataset'));
  125. });
  126. }
  127. //Récupération du jeu de données
  128. //associé à l'élément exportmodel
  129. function export_exportmodel_get_dataset(element){
  130. var container = $('#dataset-container');
  131. container.addClass('hidden');
  132. $('#empty-files').removeClass('hidden');
  133. $('li:not(.template)', container).remove();
  134. var datasetSelect = $(element);
  135. var curVal = datasetSelect.val();
  136. var pluginVal = $('#plugin').val();
  137. if(!curVal || !pluginVal) return;
  138. var parameters = {
  139. dataset: curVal,
  140. plugin: pluginVal
  141. }
  142. $.action({
  143. action: 'export_exportmodel_get_dataset',
  144. params: parameters
  145. }, function(r){
  146. container.removeClass('hidden');
  147. if(r.dataset){
  148. var showcase = $('.dataset-showcase');
  149. var tpl = $('li.hidden',showcase).get(0).outerHTML;
  150. $.each(r.dataset, function(macro, info){
  151. var datas = {
  152. macro: (info.type == 'list')?'{{#'+macro+'}}{{/'+macro+'}}':'{{'+macro+'}}',
  153. description:info.desc,
  154. type:info.type,
  155. badge: (info.type == 'list')?'Liste':'Valeur'
  156. };
  157. if(info.type == 'photo') datas.badge = 'Photo';
  158. var li = $(Mustache.render(tpl, datas));
  159. if(info.subitems) {
  160. var ul = $('<ul class="subitems"></ul>');
  161. $.each(info.subitems, function(tag, val){
  162. var subDatas = {
  163. macro: '{{'+tag+'}}',
  164. description: val !== null && typeof val === 'object' ? val.desc : val,
  165. type: val.type ? val.type : 'value',
  166. badge: val.type == 'photo' ? 'Photo' : 'Valeur'
  167. };
  168. var subLi = $(Mustache.render(tpl, subDatas));
  169. subLi.removeClass('hidden template');
  170. ul.append(subLi);
  171. });
  172. li.append(ul);
  173. }
  174. li.removeClass('hidden template');
  175. $('> ul', showcase).append(li);
  176. });
  177. }
  178. if(r.files && r.files.length){
  179. var exampleFiles = $('.dataset-example-files');
  180. $('#empty-files').addClass('hidden');
  181. var aTpl = $('li.hidden',exampleFiles).get(0).outerHTML;
  182. $.each(r.files, function(i, file){
  183. var a = $(Mustache.render(aTpl, file));
  184. a.removeClass('hidden template');
  185. $('ul', exampleFiles).append(a);
  186. });
  187. }
  188. });
  189. }
  190. //Suppression de document
  191. function export_exportmodel_export(element){
  192. if(isProcessing) return;
  193. var exportmodelId = $('#exportModel').val();
  194. var parameters = $('#exportmodel-form').attr('data-parameters');
  195. var url = window.location.href;
  196. var previousUrl = url.substring(url.lastIndexOf('/')+1);
  197. isProcessing = true;
  198. var exportUrl = 'action.php?action=export_exportmodel_export&exportmodel=';
  199. window.location = exportUrl+btoa(exportmodelId)+'&params='+btoa(parameters)+'&url='+btoa(previousUrl);
  200. isProcessing = false;
  201. }