(self["webpackChunk"] = self["webpackChunk"] || []).push([["adminlte-field-collection"],{

/***/ "../LaClicBundle/SovBundle/Resources/assets/app/adminlte/field/collection/app.collection.js":
/*!**************************************************************************************************!*\
  !*** ../LaClicBundle/SovBundle/Resources/assets/app/adminlte/field/collection/app.collection.js ***!
  \**************************************************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var core_js_modules_es_array_find_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! core-js/modules/es.array.find.js */ "./node_modules/core-js/modules/es.array.find.js");
/* harmony import */ var core_js_modules_es_array_find_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_find_js__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var core_js_modules_es_regexp_exec_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! core-js/modules/es.regexp.exec.js */ "./node_modules/core-js/modules/es.regexp.exec.js");
/* harmony import */ var core_js_modules_es_regexp_exec_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_regexp_exec_js__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! core-js/modules/es.string.replace.js */ "./node_modules/core-js/modules/es.string.replace.js");
/* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var jquery_ui__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! jquery-ui */ "./node_modules/jquery-ui-dist/jquery-ui.js");
/* harmony import */ var jquery_ui__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(jquery_ui__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _form_scss__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./form.scss */ "../LaClicBundle/SovBundle/Resources/assets/app/adminlte/field/collection/form.scss");





$(document).ready(function () {
  initCollectionWidget();
});

function initCollectionWidget() {
  $('.field-collection[data-prototype]').each(function (i, collectionWidget) {
    setCollectionWidgetSortable($(collectionWidget));
    reindexKeyCollectionWidget($(collectionWidget));
    setCollectionWidgetAdd($(collectionWidget));
    setCollectionWidgetDelete($(collectionWidget));
  });
}

function setCollectionWidgetAdd($collectionWidget) {
  if ($collectionWidget.data('allow-add')) {
    $collectionWidget.find('.field-collection-add').on('click', function (e) {
      // grab the prototype template
      var newWidget = $collectionWidget.attr('data-prototype'); // replace the "__name__" used in the id and name of the prototype
      // with a number that's unique to your emails
      // end name attribute looks like name="contact[emails][2]"

      newWidget = newWidget.replace(/__name__/g, getNumItems($collectionWidget)); // create a new list element and add it to the list

      $collectionWidget.find('.form-widget-compound .field-collection-group').append(newWidget);
      $collectionWidget.find('.field-collection-item:last').find('.field-position').val(getNumItems($collectionWidget));
      reindexKeyCollectionWidget($collectionWidget);
      setCollectionWidgetDelete($collectionWidget);
      $collectionWidget.trigger('collection-add-item');
      $collectionWidget.data('num-items', $collectionWidget.data('num-items') + 1);
      $collectionWidget.find('.collection-empty').hide();
    });
  }
}

function setCollectionWidgetDelete($collectionWidget) {
  if ($collectionWidget.data('allow-delete')) {
    $collectionWidget.find('.field-collection-delete').off('click');
    $collectionWidget.find('.field-collection-delete').on('click', function () {
      $(this).parents('.form-group:first').remove();
      reindexKeyCollectionWidget($collectionWidget);
      if (getNumItems($collectionWidget) == 0) $collectionWidget.find('.collection-empty').show();
    });
  }
}

function getNumItems($collectionWidget) {
  if ($collectionWidget.data('reindex-key')) {
    return $collectionWidget.find('.field-collection-item').length;
  } else {
    return $collectionWidget.data('num-items');
  }
}

function reindexKeyCollectionWidget($collectionWidget) {
  if ($collectionWidget.data('reindex-key')) {
    $collectionWidget.find('.field-collection-item').each(function (i, item) {
      $(item).find('input,textarea').each(function (y, field) {
        var $field = $(field); //Chanegment ID

        var posId = Tools.indexOfLastDigit($field.prop('id'));
        var idPrefix = $field.prop('id').substr(0, posId);
        var idSuffix = $field.prop('id').substr(posId + 1);
        $field.prop('id', idPrefix + i + idSuffix); //Chanegment Name

        var posName = Tools.indexOfLastDigit($field.prop('name'));
        var namePrefix = $field.prop('name').substr(0, posName);
        var nameSuffix = $field.prop('name').substr(posName + 1);
        $field.prop('name', namePrefix + i + nameSuffix);
      });
    });
  }
}

function setCollectionWidgetSortable($collectionWidget) {
  if ($collectionWidget.data('sortable')) {
    $collectionWidget.find('.field-collection-group').sortable({
      "handle": '.lc-btn-sortable',
      cancel: ''
    });
    $collectionWidget.find('.field-collection-group').on("sortupdate", function (event, ui) {
      $collectionWidget.find('.field-collection-group>div').each(function (index, item) {
        $(item).find('.field-position').val(index);
      });
    });
  }
}

/***/ }),

/***/ "../LaClicBundle/SovBundle/Resources/assets/app/adminlte/field/collection/form.scss":
/*!******************************************************************************************!*\
  !*** ../LaClicBundle/SovBundle/Resources/assets/app/adminlte/field/collection/form.scss ***!
  \******************************************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
// extracted by mini-css-extract-plugin


/***/ })

},
/******/ __webpack_require__ => { // webpackRuntimeModules
/******/ "use strict";
/******/ 
/******/ var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
/******/ __webpack_require__.O(0, ["vendors-node_modules_core-js_internals_a-function_js-node_modules_core-js_internals_export_js","vendors-node_modules_core-js_modules_es_array_find_js","vendors-node_modules_core-js_internals_advance-string-index_js-node_modules_core-js_internals-bed4a0","vendors-node_modules_jquery_src_jquery_js","vendors-node_modules_core-js_modules_es_string_replace_js-node_modules_jquery-ui-dist_jquery-ui_js"], () => (__webpack_exec__("../LaClicBundle/SovBundle/Resources/assets/app/adminlte/field/collection/app.collection.js")));
/******/ var __webpack_exports__ = __webpack_require__.O();
/******/ }
]);
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 11196 characters]