tb_core 1.3.9 → 1.3.10

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: 7071129edfa67883164c13d28337400840d8977b
4
- data.tar.gz: aee125137d5a1b6c5bd033480eccbf555fddf2fa
3
+ metadata.gz: 1f0cffee46e753563727811398cd307e5263df61
4
+ data.tar.gz: a47903d588cfae9ddea08cbe0a844685b7a9578f
5
5
  SHA512:
6
- metadata.gz: 474dd7c6e09fd2a1228387c2281a2156658b52b3eb3a05f634827cfa1f8d5efeda720dd0ccffa1306293ec87dea42567239ccde4ed5d0157f67431792bfa40fc
7
- data.tar.gz: d6ed5438c32dc90b131dc4bf6f907a0dac1de00fc17a48d01e043578b7f873263731e647ccf2526f55a18950f41e8022e3868c72a44bd4abbb6dda285cbe895f
6
+ metadata.gz: c5e33f9dc1dea1dc14efae2017bce65b7168cab6a1b9a6c5d082898fce58a2eb134ee88a811414ce360a3e5c5ad676be29ef942d22b2d7110c204ab0f3b5b229
7
+ data.tar.gz: 3ccb89456ef9606374f775aaeadffb943ea144e0167d02b6243ce1eb2b17bb2f87363dac20d34272c03ce4b31ca8ef558f3c18f38b810156facf562aa8b08a33
@@ -33,7 +33,7 @@ tb.remote = {
33
33
  var onRemoteFormBefore = function(event){
34
34
  var $form = $(this);
35
35
  if($form.data('type') === undefined){
36
- $form.data('type', 'json');
36
+ $form.data('type', 'json');
37
37
  }
38
38
  };
39
39
 
@@ -91,7 +91,7 @@ var buildSuccessPath = function(path, json){
91
91
  *
92
92
  * ie:
93
93
  * <form action="..." data-remote="true" data-errors="inline">
94
- * - OR -
94
+ * - OR -
95
95
  * <form action="..." data-remote="true" data-errors="alert">
96
96
  */
97
97
  var onRemoteFormErrors = function(event, jqXHR, textStatus, errorThrown){
@@ -99,7 +99,7 @@ var onRemoteFormErrors = function(event, jqXHR, textStatus, errorThrown){
99
99
  var errorType = $form.data('errors');
100
100
  if(jqXHR.status == 422){
101
101
  if(errorType == 'inline'){
102
- displayErrorsInline($form, jqXHR.responseJSON.errors);
102
+ displayErrorsInline($form, jqXHR.responseJSON);
103
103
  }
104
104
  else{
105
105
  displayErrorsAlert(jqXHR.responseJSON);
@@ -119,9 +119,10 @@ var onRemoteFormErrors = function(event, jqXHR, textStatus, errorThrown){
119
119
  var displayErrorsInline = function($form, errors){
120
120
  $form.find('.form-error-inline, .form-error-base').remove();
121
121
  for(var key in errors){
122
+ var messages = errors[key].messages;
122
123
  if(key == 'base'){
123
- for(var i=0; i<errors[key].length; i++){
124
- $form.prepend('<p class="form-error form-error-base">'+errors[key][i]+'</p>');
124
+ for(var i=0; i<messages.length; i++){
125
+ $form.prepend('<p class="form-error form-error-base">'+messages[i]+'</p>');
125
126
  }
126
127
  }
127
128
  else{
@@ -134,20 +135,21 @@ var displayErrorsInline = function($form, errors){
134
135
  $input = $form.find("[name$='[" + keyArr.join('][') + "]']");
135
136
  }
136
137
  else{
137
- $input = $form.find("[name$='[" + key + "]']");
138
-
138
+ $input = $form.find("[name$='[" + key + "]']").filter(function(index, input){
139
+ return !input.name.match(/\]\[/); // Filter out nested attribute inputs ie model[a][b]
140
+ })
139
141
  if($input.length === 0 && !key.match(/_id$/)){
140
142
  $input = $form.find("[name$='[" + key + "_id]']");
141
143
  }
142
144
  }
143
145
 
146
+ var message = messages[0];
144
147
  if($input.length > 0){
145
- var message = errors[key][0];
146
148
  $input.parent().append('<p class="form-error form-error-inline">'+message+'</p>');
147
149
  }
148
150
  else{
149
151
  console.warn('Missing input field for key:', key);
150
- $form.prepend('<p class="form-error form-error-base">'+key+' '+errors[key][0]+'</p>');
152
+ $form.prepend('<p class="form-error form-error-base">'+key+' '+message+'</p>');
151
153
  }
152
154
  }
153
155
  }
@@ -156,7 +158,7 @@ var displayErrorsInline = function($form, errors){
156
158
  if(!tb.util.elementIsInView($firstError)){
157
159
  $('body, html').animate({
158
160
  scrollTop: $firstError.offset().top
159
- });
161
+ });
160
162
  }
161
163
  }
162
164
  };
@@ -164,14 +166,19 @@ var displayErrorsInline = function($form, errors){
164
166
  /*
165
167
  * Display errors in a standard window.alert dialog
166
168
  */
167
- var displayErrorsAlert = function(json){
169
+ var displayErrorsAlert = function(errors){
168
170
  var text = "Please correct the following errors:\n";
169
171
  var label, message;
170
172
  var index = 0;
171
- for(var key in json.errors){
172
- label = json.labels[index];
173
- message = json.errors[key][0];
174
- text += " - " + label + ' ' + message + "\n";
173
+ for(var key in errors){
174
+ label = errors[key].label;
175
+ message = errors[key].messages[0];
176
+ if(key == 'base'){
177
+ text += ' - ' + message + "\n"
178
+ }
179
+ else{
180
+ text += ' - ' + label + ' ' + message + "\n"
181
+ }
175
182
  index++;
176
183
  }
177
184
  window.alert(text);
@@ -191,7 +198,7 @@ var onRemoteDeleteTableRow = function(){
191
198
  /*
192
199
  * Attach an authenticity_token input field when a remote form aborts due to a file input field
193
200
  *
194
- * When a form is configured with remote:true, the authenticity_token hidden input you would normally see is not included. Then what
201
+ * When a form is configured with remote:true, the authenticity_token hidden input you would normally see is not included. Then what
195
202
  * can happen is the form can fall back to a non-remote action for some reason, possibly due to the presence of a file input field. The
196
203
  * net result is that the server responds with a "Can't verify CSRF token authenticity" error because none was sent.
197
204
  *
@@ -214,7 +221,7 @@ var onRemoteAbortedFile = function(event, inputs){
214
221
 
215
222
  /*
216
223
  * Monkeypatch the base $.rails.enableFormElement function to add a
217
- * delay and a success text value to the button before returning to
224
+ * delay and a success text value to the button before returning to
218
225
  * default state.
219
226
  */
220
227
  var extendEnableFormElementMethod = function(){
@@ -232,7 +239,7 @@ var extendEnableFormElementMethod = function(){
232
239
  }, 1000);
233
240
  }
234
241
  else{
235
- originalEnableFormElement(element);
242
+ originalEnableFormElement(element);
236
243
  }
237
244
  };
238
245
  };
@@ -1,16 +1,16 @@
1
- class UserSessionsController < ApplicationController
1
+ class UserSessionsController < ApplicationController
2
2
 
3
3
  skip_before_action :require_user, :only => [:new, :create, :destroy]
4
4
  skip_before_action :check_requires_password_change, :only => [:destroy, :change_password, :set_change_password]
5
5
 
6
6
  respond_to :html, :json, :js
7
7
  layout 'user_sessions'
8
-
8
+
9
9
  def new
10
10
  @user_session = SpudUserSession.new
11
11
  render 'new'
12
12
  end
13
-
13
+
14
14
  def create
15
15
  @user_session = SpudUserSession.new(params[:spud_user_session])
16
16
  if @user_session.save()
@@ -31,7 +31,7 @@
31
31
  end
32
32
  end
33
33
  end
34
-
34
+
35
35
  def destroy
36
36
  current_user_session.destroy unless current_user_session.blank?
37
37
  respond_with({}) do |format|
@@ -43,6 +43,7 @@
43
43
  end
44
44
 
45
45
  def change_password
46
+ require_user
46
47
  render 'change_password'
47
48
  end
48
49
 
@@ -1,5 +1,5 @@
1
1
  module Spud
2
2
  module Core
3
- VERSION = "1.3.9"
3
+ VERSION = "1.3.10"
4
4
  end
5
5
  end
@@ -26,10 +26,12 @@ class TbCore::Responder < ActionController::Responder
26
26
  # This override also sends the translated labels for convenience
27
27
  #
28
28
  def json_resource_errors
29
- return {
30
- :errors => resource.errors,
31
- :labels => resource.errors.keys.collect{ |attribute| resource.class.human_attribute_name(attribute) }
32
- }
29
+ return Hash[resource.errors.messages.map do |attribute, messages|
30
+ [attribute, {
31
+ label: resource.class.human_attribute_name(attribute),
32
+ messages: messages
33
+ }]
34
+ end]
33
35
  end
34
36
 
35
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tb_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.9
4
+ version: 1.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Woods
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-02 00:00:00.000000000 Z
11
+ date: 2016-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails