formily 0.0.5.5.7 → 0.0.5.5.9

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
  SHA1:
3
- metadata.gz: b84fc2bb7f9473589b61bd8996d0ff5746aae335
4
- data.tar.gz: 21a06152a3ab5e902fcd9d1faa45a763d7361d4f
3
+ metadata.gz: 966730c1ed08384468fff0f6840c15a866e41f23
4
+ data.tar.gz: a76f7649a99b0fb2dfc7fcf964ccfe53759c2371
5
5
  SHA512:
6
- metadata.gz: 38308ce7f7d6f9394640108d5672a778e1aeab9632db18ed9f85f7abcf16716d4ba53e50773be43082c64cbb6157812e0293cad8df47666bbd45e8f8cefc822b
7
- data.tar.gz: 8df0264eb76c96fe953fc88e231540d89be3bb2b8bb18bf6e4fb6fc4ec6b4646f0627824a0930f002fbb9f914545ca9baeda399f9d9e04404df01c87a5037dfe
6
+ metadata.gz: cc07e3d91213b72d5061b709d509606b85a623734f545e9346b36dddf86bead27745727e06527c09eb41d22280f57879aa5249c5184d462060580f61e3bc6a52
7
+ data.tar.gz: f30d8de78c624cc3777e22833de2b9b005869bf5e54733f89964303b9670d055780d7fbdc8a899b139afa25cbecaef2852208db0ca613a40ac3148327a01cbc4
@@ -63,6 +63,25 @@ $(document).ready(function() {
63
63
  $('.formily-edit').remove();
64
64
  });
65
65
 
66
+ $(document).on('click', '#formily_delete', function(e){
67
+ if(isFormilyFileUploaded()){
68
+ var self = $(this);
69
+ var id = self.data('formilyDeleteResponseId');
70
+ var data = self.data('formilyResponse');
71
+
72
+ if(confirm('Are you sure you want to delete the form submission?')){
73
+ $.ajax({
74
+ url: FormilyRoutes.response_delete_path(id),
75
+ data: data,
76
+ type: 'DELETE',
77
+ success: function(){
78
+ closeWindowFunc('formily_update_table');
79
+ }
80
+ });
81
+ }
82
+ }
83
+ });
84
+
66
85
  $('#formily_form_tag').on('submit', function(e){
67
86
  var form = $(this);
68
87
 
@@ -25,4 +25,25 @@ $(document).ready(function() {
25
25
  e.preventDefault();
26
26
  });
27
27
 
28
- });
28
+ $(document).on('click', 'span[data-formily-delete-response-id]', function(e){
29
+ var self = $(this);
30
+ var id = self.data('formilyDeleteResponseId');
31
+ var data = self.data('formilyResponse');
32
+
33
+ if(confirm('Are you sure you want to delete the form submission?')){
34
+ $.ajax({
35
+ url: FormilyRoutes.response_delete_path(id),
36
+ data: data,
37
+ type: 'DELETE',
38
+ success: function(){
39
+ $(document).trigger('formily_update_table', data);
40
+ },
41
+ error: function(resp){
42
+ console.error(resp.responseJSON.msg);
43
+ alert(resp.responseJSON.msg);
44
+ }
45
+ });
46
+ }
47
+ e.preventDefault();
48
+ });
49
+ });
@@ -22,5 +22,8 @@ window.FormilyRoutes = {
22
22
  },
23
23
  form_upload_file_path: function () {
24
24
  return "<%= url.upload_file_formily_submit_data_path %>";
25
- }
26
- };
25
+ },
26
+ response_delete_path: function (id) {
27
+ return "<%= url.destroy_response_formily_submit_data_path(0).to_s[0...-1] %>" + id.toString();
28
+ },
29
+ };
@@ -123,6 +123,12 @@ span.ff-icon-plus {
123
123
  cursor: pointer;
124
124
  }
125
125
 
