inline_editor 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 613a54ae2b2094b2b3f65bd09076ad440296cdc656ce4d9bce885f1da216a11d
4
- data.tar.gz: bba7a5f528f10bda0a6bb0bfc9766c8bc62585931336a1916665ad97d3c79f9b
3
+ metadata.gz: 964af5b7bbee12fa4477afd5183b52785a323fd11f8d888399c457847613c012
4
+ data.tar.gz: 8de677e0c699e4b7a53310fe572107d77d714aa7f011cf1a36e191dd59278a99
5
5
  SHA512:
6
- metadata.gz: d68aaf7a3982b5213fb9a142a84e3910efb0c5e28f00c1527b625c8804c09e024100aeaa68ad9c7153f545adc9544f9a9e135d14454c2ef9b310f65b14206980
7
- data.tar.gz: 4ecf2664588d9e1443c1d4fb5b4ba4d7f13e48714317e74788cc2bdf285baf543587cddc1002042a7835c3074c86b560187ac2babca627cf559573f61f475784
6
+ metadata.gz: 11805fff7f98a872f30e4dd78a1ab684bceffeaa09e6a1198024c839c0ade648421006ebd93de00f73bf84ec0881e3dbc9d166dd290dece83975a40b6fa63d5a
7
+ data.tar.gz: f064437169a4ed114b0bdce9c1f7129ad92a3d6ba2450de4fe4d187cdab7da50f21d611954ad005312f138f3132dd4a36d9bb6200b7d5c83982cb5a47d3d9a00
@@ -4,42 +4,49 @@ document.addEventListener('DOMContentLoaded', function(){
4
4
  let data = {};
5
5
  let target = e.currentTarget;
6
6
  const url = target.dataset.url;
7
+ let url_type = url.split('.').pop();
7
8
  data[target.dataset.param] = target.querySelector('option:checked').text;
8
9
 
9
10
  fetch(url, {
10
11
  method: 'PUT',
11
- body: JSON.stringify(data),
12
+ body: JSON.stringify({post: data}),
12
13
  headers: { 'Content-Type': 'application/json' }
13
14
  })
14
15
  .then(response => {
15
- return response.json();
16
+ return url_type == 'js' ? response.text() : response.json();
16
17
  })
17
- .then(resultJson => {
18
- const form = target.parentNode;
19
- const hint = form.querySelector('span.inline-form-hint');
20
- if (hint) {
21
- hint.remove();
22
- };
18
+ .then(result => {
19
+ if(url_type == 'js') {
20
+ eval(result);
21
+ }
22
+ else {
23
+ const form = target.parentNode;
24
+ const hint = form.querySelector('span.inline-form-hint');
25
+ if (hint) {
26
+ hint.remove();
27
+ };
23
28
 
24
- if (resultJson.status === 'error') {
25
- form.dispatchEvent(createEvent('inlineEditError', resultJson));
29
+ if (result.status === 'error') {
30
+ form.dispatchEvent(createEvent('inlineEditError', result));
26
31
 
27
- form.classList.add('invalid-value');
28
- if (resultJson.message) {
29
- form.insertAdjacentHTML('beforeend',
30
- "<span class='inline-form-hint'>" + resultJson.message + "</span>"
31
- );
32
+ form.classList.add('invalid-value');
33
+ if (result.message) {
34
+ form.insertAdjacentHTML('beforeend',
35
+ "<span class='inline-form-hint'>" + result.message + "</span>"
36
+ );
37
+ }
32
38
  }
33
- } else {
34
- const container = form.parentNode;
35
- let clicableItem = container.querySelector('.clickable-item');
39
+ else {
40
+ const container = form.parentNode;
41
+ let clicableItem = container.querySelector('.clickable-item');
36
42
 
37
- form.dispatchEvent(createEvent('inlineEditSuccess', resultJson))
43
+ form.dispatchEvent(createEvent('inlineEditSuccess', result))
38
44
 
39
- form.classList.remove('invalid-value');
40
- clicableItem.innerHTML = '';
41
- clicableItem.insertAdjacentHTML('beforeend', resultJson.html);
42
- toggleVisibility(container);
45
+ form.classList.remove('invalid-value');
46
+ clicableItem.innerHTML = '';
47
+ clicableItem.insertAdjacentHTML('beforeend', result.html);
48
+ toggleVisibility(container);
49
+ }
43
50
  }
44
51
  })
45
52
  .catch(function(error) {
@@ -1,3 +1,3 @@
1
1
  module InlineEditor
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ShevchukTania
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-19 00:00:00.000000000 Z
11
+ date: 2020-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,7 +80,7 @@ homepage: https://github.com/ShevchukTania/inline_editor
80
80
  licenses:
81
81
  - MIT
82
82
  metadata: {}
83
- post_install_message:
83
+ post_install_message:
84
84
  rdoc_options: []
85
85
  require_paths:
86
86
  - lib
@@ -95,8 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.0.6
99
- signing_key:
98
+ rubygems_version: 3.0.8
99
+ signing_key:
100
100
  specification_version: 4
101
101
  summary: Inline editor for Rails applications
102
102
  test_files: []