binda 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -2
  3. data/app/assets/javascripts/binda/components/fileupload.js +11 -2
  4. data/app/assets/javascripts/binda/components/form_item.js +25 -45
  5. data/app/assets/javascripts/binda/components/form_item_choice.js +42 -32
  6. data/app/assets/javascripts/binda/components/form_item_repeater.js +29 -32
  7. data/app/assets/javascripts/binda/components/sortable.js +24 -19
  8. data/app/assets/javascripts/binda/dist/binda.bundle.js +133 -138
  9. data/app/assets/stylesheets/binda/components/b-alert.scss +24 -0
  10. data/app/assets/stylesheets/binda/components/form_item.scss +20 -17
  11. data/app/assets/stylesheets/binda/components/form_item_choice.scss +20 -0
  12. data/app/assets/stylesheets/binda/components/main_header.scss +1 -1
  13. data/app/assets/stylesheets/binda/components/main_sidebar.scss +33 -13
  14. data/app/assets/stylesheets/binda/components/main_table.scss +11 -3
  15. data/app/assets/stylesheets/binda/components/select2.scss +27 -18
  16. data/app/assets/stylesheets/binda/components/sortable.scss +1 -1
  17. data/app/assets/stylesheets/binda/components/standard-form.scss +41 -56
  18. data/app/assets/stylesheets/binda/index.scss +2 -0
  19. data/app/assets/stylesheets/binda/settings/common.scss +4 -3
  20. data/app/assets/stylesheets/binda/settings/tiny_mce_overrides.scss +21 -5
  21. data/app/assets/stylesheets/binda/settings/variables.scss +2 -2
  22. data/app/controllers/binda/components_controller.rb +3 -1
  23. data/app/controllers/binda/field_groups_controller.rb +9 -5
  24. data/app/controllers/binda/structures_controller.rb +1 -3
  25. data/app/models/binda/choice.rb +15 -9
  26. data/app/views/binda/categories/_form.html.erb +4 -6
  27. data/app/views/binda/categories/index.html.erb +3 -3
  28. data/app/views/binda/components/index.html.erb +6 -6
  29. data/app/views/binda/components/sort_index.html.erb +6 -6
  30. data/app/views/binda/field_groups/_form_body.html.erb +9 -9
  31. data/app/views/binda/field_groups/_form_item.html.erb +95 -104
  32. data/app/views/binda/field_groups/_form_item_choice.erb +5 -2
  33. data/app/views/binda/field_groups/_form_section.html.erb +5 -3
  34. data/app/views/binda/field_groups/_form_section_repeater.html.erb +6 -3
  35. data/app/views/binda/fieldable/_form_body.html.erb +5 -7
  36. data/app/views/binda/fieldable/_form_item_new_repeater.html.erb +1 -1
  37. data/app/views/binda/fieldable/_form_item_repeater.html.erb +2 -2
  38. data/app/views/binda/fieldable/_form_item_selections.html.erb +1 -1
  39. data/app/views/binda/fieldable/_form_sidebar.html.erb +4 -6
  40. data/app/views/binda/manage/users/_form_body.html.erb +4 -6
  41. data/app/views/binda/manage/users/index.html.erb +3 -3
  42. data/app/views/binda/structures/_form_body.html.erb +3 -5
  43. data/app/views/binda/structures/_form_section.html.erb +49 -25
  44. data/app/views/binda/structures/_form_sidebar.html.erb +1 -1
  45. data/app/views/binda/structures/index.html.erb +4 -4
  46. data/app/views/binda/structures/sort_index.html.erb +6 -6
  47. data/app/views/binda/users/sessions/new.html.erb +1 -1
  48. data/app/views/layouts/binda/_flash.html.erb +14 -16
  49. data/app/views/layouts/binda/_sidebar.html.erb +3 -0
  50. data/config/initializers/simple_form_custom.rb +1 -1
  51. data/config/locales/en.yml +1 -1
  52. data/config/routes.rb +1 -1
  53. data/db/migrate/1_create_binda_tables.rb +1 -0
  54. data/lib/binda.rb +1 -0
  55. data/lib/binda/version.rb +1 -1
  56. data/lib/generators/binda/setup/setup_generator.rb +3 -1
  57. metadata +26 -5
  58. data/db/migrate/20171214140451_add_preview_mode.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b58323a2adb5832314cc30abbce3b2455b5771a2
4
- data.tar.gz: 7662cff5f1a441bc8d8ad6872ffea56836d1c276
3
+ metadata.gz: 5fdbd3a53b7c0c27db1b20d03b562cce049886ef
4
+ data.tar.gz: d8678b7b7ee4a36804234f19f13abbaac7a38974
5
5
  SHA512:
6
- metadata.gz: 4b46646f7c7b91be681708f2373695f04c3b2ffca7390212c1d285d4d8434442505c58610b581367639a2d057edf164fa608091ed70d7fcc9b82d446f3bcead7
7
- data.tar.gz: e005c49678e2d93cf8ed140b0d3635359c3f7a11ae91d9dd7c8b82796081542eb942ea8fc1860d2935900487c6ee6851299851f1961d82d3fa21049a21d10fd6
6
+ metadata.gz: 82c4198e24a5d9cc12aaefbf713c870a7250a46ee7d5b7a8edca6d16617d6d8d6772574fada749b638d61ab6b6158f107e897e358a6f84146b48ccf2da7b94a7
7
+ data.tar.gz: 81a8f0072979bfeb62d247240f4a258bc60f29cf247332b2a7b9334d918b0ec4793774240dc19edbb282a0f9c28992af6727005aba781a577663f9bf9f5d2893
data/README.md CHANGED
@@ -17,7 +17,7 @@ A modular CMS for Ruby on Rails 5.1.
17
17
 
18
18
  # Quick Start
19
19
 
20
- **Binda** is a CMS with an intuitive out-of-the-box interface to manage and customize page components.
20
+ **Binda** is a headless CMS with an intuitive out-of-the-box interface which makes very easy to create your application infrastructure.
21
21
 
22
22
  The core element is the _structure_ element which is the finger print of any _component_ instance. Every _structure_ can have one or more _field-groups_ which can be populated with several _field-settings_. _Field-groups_ and _field-settings_ represent _components_ features, such as galleries, textareas, dates, repeaters and so on.
23
23
 
@@ -30,8 +30,9 @@ Let's say your website needs a set of pages with a subtitle. That's super easy.
30
30
  Done! Now you'll see the "Pages" tab in your menu which will contain all your pages.
31
31
 
32
32
  It's easier learning by doing than by reading. ;-)