126
+ span.ff-icon-trash-empty {
127
+ position: relative;
128
+ cursor: pointer;
129
+ color: red;
130
+ }
131
+
126
132
  .panel.warning {
127
133
  border-color: #f08a24;
128
134
  }
@@ -17,16 +17,9 @@ class Formily::FormsController < FormilyController
17
17
 
18
18
  def show
19
19
  @form = Formily::Form.find(params[:id])
20
- model = params[:model_name].safe_constantize
21
- @obj_rel = model.find(params[:model_id])
22
-
23
- @submit = @form.submits.find_by(id: params[:submit_id])
24
-
25
- if @submit.blank?
26
- @submit = Formily::Submit.create({form_id: @form.id, resource_id: params[:model_id],
27
- user_id: params[:user_id], resource_type: params[:model_name]})
28
- end
29
-
20
+ form_model = params[:model_name].safe_constantize
21
+ @obj_rel = form_model.find(params[:model_id])
22
+ @submit = @form.find_or_create_submission_by(params)
30
23
  end
31
24
 
32
25
  def edit
@@ -90,7 +83,6 @@ class Formily::FormsController < FormilyController
90
83
  render partial: 'preview', layout: false, locals: {:@form => form, :@obj_rel => form, :@submit => submit}
91
84
  end
92
85
 
93
-
94
86
  def reload_formily_table
95
87
  user_id = params[:user_id]
96
88
  obj_rel = params[:resource_type].safe_constantize.find(params[:resource_id])
@@ -98,7 +90,6 @@ class Formily::FormsController < FormilyController
98
90
  render locals: {obj_rel: obj_rel, user_id: user_id, flag: params[:flag].present?}, layout: false
99
91
  end
100
92
 
101
-
102
93
  def add_new_response
103
94
  submit = Formily::Submit.where(params.permit(:form_id, :resource_id, :user_id, :resource_type))
104
95
  .order(created_at: :desc).first
@@ -1,28 +1,18 @@
1
1
  # coding: utf-8
2
2
  class Formily::Iframe::FormsController < FormilyController
3
-
4
3
  def show
5
4
  @form = Formily::Form.find(params[:id])
6
-
7
- model = params[:model_name].safe_constantize
8
-
9
- @obj_rel = model.blank? ? nil : model.find(params[:model_id])
10
-
11
- @submit = @form.submits.find_by(id: params[:submit_id])
12
-
13
- if @submit.blank?
14
- @submit = Formily::Submit.create({form_id: @form.id, resource_id: params[:model_id],
15
- user_id: params[:user_id], resource_type: params[:model_name]})
16
- end
5
+ form_model = params[:model_name].safe_constantize
6
+ @obj_rel = form_model.blank? ? nil : form_model.find(params[:model_id])
7
+ @submit = @form.find_or_create_submission_by(params)
17
8
  end
18
9
 
19
10
  def add
20
11
  end
21
12
 
22
-
23
13
  private
24
- def formily_layout
25
- 'formily_iframe'
26
- end
27
14
 
28
- end
15
+ def formily_layout
16
+ 'formily_iframe'
17
+ end
18
+ end
@@ -137,6 +137,13 @@ class Formily::SubmitDataController < FormilyController
137
137
  end
138
138
  end
139
139
 
140
+ def destroy_response
141
+ submit = Formily::Submit.find(params[:id])
142
+ submit.destroy
143
+
144
+ render json: {}, status: :ok
145
+ end
146
+
140
147
  private
141
148
  def set_layout
142
149
  if params[:iframe]
@@ -25,6 +25,12 @@ class Formily::Form < ActiveRecord::Base
25
25
  '#response'
26
26
  end
27
27
 
28
+ def find_or_create_submission_by(attributes)
29
+ submission = submits.find_by(id: attributes[:submit_id])
30
+ submission ||= submits.find_by(resource_id: attributes[:model_id], user_id: attributes[:user_id], resource_type: attributes[:model_name])
31
+ submission ||= submits.create(resource_id: attributes[:model_id], user_id: attributes[:user_id], resource_type: attributes[:model_name])
32
+ end
33
+
28
34
  private
