|
@@ -1,90 +0,0 @@
|
|
|
-(function ($) {
|
|
|
- $.fn.addCollection = function() {
|
|
|
- function requete(chemin, handleData) {
|
|
|
- $.ajax({
|
|
|
- url: chemin,
|
|
|
- type: 'POST',
|
|
|
- dataType: 'json',
|
|
|
- success: function (reponse) {
|
|
|
- let reponseArray = parseJson(reponse);
|
|
|
- handleData(reponseArray);
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- function parseJson(data) {
|
|
|
- let tableau = [];
|
|
|
- for (let i = 0; i < data.length; i++) {
|
|
|
- let UnObjetJson = data[i];
|
|
|
- let obj = JSON.parse(UnObjetJson);
|
|
|
- sortie = Object.values(obj)
|
|
|
- tableau.push(sortie[0]);
|
|
|
- }
|
|
|
- return tableau;
|
|
|
- }
|
|
|
-
|
|
|
- function addDeleteLink($prototype) {
|
|
|
-
|
|
|
- let $deleteLink = $('<button type="button" class="btn btn-outline-secondary"><i class="fa fa-trash fa-lg text-danger"></i></button>');
|
|
|
-
|
|
|
-
|
|
|
- $prototype.find(":input").after($deleteLink);
|
|
|
-
|
|
|
-
|
|
|
- $deleteLink.on("click", function(e) {
|
|
|
- $prototype.remove();
|
|
|
-
|
|
|
- e.preventDefault();
|
|
|
- return false;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- this.each(function() {
|
|
|
-
|
|
|
- var chemin = $(this).data('path');
|
|
|
-
|
|
|
-
|
|
|
- var $container = $($(this).attr("data-list-selector"));
|
|
|
- $li = $container.find('li');
|
|
|
- $li.each(function() {
|
|
|
- if (chemin !== "") {
|
|
|
- $(this).find(':input').prop("readonly", true);
|
|
|
- }
|
|
|
- addDeleteLink($(this));
|
|
|
- })
|
|
|
-
|
|
|
- $(this).on("click", function(e) {
|
|
|
- e.preventDefault();
|
|
|
- var list = jQuery(jQuery(this).attr('data-list-selector'));
|
|
|
-
|
|
|
- var counter = list.data('widget-counter') | list.children().length;
|
|
|
-
|
|
|
-
|
|
|
- var newWidget = list.attr('data-prototype');
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- newWidget = newWidget.replace(/__name__/g, counter);
|
|
|
-
|
|
|
- counter++;
|
|
|
-
|
|
|
- list.data('widget-counter', counter);
|
|
|
-
|
|
|
- var newElem = jQuery(list.attr('data-widget-tags')).html(newWidget);
|
|
|
-
|
|
|
- if (chemin !== "") {
|
|
|
- requete (chemin, function(output) {
|
|
|
- newElem.find(':input').autocomplete({
|
|
|
- source: output
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- addDeleteLink(newElem);
|
|
|
-
|
|
|
- newElem.appendTo(list);
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
-})(jQuery);
|