33
+ Watch the preview on [Binda's vimeo channel](https://vimeo.com/bindacms/010-preview)
33
34
 
34
- ![Binda preview](https://www.dropbox.com/s/m7vwrou1homqc6p/binda-01.gif?raw=1)
35
+ ![binda-preview-01](https://user-images.githubusercontent.com/1528468/34540454-ea110712-f0d4-11e7-80d5-5464344e1d69.gif)
35
36
 
36
37
  ---
37
38
 
@@ -39,7 +39,6 @@ function handle_file(event)
39
39
  {
40
40
  let id = event.target.getAttribute('data-id')
41
41
  let $parent = $('#fileupload-'+id)
42
- let $preview = $('#fileupload-'+id+' .fileupload--preview')
43
42
 
44
43
  // Get the selected file from the input
45
44
  // This script doesn't consider multiple files upload
@@ -81,7 +80,16 @@ function handle_file(event)
81
80
  // Display loader
82
81
  $('.popup-warning').removeClass('popup-warning--hidden')
83
82
 
84
- // Open the connection
83
+ // Once form data are gathered make the request
84
+ makeRequest(event, formData )
85
+ }
86
+
87
+
88
+ function makeRequest(event, formData )
89
+ {
90
+ let id = event.target.getAttribute('data-id')
91
+ let $parent = $('#fileupload-'+id)
92
+ // Make request
85
93
  $.ajax(
86
94
  {
87
95
  url: event.target.getAttribute('data-url'),
@@ -109,6 +117,7 @@ function handle_file(event)
109
117
  })
110
118
  }
111
119
 
120
+
112
121
  function reset_file(event)
113
122
  {
114
123
  let input = event.target
@@ -29,51 +29,7 @@ class FormItem {
29
29
  $( this ).closest('.form-item').remove()
30
30
  })
31
31
 
32
- $(document).on('click', '.form-item--collapse-btn', function( event )
33
- {
34
- // This function is temporarely just set for repeaters.
35
- // TODO: Need refactoring in order to be available also for generic form items
36
-
37
- // Stop default behaviour
38
- event.preventDefault()
39
-
40
- let $collapsable = $(this).closest('.form-item--collapsable')
41
-
42
- if ( $collapsable.hasClass('form-item--collapsed') )
43
- {
44
- $collapsable.find('.form-item--repeater-fields').each(open)
45
- $collapsable.removeClass('form-item--collapsed')
46
- }
47
- else
48
- {
49
- $collapsable.find('.form-item--repeater-fields').each(close)
50
- $collapsable.addClass('form-item--collapsed')
51
- }
52
- })
53
-
54
- $(document).on('click', '.form-item--toggle-button', function()
55
- {
56
-
57
- let $formItem = $( this ).closest('.form-item')
58
- let $formItemEditor = $formItem.children('.form-item--editor')
59
-
60
- if ( $formItemEditor.get(0).style.maxHeight === '' )
61
- {
62
- // Update height
63
- $formItemEditor.get(0).style.maxHeight = $formItemEditor.get(0).scrollHeight + "px";
64
-
65
- // Add class to trigger animation
66
- $formItem.children('.form-item--toggle-button').removeClass('form-item--toggle-button-closed')
67
- }
68
- else
69
- {
70
- // Zero height
71
- $formItemEditor.get(0).style.maxHeight = null;
72
-
73
- // Add class to trigger animation
74
- $formItem.children('.form-item--toggle-button').addClass('form-item--toggle-button-closed')
75
- }
76
- })
32
+ $(document).on('click', '.form-item--collapse-btn', collapseToggle )
77
33
  }
78
34
  }
79
35
 
@@ -130,4 +86,28 @@ function close()
130
86
  function open()
131
87
  {
132
88
  this.style.maxHeight = this.scrollHeight + "px";
89
+ }
90
+
91
+ function collapseToggle( event )
92
+ {
93
+ // This function is temporarely just set for repeaters.
94
+ // TODO: Need refactoring in order to be available also for generic form items
95
+
96
+ // Stop default behaviour
97
+ event.preventDefault()
98
+
99
+ let $collapsable = $(this).closest('.form-item--collapsable')
100
+
101
+ if ( $collapsable.hasClass('form-item--collapsed') )
102
+ {
103
+ $collapsable.find('.form-item--repeater-fields').each(open)
104
+ $collapsable.find('.form-item--editor').each(open)
105
+ $collapsable.removeClass('form-item--collapsed')
106
+ }
107
+ else
108
+ {
109
+ $collapsable.find('.form-item--repeater-fields').each(close)
110
+ $collapsable.find('.form-item--editor').each(close)
111
+ $collapsable.addClass('form-item--collapsed')
112
+ }
133
113
  }
@@ -20,38 +20,9 @@ class FormItemChoice {
20
20
 
21
21
  setEvents()
22
22
  {
23
- $(document).on('click', '.form-item--add-choice', function( event )
24
- {
25
- event.preventDefault()
26
- // Clone the new choice field
27
- var choices = $( this ).closest('.form-item--choices')
28
- var newchoice = choices.find('.form-item--new-choice')
29
- var clone = newchoice.clone().removeClass('form-item--new-choice').toggle()
30
- clone.find('.form-item--toggle-choice').toggle()
31
- // Append the clone right after
32
- choices.prepend( clone )
33
- // Update form item editor size
34
- _FormItemEditor.resize()
35
- })
23
+ $(document).on('click', '.form-item--add-choice', addChoice )
36
24
 
37
- $(document).on('click', '.form-item--delete-choice', function( event )
38
- {
39
- event.preventDefault()
40
-
41
- var choice = $( this ).closest('.form-item--choice')
42
- var destination = $( this ).attr('href')
43
- var self = this
44
-
45
- $.ajax({
46
- url: destination,
47
- type: 'DELETE',
48
- success: function() {
49
- choice.remove()
50
- // Update form item editor size
51
- _FormItemEditor.resize()
52
- }
53
- })
54
- })
25
+ $(document).on('click', '.form-item--delete-choice', deleteChoice )
55
26
  $(document).on('click', '.form-item--js-delete-choice', function( event )
56
27
  {
57
28
  event.preventDefault()
@@ -62,4 +33,43 @@ class FormItemChoice {
62
33
  }
63
34
  }
64
35
 
65
- export let _FormItemChoice = new FormItemChoice()
36
+ export let _FormItemChoice = new FormItemChoice()
37
+
38
+
39
+ /**
40
+ * HELPER FUNCTIONS
41
+ */
42
+
43
+ function addChoice(event)
44
+ {
45
+ event.preventDefault()
46
+ // Clone the new choice field
47
+ var choices = $( this ).closest('.form-item--choices')
48
+ var newchoice = choices.find('.form-item--new-choice')
49
+ var clone = newchoice.clone().removeClass('form-item--new-choice').toggle()
50
+ clone.find('.form-item--toggle-choice').toggle()
51
+ // Append the clone right after
52
+ choices.prepend( clone )
53
+ // Update form item editor size
54
+ _FormItemEditor.resize()
55
+ }
56
+
57
+
58
+ function deleteChoice( event )
59
+ {
60
+ event.preventDefault()
61
+
62
+ var choice = $( this ).closest('.form-item--choice')
63
+ var destination = $( this ).attr('href')
64
+ var self = this
65
+
66
+ $.ajax({
67
+ url: destination,
68
+ type: 'DELETE',
69
+ success: function() {
70
+ choice.remove()
71
+ // Update form item editor size
72
+ _FormItemEditor.resize()
73
+ }
74
+ })
75
+ }
@@ -17,7 +17,7 @@ class FormItemRepeater {
17
17
 
18
18
  setEvents()
19
19
  {
20
- $(document).on('click', '.form-item--repeater-section--add-new', function(event){ addNewItem(this, event)} )
20
+ $(document).on('click', '.form-item--repeater-section--add-new', addNewItem )
21
21
 
22
22
  $(document).on('click', '.form-item--remove-item-with-js', function( event )
23
23
  {
@@ -27,31 +27,7 @@ class FormItemRepeater {
27
27
  _FormItemEditor.resize()
28
28
  })
29
29
 
30
- $(document).on('click', '.form-item--delete-repeater-item', function( event )
31
- {
32
- // Stop default behaviour
33
- event.preventDefault()
34
-
35
- // if ( !confirm($(this).data('confirm')) ) return
36
-
37
- let record_id = $( this ).data('id')
38
- let target = $('#repeater_' + record_id).get(0)
39
- // As max-height isn't set you need to set it manually before changing it,
40
- // otherwise the animation doesn't get triggered
41
- target.style.maxHeight = target.scrollHeight + 'px'
42
- // Change max-height after 50ms to trigger css animation
43
- setTimeout( function(){ target.style.maxHeight = 0 + 'px' }, 50)
44
-
45
- $.ajax({
46
- url: $( this ).attr('href'),
47
- data: { id: record_id, isAjax: true },
48
- method: "DELETE"
49
- }).done( ()=>{
50
- // Make sure the animation completes before removing the item (it should last 600ms + 50ms)
51
- setTimeout( function(){ $(target).remove() }, 700)
52
- // _FormItemEditor.resize()
53
- })
54
- })
30
+ $(document).on('click', '.form-item--delete-repeater-item', deleteRepeter )
55
31
  }
56
32
  }
57
33
 
@@ -60,19 +36,16 @@ export let _FormItemRepeater = new FormItemRepeater()
60
36
 
61
37
  /**
62
38
  * COMPONENT HELPER FUNCTIONS
63
- *
64
- * @param {string} target The target
65
- * @param {object} event The event
66
39
  */
67
40
 
68
- function addNewItem( target, event )
41
+ function addNewItem( event )
69
42
  {
70
43
  // Stop default behaviour
71
44
  event.preventDefault()
72
45
  // Get the child to clone
73
- let id = $( target ).data( 'id' )
46
+ let id = $( this ).data( 'id' )
74
47
  let $list = $('#form-item--repeater-setting-' + id )
75
- let url = $( target ).data( 'url' )
48
+ let url = $( this ).data( 'url' )
76
49
  $.post( url, { repeater_setting_id: id }, function( data )
77
50
  {
78
51
  // Get repaeter code from Rails
@@ -117,4 +90,28 @@ function addNewItem( target, event )
117
90
  new_repeater_item.style.maxHeight = new_repeater_item.scrollHeight + 'px'
118
91
  }, 50)
119
92
  })
93
+ }
94
+
95
+ function deleteRepeter( event )
96
+ {
97
+ // Stop default behaviour
98
+ event.preventDefault()
99
+
100
+ let record_id = $( this ).data('id')
101
+ let target = $('#repeater_' + record_id).get(0)
102
+ // As max-height isn't set you need to set it manually before changing it,
103
+ // otherwise the animation doesn't get triggered
104
+ target.style.maxHeight = target.scrollHeight + 'px'
105
+ // Change max-height after 50ms to trigger css animation
106
+ setTimeout( function(){ target.style.maxHeight = 0 + 'px' }, 50)
107
+
108
+ $.ajax({
109
+ url: $( this ).attr('href'),
110
+ data: { id: record_id, isAjax: true },
111
+ method: "DELETE"
112
+ }).done( ()=>{
113
+ // Make sure the animation completes before removing the item (it should last 600ms + 50ms)
114
+ setTimeout( function(){ $(target).remove() }, 700)
115
+ // _FormItemEditor.resize()
116
+ })
120
117
  }
@@ -2,30 +2,35 @@
2
2
  * SORTABLE
3
3
  */
4
4
 
5
+
6
+ var sortableOptions = {
7
+ stop: function(event, ui)
8
+ {
9
+ ui.item.css('z-index', 0)
10
+ },
11
+ placeholder: "ui-state-highlight",
12
+ update: function ()
13
+ {
14
+ if ( $('.popup-warning').length > 0 )
15
+ {
16
+ $('.sortable').addClass('sortable--disabled')
17
+ $('.popup-warning').removeClass('popup-warning--hidden')
18
+ $(this).sortable('option','disabled', true)
19
+ }
20
+ let url = $(this).data('update-url')
21
+ let data = $(this).sortable('serialize')
22
+ // If there is a pagination update accordingly
23
+ data = data.concat(`&id=${$(this).attr('id')}`)
24
+ $.post( url, data )
25
+ }
26
+ }
27
+
5
28
  export default function()
6
29
  {
7
30
  if ( $('.sortable').length > 0 )
8
31
  {
9
32
  // Initialize sortable item
10
- $('.sortable')
11
- .sortable({
12
- stop: function(event, ui){
13
- ui.item.css('z-index', 0)
14
- },
15
- placeholder: "ui-state-highlight",
16
- update: function () {
17
- if ( $('.popup-warning').length > 0 ) {
18
- $('.sortable').addClass('sortable--disabled')
19
- $('.popup-warning').removeClass('popup-warning--hidden')
20
- $(this).sortable('option','disabled', true)
21
- }
22
- let url = $(this).data('update-url')
23
- let data = $(this).sortable('serialize')
24
- // If there is a pagination update accordingly
25
- data = data.concat(`&id=${$(this).attr('id')}`)
26
- $.post( url, data )
27
- }
28
- })
33
+ $('.sortable').sortable( sortableOptions )
29
34
 
30
35
  // Check if sortable item needs handles
31
36
  $('.sortable').each( function()
@@ -6,9 +6,9 @@
6
6
  /******/ function __webpack_require__(moduleId) {
7
7
  /******/
8
8
  /******/ // Check if module is in cache
9
- /******/ if(installedModules[moduleId])
9
+ /******/ if(installedModules[moduleId]) {
10
10
  /******/ return installedModules[moduleId].exports;
11
- /******/
11
+ /******/ }
12
12
  /******/ // Create a new module (and put it into the cache)
13
13
  /******/ var module = installedModules[moduleId] = {
14
14
  /******/ i: moduleId,
@@ -137,9 +137,9 @@ var _FormItemEditor = new FormItemEditor();
137
137
  * OPTIONAL (SELECT2 PLUGIN)
138
138
  */
139
139
 
140
- /* harmony default export */ __webpack_exports__["a"] = function () {
140
+ /* harmony default export */ __webpack_exports__["a"] = (function () {
141
141
  setupSelect2('.select2-item');
142
- };
142
+ });
143
143
 
144
144
  function setupSelect2(target) {
145
145
  $(target).each(function () {
@@ -164,10 +164,10 @@ function setupSelect2(target) {
164
164
  * BOOSTRAP SCRIPT
165
165
  */
166
166
 
167
- /* harmony default export */ __webpack_exports__["a"] = function () {
167
+ /* harmony default export */ __webpack_exports__["a"] = (function () {
168
168
  // See https://v4-alpha.getbootstrap.com/components/tooltips/#example-enable-tooltips-everywhere
169
169
  $('[data-toggle="tooltip"]').tooltip();
170
- };
170
+ });
171
171
 
172
172
  /***/ }),
173
173
  /* 3 */
@@ -178,7 +178,7 @@ function setupSelect2(target) {
178
178
  * FIELD GROUP EDITOR
179
179
  */
180
180
 
181
- /* harmony default export */ __webpack_exports__["a"] = function () {
181
+ /* harmony default export */ __webpack_exports__["a"] = (function () {
182
182
  $('.field_groups-edit #save').on('click', function (event) {
183
183
  var instanceType = $(this).data('instance-type');
184
184
  var entriesNumber = $(this).data('entries-number');
@@ -189,7 +189,7 @@ function setupSelect2(target) {
189
189
  alert('You have ' + entriesNumber + ' ' + instanceType + '. This operation might take some time to complete. To avoid unexpected behaviour don\'t leave or refresh the page');
190
190
  }
191
191
  });
192
- };
192
+ });
193
193
 
194
194
  /***/ }),
195
195
  /* 4 */
@@ -248,7 +248,6 @@ var _FileUpload = new FileUpload();
248
248
  function handle_file(event) {
249
249
  var id = event.target.getAttribute('data-id');
250
250
  var $parent = $('#fileupload-' + id);
251
- var $preview = $('#fileupload-' + id + ' .fileupload--preview');
252
251
 
253
252
  // Get the selected file from the input
254
253
  // This script doesn't consider multiple files upload
@@ -288,7 +287,14 @@ function handle_file(event) {
288
287
  // Display loader
289
288
  $('.popup-warning').removeClass('popup-warning--hidden');
290
289
 
291
- // Open the connection
290
+ // Once form data are gathered make the request
291
+ makeRequest(event, formData);
292
+ }
293
+
294
+ function makeRequest(event, formData) {
295
+ var id = event.target.getAttribute('data-id');
296
+ var $parent = $('#fileupload-' + id);
297
+ // Make request
292
298
  $.ajax({
293
299
  url: event.target.getAttribute('data-url'),
294
300
  type: 'PATCH',
@@ -384,9 +390,9 @@ function setup_video_preview(data, id) {
384
390
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
385
391
 
386
392
  "use strict";
393
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FormItem; });
387
394
  /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__form_item_editor__ = __webpack_require__(0);
388
395
  /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__select2__ = __webpack_require__(1);
389
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FormItem; });
390
396
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
391
397
 
392
398
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -426,43 +432,7 @@ var FormItem = function () {
426
432
  $(this).closest('.form-item').remove();
427
433
  });
428
434
 
429
- $(document).on('click', '.form-item--collapse-btn', function (event) {
430
- // This function is temporarely just set for repeaters.
431
- // TODO: Need refactoring in order to be available also for generic form items
432
-
433
- // Stop default behaviour
434
- event.preventDefault();
435
-
436
- var $collapsable = $(this).closest('.form-item--collapsable');
437
-
438
- if ($collapsable.hasClass('form-item--collapsed')) {
439
- $collapsable.find('.form-item--repeater-fields').each(open);
440
- $collapsable.removeClass('form-item--collapsed');
441
- } else {
442
- $collapsable.find('.form-item--repeater-fields').each(close);
443
- $collapsable.addClass('form-item--collapsed');
444
- }
445
- });
446
-
447
- $(document).on('click', '.form-item--toggle-button', function () {
448
-
449
- var $formItem = $(this).closest('.form-item');
450
- var $formItemEditor = $formItem.children('.form-item--editor');
451
-
452
- if ($formItemEditor.get(0).style.maxHeight === '') {
453
- // Update height
454
- $formItemEditor.get(0).style.maxHeight = $formItemEditor.get(0).scrollHeight + "px";
455
-
456
- // Add class to trigger animation
457
- $formItem.children('.form-item--toggle-button').removeClass('form-item--toggle-button-closed');
458
- } else {
459
- // Zero height
460
- $formItemEditor.get(0).style.maxHeight = null;
461
-
462
- // Add class to trigger animation
463
- $formItem.children('.form-item--toggle-button').addClass('form-item--toggle-button-closed');
464
- }
465
- });
435
+ $(document).on('click', '.form-item--collapse-btn', collapseToggle);
466
436
  }
467
437
  }]);
468
438
 
@@ -522,13 +492,33 @@ function open() {
522
492
  this.style.maxHeight = this.scrollHeight + "px";
523
493
  }
524
494
 
495
+ function collapseToggle(event) {
496
+ // This function is temporarely just set for repeaters.
497
+ // TODO: Need refactoring in order to be available also for generic form items
498
+
499
+ // Stop default behaviour
500
+ event.preventDefault();
501
+
502
+ var $collapsable = $(this).closest('.form-item--collapsable');
503
+
504
+ if ($collapsable.hasClass('form-item--collapsed')) {
505
+ $collapsable.find('.form-item--repeater-fields').each(open);
506
+ $collapsable.find('.form-item--editor').each(open);
507
+ $collapsable.removeClass('form-item--collapsed');
508
+ } else {
509
+ $collapsable.find('.form-item--repeater-fields').each(close);
510
+ $collapsable.find('.form-item--editor').each(close);
511
+ $collapsable.addClass('form-item--collapsed');
512
+ }
513
+ }
514
+
525
515
  /***/ }),
526
516
  /* 6 */
527
517
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
528
518
 
529
519
  "use strict";
530
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__form_item_editor__ = __webpack_require__(0);
531
520
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FormItemChoice; });
521
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__form_item_editor__ = __webpack_require__(0);
532
522
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
533
523
 
534
524
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -558,36 +548,9 @@ var FormItemChoice = function () {
558
548
  }, {
559
549
  key: 'setEvents',
560
550
  value: function setEvents() {
561
- $(document).on('click', '.form-item--add-choice', function (event) {
562
- event.preventDefault();
563
- // Clone the new choice field
564
- var choices = $(this).closest('.form-item--choices');
565
- var newchoice = choices.find('.form-item--new-choice');
566
- var clone = newchoice.clone().removeClass('form-item--new-choice').toggle();
567
- clone.find('.form-item--toggle-choice').toggle();
568
- // Append the clone right after
569
- choices.prepend(clone);
570
- // Update form item editor size
571
- __WEBPACK_IMPORTED_MODULE_0__form_item_editor__["a" /* _FormItemEditor */].resize();
572
- });
573
-
574
- $(document).on('click', '.form-item--delete-choice', function (event) {
575
- event.preventDefault();
551
+ $(document).on('click', '.form-item--add-choice', addChoice);
576
552
 
577
- var choice = $(this).closest('.form-item--choice');
578
- var destination = $(this).attr('href');
579
- var self = this;
580
-
581
- $.ajax({
582
- url: destination,
583
- type: 'DELETE',
584
- success: function success() {
585
- choice.remove();
586
- // Update form item editor size
587
- __WEBPACK_IMPORTED_MODULE_0__form_item_editor__["a" /* _FormItemEditor */].resize();
588
- }
589
- });
590
- });
553
+ $(document).on('click', '.form-item--delete-choice', deleteChoice);
591
554
  $(document).on('click', '.form-item--js-delete-choice', function (event) {
592
555
  event.preventDefault();
593
556
  $(this).closest('.form-item--choice').remove();
@@ -602,6 +565,41 @@ var FormItemChoice = function () {
602
565
 
603
566
  var _FormItemChoice = new FormItemChoice();
604
567
 
568
+ /**
569
+ * HELPER FUNCTIONS
570
+ */
571
+
572
+ function addChoice(event) {
573
+ event.preventDefault();
574
+ // Clone the new choice field
575
+ var choices = $(this).closest('.form-item--choices');
576
+ var newchoice = choices.find('.form-item--new-choice');
577
+ var clone = newchoice.clone().removeClass('form-item--new-choice').toggle();
578
+ clone.find('.form-item--toggle-choice').toggle();
579
+ // Append the clone right after
580
+ choices.prepend(clone);
581
+ // Update form item editor size
582
+ __WEBPACK_IMPORTED_MODULE_0__form_item_editor__["a" /* _FormItemEditor */].resize();
583
+ }
584
+
585
+ function deleteChoice(event) {
586
+ event.preventDefault();
587
+
588
+ var choice = $(this).closest('.form-item--choice');
589
+ var destination = $(this).attr('href');
590
+ var self = this;
591
+
592
+ $.ajax({
593
+ url: destination,
594
+ type: 'DELETE',
595
+ success: function success() {
596
+ choice.remove();
597
+ // Update form item editor size
598
+ __WEBPACK_IMPORTED_MODULE_0__form_item_editor__["a" /* _FormItemEditor */].resize();
599
+ }
600
+ });
601
+ }
602
+
605
603
  /***/ }),
606
604
  /* 7 */
607
605
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
@@ -647,9 +645,9 @@ var _FormItemImage = new FormItemImage();
647
645
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
648
646
 
649
647
  "use strict";
648
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FormItemRepeater; });
650
649
  /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__form_item_editor__ = __webpack_require__(0);
651
650
  /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__select2__ = __webpack_require__(1);
652
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FormItemRepeater; });
653
651
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
654
652
 
655
653
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -678,9 +676,7 @@ var FormItemRepeater = function () {
678
676
  }, {
679
677
  key: 'setEvents',
680
678
  value: function setEvents() {
681
- $(document).on('click', '.form-item--repeater-section--add-new', function (event) {
682
- addNewItem(this, event);
683
- });
679
+ $(document).on('click', '.form-item--repeater-section--add-new', addNewItem);
684
680
 
685
681
  $(document).on('click', '.form-item--remove-item-with-js', function (event) {
686
682
  // Stop default behaviour
@@ -689,34 +685,7 @@ var FormItemRepeater = function () {
689
685
  __WEBPACK_IMPORTED_MODULE_0__form_item_editor__["a" /* _FormItemEditor */].resize();
690
686
  });
691
687
 
692
- $(document).on('click', '.form-item--delete-repeater-item', function (event) {
693
- // Stop default behaviour
694
- event.preventDefault();
695
-
696
- // if ( !confirm($(this).data('confirm')) ) return
697
-
698
- var record_id = $(this).data('id');
699
- var target = $('#repeater_' + record_id).get(0);
700
- // As max-height isn't set you need to set it manually before changing it,
701
- // otherwise the animation doesn't get triggered
702
- target.style.maxHeight = target.scrollHeight + 'px';
703
- // Change max-height after 50ms to trigger css animation
704
- setTimeout(function () {
705
- target.style.maxHeight = 0 + 'px';
706
- }, 50);
707
-
708
- $.ajax({
709
- url: $(this).attr('href'),
710
- data: { id: record_id, isAjax: true },
711
- method: "DELETE"
712
- }).done(function () {
713
- // Make sure the animation completes before removing the item (it should last 600ms + 50ms)
714
- setTimeout(function () {
715
- $(target).remove();
716
- }, 700);
717
- // _FormItemEditor.resize()
718
- });
719
- });
688
+ $(document).on('click', '.form-item--delete-repeater-item', deleteRepeter);
720
689
  }
721
690
  }]);
722
691
 
@@ -727,18 +696,15 @@ var _FormItemRepeater = new FormItemRepeater();
727
696
 
728
697
  /**
729
698
  * COMPONENT HELPER FUNCTIONS
730
- *
731
- * @param {string} target The target
732
- * @param {object} event The event
733
699
  */
734
700
 
735
- function addNewItem(target, event) {
701
+ function addNewItem(event) {
736
702
  // Stop default behaviour
737
703
  event.preventDefault();
738
704
  // Get the child to clone
739
- var id = $(target).data('id');
705
+ var id = $(this).data('id');
740
706
  var $list = $('#form-item--repeater-setting-' + id);
741
- var url = $(target).data('url');
707
+ var url = $(this).data('url');
742
708
  $.post(url, { repeater_setting_id: id }, function (data) {
743
709
  // Get repaeter code from Rails
744
710
  // Due to the Rails way of creating nested forms it's necessary to
@@ -781,6 +747,33 @@ function addNewItem(target, event) {
781
747
  });
782
748
  }
783
749
 
750
+ function deleteRepeter(event) {
751
+ // Stop default behaviour
752
+ event.preventDefault();
753
+
754
+ var record_id = $(this).data('id');
755
+ var target = $('#repeater_' + record_id).get(0);
756
+ // As max-height isn't set you need to set it manually before changing it,
757
+ // otherwise the animation doesn't get triggered
758
+ target.style.maxHeight = target.scrollHeight + 'px';
759
+ // Change max-height after 50ms to trigger css animation
760
+ setTimeout(function () {
761
+ target.style.maxHeight = 0 + 'px';
762
+ }, 50);
763
+
764
+ $.ajax({
765
+ url: $(this).attr('href'),
766
+ data: { id: record_id, isAjax: true },
767
+ method: "DELETE"
768
+ }).done(function () {
769
+ // Make sure the animation completes before removing the item (it should last 600ms + 50ms)
770
+ setTimeout(function () {
771
+ $(target).remove();
772
+ }, 700);
773
+ // _FormItemEditor.resize()
774
+ });
775
+ }
776
+
784
777
  /***/ }),
785
778
  /* 9 */
786
779
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
@@ -1130,7 +1123,7 @@ var _LoginForm = new LoginForm();
1130
1123
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1131
1124
 
1132
1125
  "use strict";
1133
- /* harmony default export */ __webpack_exports__["a"] = function () {
1126
+ /* harmony default export */ __webpack_exports__["a"] = (function () {
1134
1127
  $('input[name="login"]').click(function () {
1135
1128
  var $radio = $(this);
1136
1129
 
@@ -1143,7 +1136,7 @@ var _LoginForm = new LoginForm();
1143
1136
  // remove was checked from other radios
1144
1137
  $radio.siblings('input[name="login"]').data('waschecked', false);
1145
1138
  });
1146
- };
1139
+ });
1147
1140
 
1148
1141
  /***/ }),
1149
1142
  /* 12 */
@@ -1154,27 +1147,29 @@ var _LoginForm = new LoginForm();
1154
1147
  * SORTABLE
1155
1148
  */
1156
1149
 
1157
- /* harmony default export */ __webpack_exports__["a"] = function () {
1150
+ var sortableOptions = {
1151
+ stop: function stop(event, ui) {
1152
+ ui.item.css('z-index', 0);
1153
+ },
1154
+ placeholder: "ui-state-highlight",
1155
+ update: function update() {
1156
+ if ($('.popup-warning').length > 0) {
1157
+ $('.sortable').addClass('sortable--disabled');
1158
+ $('.popup-warning').removeClass('popup-warning--hidden');
1159
+ $(this).sortable('option', 'disabled', true);
1160
+ }
1161
+ var url = $(this).data('update-url');
1162
+ var data = $(this).sortable('serialize');
1163
+ // If there is a pagination update accordingly
1164
+ data = data.concat('&id=' + $(this).attr('id'));
1165
+ $.post(url, data);
1166
+ }
1167
+ };
1168
+
1169
+ /* harmony default export */ __webpack_exports__["a"] = (function () {
1158
1170
  if ($('.sortable').length > 0) {
1159
1171
  // Initialize sortable item
1160
- $('.sortable').sortable({
1161
- stop: function stop(event, ui) {
1162
- ui.item.css('z-index', 0);
1163
- },
1164
- placeholder: "ui-state-highlight",
1165
- update: function update() {
1166
- if ($('.popup-warning').length > 0) {
1167
- $('.sortable').addClass('sortable--disabled');
1168
- $('.popup-warning').removeClass('popup-warning--hidden');
1169
- $(this).sortable('option', 'disabled', true);
1170
- }
1171
- var url = $(this).data('update-url');
1172
- var data = $(this).sortable('serialize');
1173
- // If there is a pagination update accordingly
1174
- data = data.concat('&id=' + $(this).attr('id'));
1175
- $.post(url, data);
1176
- }
1177
- });
1172
+ $('.sortable').sortable(sortableOptions);
1178
1173
 
1179
1174
  // Check if sortable item needs handles
1180
1175
  $('.sortable').each(function () {
@@ -1211,7 +1206,7 @@ var _LoginForm = new LoginForm();
1211
1206
  $(id).toggleClass('sortable--enabled');
1212
1207
  $(this).children('.sortable--toggle-text').toggle();
1213
1208
  });
1214
- };
1209
+ });
1215
1210
 
1216
1211
  function setupSortableToggle() {
1217
1212
  $('.sortable--toggle').each(function () {