29
35
 
30
36
  def delete_data
@@ -5,6 +5,8 @@ class Formily::Submit < ActiveRecord::Base
5
5
 
6
6
  has_paper_trail
7
7
 
8
+ after_destroy :delete_data
9
+
8
10
  belongs_to :form
9
11
  has_many :input_values, foreign_key: :submit_id, class_name: 'Formily::InputValue', dependent: :destroy
10
12
 
@@ -44,4 +46,9 @@ class Formily::Submit < ActiveRecord::Base
44
46
  end
45
47
  end
46
48
 
47
- end
49
+ private
50
+
51
+ def delete_data
52
+ input_values.destroy_all
53
+ end
54
+ end
@@ -4,12 +4,13 @@
4
4
 
5
5
  - submits = [nil] if submits.blank?
6
6
 
7
+ - p = {user_id: user_id, authenticity_token: form_authenticity_token, form_id: form.id, resource_id: obj_rel.id, resource_type: obj_rel.class.to_s}
8
+
7
9
  - submits.each_with_index do |submit, i|
8
10
 
9
11
  %tr{'data-formily-form-id' => form.id}
10
12
  %td.icon
11
13
  - if i == 0
12
- - p = {user_id: user_id, authenticity_token: form_authenticity_token, form_id: form.id, resource_id: obj_rel.id, resource_type: obj_rel.class.to_s}
13
14
  %span.ff-icon-plus{title: 'Add New Response', 'data-tooltip'=> (browser.device.ipad? ? nil : ''), 'data-formily-new-response' => p.to_json, 'data-href' => add_new_response_formily_forms_path}
14
15
  %td.icon
15
16
  - if submit && submit.input_values.count > 0
@@ -25,4 +26,8 @@
25
26
  = show_formily_form_link_tag form.id, obj_rel, submit.try(:id) , user_id, title, class: 'response'
26
27
 
27
28
  - if form.description.present?
28
- %span.has-tip.tip-top{'data-tooltip'=> '', 'aria-haspopup'=>true, title: form.description} ?
29
+ %span.has-tip.tip-top{'data-tooltip'=> '', 'aria-haspopup'=>true, title: form.description} ?
30
+
31
+ %td.icon
32
+ - if submit.present?
33
+ %span.ff-icon-trash-empty{title: 'Delete Response', 'data-tooltip'=> (browser.device.ipad? ? nil : ''), 'data-formily-delete-response-id' => submit.id, 'data-formily-response' => p.to_json}
@@ -34,4 +34,7 @@
34
34
 
35
35
  %input.button.tiny#formily_cancel{type: 'button', value: 'Cancel', title: 'Cancel'}
36
36
 
37
+ - p = {user_id: @user_id, authenticity_token: form_authenticity_token, form_id: @form.id, resource_id: @obj_rel.id, resource_type: @obj_rel.class.to_s}
38
+ %input.button.tiny.alert#formily_delete{type: 'button', value: 'Delete', title: 'Delete', 'data-formily-delete-response-id' => @submit.id, 'data-formily-response' => p.to_json}
39
+
37
40
  .formily-spinner
@@ -26,6 +26,7 @@ Rails.application.routes.draw do
26
26
  collection do
27
27
  post 'submit', action: :submit
28
28
  post 'upload_file', action: :upload_file
29
+ delete 'destroy_response/:id', action: :destroy_response, as: :destroy_response
29
30
  end
30
31
  end
31
32
 
@@ -1,4 +1,4 @@
1
1
  # coding: utf-8
2
2
  module Formily
3
- VERSION = '0.0.5.5.7'
3
+ VERSION = '0.0.5.5.9'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formily
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5.5.7
4
+ version: 0.0.5.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-12 00:00:00.000000000 Z
11
+ date: 2018-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler