ultimate-base 0.5.0.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/ultimate/backbone/app.js.coffee +47 -5
- data/app/assets/javascripts/ultimate/backbone/base.js.coffee +9 -10
- data/app/assets/javascripts/ultimate/backbone/collection.js.coffee +0 -1
- data/app/assets/javascripts/ultimate/backbone/lib/backbone.js +765 -673
- data/app/assets/javascripts/ultimate/backbone/model.js.coffee +0 -1
- data/app/assets/javascripts/ultimate/backbone/router.js.coffee +0 -4
- data/app/assets/javascripts/ultimate/backbone/view-mixins/nodes.js.coffee +51 -0
- data/app/assets/javascripts/ultimate/backbone/view.js.coffee +18 -104
- data/app/assets/javascripts/ultimate/base.js.coffee +1 -11
- data/app/assets/javascripts/ultimate/jquery-plugin-adapter.js.coffee +0 -1
- data/app/assets/javascripts/ultimate/jquery-plugin-class.js.coffee +3 -25
- data/app/assets/javascripts/ultimate/jquery.base.js.coffee +0 -2
- data/app/assets/javascripts/ultimate/underscore/underscore.inflection.js +4 -3
- data/app/assets/javascripts/ultimate/underscore/underscore.js +103 -80
- data/app/assets/javascripts/ultimate/underscore/underscore.string.js +71 -27
- data/lib/ultimate/base.rb +0 -1
- data/lib/ultimate/base/version.rb +1 -1
- metadata +3 -8
- data/app/assets/javascripts/ultimate/backbone/extra/jquery-ext.js.coffee +0 -96
- data/app/assets/javascripts/ultimate/improves/datepicker.js.coffee +0 -34
- data/app/assets/javascripts/ultimate/improves/devise.js.coffee +0 -18
- data/app/assets/javascripts/ultimate/improves/form-errors.js.coffee +0 -146
- data/app/assets/javascripts/ultimate/improves/tablesorter.js +0 -59
- data/lib/ultimate/extensions/directive_processor.rb +0 -64
@@ -41,12 +41,13 @@
|
|
41
41
|
lt: '<',
|
42
42
|
gt: '>',
|
43
43
|
quot: '"',
|
44
|
-
|
45
|
-
|
44
|
+
amp: '&',
|
45
|
+
apos: "'"
|
46
46
|
};
|
47
47
|
|
48
48
|
var reversedEscapeChars = {};
|
49
|
-
for(var key in escapeChars)
|
49
|
+
for(var key in escapeChars) reversedEscapeChars[escapeChars[key]] = key;
|
50
|
+
reversedEscapeChars["'"] = '#39';
|
50
51
|
|
51
52
|
// sprintf() for JavaScript 0.7-beta1
|
52
53
|
// http://www.diveintojavascript.com/projects/javascript-sprintf
|
@@ -206,7 +207,22 @@
|
|
206
207
|
|
207
208
|
count: function(str, substr){
|
208
209
|
if (str == null || substr == null) return 0;
|
209
|
-
|
210
|
+
|
211
|
+
str = String(str);
|
212
|
+
substr = String(substr);
|
213
|
+
|
214
|
+
var count = 0,
|
215
|
+
pos = 0,
|
216
|
+
length = substr.length;
|
217
|
+
|
218
|
+
while (true) {
|
219
|
+
pos = str.indexOf(substr, pos);
|
220
|
+
if (pos === -1) break;
|
221
|
+
count++;
|
222
|
+
pos += length;
|
223
|
+
}
|
224
|
+
|
225
|
+
return count;
|
210
226
|
},
|
211
227
|
|
212
228
|
chars: function(str) {
|
@@ -320,7 +336,7 @@
|
|
320
336
|
},
|
321
337
|
|
322
338
|
classify: function(str){
|
323
|
-
return _s.titleize(String(str).replace(/
|
339
|
+
return _s.titleize(String(str).replace(/[\W_]/g, ' ')).replace(/\s/g, '');
|
324
340
|
},
|
325
341
|
|
326
342
|
humanize: function(str){
|
@@ -429,17 +445,17 @@
|
|
429
445
|
},
|
430
446
|
|
431
447
|
toNumber: function(str, decimals) {
|
432
|
-
if (str
|
433
|
-
str =
|
434
|
-
|
435
|
-
return
|
448
|
+
if (!str) return 0;
|
449
|
+
str = _s.trim(str);
|
450
|
+
if (!str.match(/^-?\d+(?:\.\d+)?$/)) return NaN;
|
451
|
+
return parseNumber(parseNumber(str).toFixed(~~decimals));
|
436
452
|
},
|
437
453
|
|
438
454
|
numberFormat : function(number, dec, dsep, tsep) {
|
439
455
|
if (isNaN(number) || number == null) return '';
|
440
456
|
|
441
457
|
number = number.toFixed(~~dec);
|
442
|
-
tsep = tsep
|
458
|
+
tsep = typeof tsep == 'string' ? tsep : ',';
|
443
459
|
|
444
460
|
var parts = number.split('.'), fnums = parts[0],
|
445
461
|
decimals = parts[1] ? (dsep || '.') + parts[1] : '';
|
@@ -494,8 +510,8 @@
|
|
494
510
|
slugify: function(str) {
|
495
511
|
if (str == null) return '';
|
496
512
|
|
497
|
-
var from = "
|
498
|
-
to = "
|
513
|
+
var from = "ąàáäâãåæćęèéëêìíïîłńòóöôõøśùúüûñçżź",
|
514
|
+
to = "aaaaaaaaceeeeeiiiilnoooooosuuuunczz",
|
499
515
|
regex = new RegExp(defaultToWhiteSpace(from), 'g');
|
500
516
|
|
501
517
|
str = String(str).toLowerCase().replace(regex, function(c){
|
@@ -538,6 +554,36 @@
|
|
538
554
|
return repeat.join(separator);
|
539
555
|
},
|
540
556
|
|
557
|
+
naturalCmp: function(str1, str2){
|
558
|
+
if (str1 == str2) return 0;
|
559
|
+
if (!str1) return -1;
|
560
|
+
if (!str2) return 1;
|
561
|
+
|
562
|
+
var cmpRegex = /(\.\d+)|(\d+)|(\D+)/g,
|
563
|
+
tokens1 = String(str1).toLowerCase().match(cmpRegex),
|
564
|
+
tokens2 = String(str2).toLowerCase().match(cmpRegex),
|
565
|
+
count = Math.min(tokens1.length, tokens2.length);
|
566
|
+
|
567
|
+
for(var i = 0; i < count; i++) {
|
568
|
+
var a = tokens1[i], b = tokens2[i];
|
569
|
+
|
570
|
+
if (a !== b){
|
571
|
+
var num1 = parseInt(a, 10);
|
572
|
+
if (!isNaN(num1)){
|
573
|
+
var num2 = parseInt(b, 10);
|
574
|
+
if (!isNaN(num2) && num1 - num2)
|
575
|
+
return num1 - num2;
|
576
|
+
}
|
577
|
+
return a < b ? -1 : 1;
|
578
|
+
}
|
579
|
+
}
|
580
|
+
|
581
|
+
if (tokens1.length === tokens2.length)
|
582
|
+
return tokens1.length - tokens2.length;
|
583
|
+
|
584
|
+
return str1 < str2 ? -1 : 1;
|
585
|
+
},
|
586
|
+
|
541
587
|
levenshtein: function(str1, str2) {
|
542
588
|
if (str1 == null && str2 == null) return 0;
|
543
589
|
if (str1 == null) return String(str2).length;
|
@@ -576,25 +622,23 @@
|
|
576
622
|
_s.contains = _s.include;
|
577
623
|
_s.q = _s.quote;
|
578
624
|
|
625
|
+
// Exporting
|
626
|
+
|
579
627
|
// CommonJS module is defined
|
580
628
|
if (typeof exports !== 'undefined') {
|
581
|
-
if (typeof module !== 'undefined' && module.exports)
|
582
|
-
// Export module
|
629
|
+
if (typeof module !== 'undefined' && module.exports)
|
583
630
|
module.exports = _s;
|
584
|
-
}
|
585
|
-
exports._s = _s;
|
586
631
|
|
587
|
-
|
588
|
-
// Register as a named module with AMD.
|
589
|
-
define('underscore.string', [], function() {
|
590
|
-
return _s;
|
591
|
-
});
|
592
|
-
|
593
|
-
} else {
|
594
|
-
// Integrate with Underscore.js if defined
|
595
|
-
// or create our own underscore object.
|
596
|
-
root._ = root._ || {};
|
597
|
-
root._.string = root._.str = _s;
|
632
|
+
exports._s = _s;
|
598
633
|
}
|
599
634
|
|
635
|
+
// Register as a named module with AMD.
|
636
|
+
if (typeof define === 'function' && define.amd)
|
637
|
+
define('underscore.string', [], function(){ return _s; });
|
638
|
+
|
639
|
+
|
640
|
+
// Integrate with Underscore.js if defined
|
641
|
+
// or create our own underscore object.
|
642
|
+
root._ = root._ || {};
|
643
|
+
root._.string = root._.str = _s;
|
600
644
|
}(this, String);
|
data/lib/ultimate/base.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ultimate-base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -75,10 +75,10 @@ files:
|
|
75
75
|
- app/assets/javascripts/ultimate/backbone/app.js.coffee
|
76
76
|
- app/assets/javascripts/ultimate/backbone/base.js.coffee
|
77
77
|
- app/assets/javascripts/ultimate/backbone/collection.js.coffee
|
78
|
-
- app/assets/javascripts/ultimate/backbone/extra/jquery-ext.js.coffee
|
79
78
|
- app/assets/javascripts/ultimate/backbone/lib/backbone.js
|
80
79
|
- app/assets/javascripts/ultimate/backbone/model.js.coffee
|
81
80
|
- app/assets/javascripts/ultimate/backbone/router.js.coffee
|
81
|
+
- app/assets/javascripts/ultimate/backbone/view-mixins/nodes.js.coffee
|
82
82
|
- app/assets/javascripts/ultimate/backbone/view.js.coffee
|
83
83
|
- app/assets/javascripts/ultimate/backbone/views/slider.js.coffee
|
84
84
|
- app/assets/javascripts/ultimate/backbone/views/typed-fields.js.coffee
|
@@ -87,13 +87,9 @@ files:
|
|
87
87
|
- app/assets/javascripts/ultimate/experimental/_inflections/plur.js
|
88
88
|
- app/assets/javascripts/ultimate/experimental/fuzzy-json-generator.js.coffee
|
89
89
|
- app/assets/javascripts/ultimate/helpers.js.coffee
|
90
|
-
- app/assets/javascripts/ultimate/improves/datepicker.js.coffee
|
91
|
-
- app/assets/javascripts/ultimate/improves/devise.js.coffee
|
92
|
-
- app/assets/javascripts/ultimate/improves/form-errors.js.coffee
|
93
90
|
- app/assets/javascripts/ultimate/improves/form.js.coffee
|
94
91
|
- app/assets/javascripts/ultimate/improves/i18n-lite.js.coffee
|
95
92
|
- app/assets/javascripts/ultimate/improves/magic-radios.js.coffee
|
96
|
-
- app/assets/javascripts/ultimate/improves/tablesorter.js
|
97
93
|
- app/assets/javascripts/ultimate/improves/typed-fields.js.coffee
|
98
94
|
- app/assets/javascripts/ultimate/jquery-plugin-adapter.js.coffee
|
99
95
|
- app/assets/javascripts/ultimate/jquery-plugin-class.js.coffee
|
@@ -106,7 +102,6 @@ files:
|
|
106
102
|
- lib/ultimate/base.rb
|
107
103
|
- lib/ultimate/base/engine.rb
|
108
104
|
- lib/ultimate/base/version.rb
|
109
|
-
- lib/ultimate/extensions/directive_processor.rb
|
110
105
|
- scripts/rails
|
111
106
|
- test/dummy/Rakefile
|
112
107
|
- test/dummy/_emfile
|
@@ -1,96 +0,0 @@
|
|
1
|
-
#= require ../base
|
2
|
-
|
3
|
-
do ($ = jQuery) ->
|
4
|
-
|
5
|
-
# TODO arguments
|
6
|
-
$.fn.getViews = (viewClass = null, inheritance = false, domDeep = false) ->
|
7
|
-
if not @length
|
8
|
-
return []
|
9
|
-
else if @length is 1
|
10
|
-
views = @data("views") or []
|
11
|
-
else
|
12
|
-
# TODO check work and perf tests
|
13
|
-
views = _.flatten($(o).data("views") or [] for o in @, true)
|
14
|
-
#2: @map -> $(@).data("views") or []
|
15
|
-
#3: _.flatten ( @map -> $(@).data("views") or [] ), true
|
16
|
-
if viewClass?
|
17
|
-
_.filter views, if inheritance then (w) -> w instanceof viewClass else (w) -> w.costructor is viewClass
|
18
|
-
else
|
19
|
-
views
|
20
|
-
|
21
|
-
$.fn.getView = (viewClass, inheritance = false) ->
|
22
|
-
if _.isString(viewClass)
|
23
|
-
deprecate "getView() with viewClass as string", "viewClass as Backbone.View inheritor"
|
24
|
-
# for o in @
|
25
|
-
# views = $(o).data("views") or []
|
26
|
-
# for view in views
|
27
|
-
# return view if view.constructor.className is viewClass
|
28
|
-
else if Ultimate.Backbone.isViewClass(viewClass)
|
29
|
-
for o in @
|
30
|
-
views = $(o).data("views") or []
|
31
|
-
if inheritance
|
32
|
-
for view in views
|
33
|
-
return view if view instanceof viewClass
|
34
|
-
else
|
35
|
-
for view in views
|
36
|
-
return view if view.constructor is viewClass
|
37
|
-
false
|
38
|
-
|
39
|
-
$.fn.hasView = (viewClass) ->
|
40
|
-
if _.isString(viewClass)
|
41
|
-
deprecate "hasView() with viewClass as string", "viewClass as Backbone.View inheritor"
|
42
|
-
# for o in @
|
43
|
-
# return true if _.any $(o).data("views") or [], (w) -> w.constructor.className is viewClass
|
44
|
-
else if Ultimate.Backbone.isViewClass(viewClass)
|
45
|
-
for o in @
|
46
|
-
return true if _.any $(o).data("views") or [], (w) -> w.constructor is viewClass
|
47
|
-
false
|
48
|
-
|
49
|
-
# $.fn.bindOneView = (viewClass, options = {}) ->
|
50
|
-
# Ultimate.gcViews()
|
51
|
-
# bindedView = null
|
52
|
-
# if @length
|
53
|
-
# selector = "#{viewClass.selector}:not(.prevent-binding)"
|
54
|
-
# jContainer = if @is(selector) then @filter(selector) else @find(selector)
|
55
|
-
# if (l = jContainer.length)
|
56
|
-
# if l is 1
|
57
|
-
# bindedView = Ultimate.createView viewClass, jContainer, options
|
58
|
-
# else
|
59
|
-
# warning "$.fn.bindOneView() found #{l} elements by #{selector}, when need only 1"
|
60
|
-
# else
|
61
|
-
# warning "$.fn.bindOneView() not found elements by #{selector}"
|
62
|
-
# else
|
63
|
-
# warning "$.fn.bindOneView() call from empty jQuery()"
|
64
|
-
# bindedView
|
65
|
-
#
|
66
|
-
# $.fn.bindView = (viewClass, options = {}) ->
|
67
|
-
# Ultimate.gcViews()
|
68
|
-
# bindedViews = []
|
69
|
-
# if @length
|
70
|
-
# ( if @is(viewClass.selector) then @ else @find(viewClass.selector) ).filter(":not(.prevent-binding)").each ->
|
71
|
-
# if viewClass.canCreateInstance()
|
72
|
-
# jContainer = $ @
|
73
|
-
# if view = Ultimate.createView viewClass, jContainer, options
|
74
|
-
# bindedViews.push view
|
75
|
-
# else
|
76
|
-
# false
|
77
|
-
# bindedViews
|
78
|
-
#
|
79
|
-
# $.fn.bindViews = (viewClasses = Ultimate.LazyViews, options = {}) ->
|
80
|
-
# cout "info", "bindViews begin"
|
81
|
-
# bindedViews = []
|
82
|
-
# if @length
|
83
|
-
# bindedViews = for viewName, viewClass of viewClasses when viewClass.canCreateInstance()
|
84
|
-
# viewClass.constructor.className ||= viewName
|
85
|
-
# @bindView viewClass, options
|
86
|
-
# _.flatten bindedViews, true
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
# # TODO filtering by viewClass
|
91
|
-
# # TODO enother algorithm with enother projection
|
92
|
-
# $.fn.closestViews = (viewClass = null) ->
|
93
|
-
# views = []
|
94
|
-
# jTry = @
|
95
|
-
# jTry = jTry.parent() while jTry.length and not (views = jTry.getViews()).length
|
96
|
-
# views
|
@@ -1,34 +0,0 @@
|
|
1
|
-
|
2
|
-
@unlazy_datepickers = (jRoot) ->
|
3
|
-
jRoot.find('input.datepicker.lazy').removeClass('lazy').length
|
4
|
-
|
5
|
-
@bind_datepickers = (jRoot) ->
|
6
|
-
jRoot.find('input.datepicker:not(.lazy, .hasDatepicker)').each( ->
|
7
|
-
jThis = $ @
|
8
|
-
opts =
|
9
|
-
'showAnim' : ''
|
10
|
-
'showOn' : 'both'
|
11
|
-
'buttonImage' : '/images/forms/datepicker__icon.png' # TODO forwarding assets path
|
12
|
-
'buttonImageOnly': true
|
13
|
-
'changeMonth' : true
|
14
|
-
'changeYear' : true
|
15
|
-
'onClose' : (dateText, inst) -> $(inst.input).change().focusout()
|
16
|
-
opts[_.camelize(k)] = d for k, d of jThis.data()
|
17
|
-
jThis.datepicker opts
|
18
|
-
).length
|
19
|
-
|
20
|
-
$.fn.orig_datepicker = $.fn.datepicker
|
21
|
-
|
22
|
-
$.fn.datepicker = ->
|
23
|
-
return @ unless @length
|
24
|
-
@data('changed', true) if arguments.length and arguments[0] is 'setDate'
|
25
|
-
$.fn.orig_datepicker.apply @, arguments
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
$ ->
|
30
|
-
|
31
|
-
$('body').on 'keyup keydown', 'input.datepicker.hasDatepicker', ->
|
32
|
-
$(@).datepicker 'hide'
|
33
|
-
|
34
|
-
bind_datepickers $('body')
|
@@ -1,18 +0,0 @@
|
|
1
|
-
$ ->
|
2
|
-
|
3
|
-
jBody = $ 'body'
|
4
|
-
|
5
|
-
# fixes on sessions/new form, because devise don't return errors on fields
|
6
|
-
jBody.on 'ajax:error', 'form.sessions-new', ->
|
7
|
-
$(@).find(':input:visible').filter(-> not @value).closestEdge().setErrors()
|
8
|
-
false
|
9
|
-
|
10
|
-
# if devise form success, then open root path
|
11
|
-
jBody.on 'ajax:success', 'form.user[data-remote="true"]', (event, data, textStatus, jqXHR) ->
|
12
|
-
jForm = $ @
|
13
|
-
if jForm.hasClass('users-new')
|
14
|
-
getWidget('AccountPanel').showConfirmationInfo(jForm, data)
|
15
|
-
else if jForm.hasClass('password-recovery')
|
16
|
-
getWidget('AccountPanel').showConfirmationInfo(jForm, data)
|
17
|
-
else unless jForm.hasClass('status')
|
18
|
-
window.location = jqXHR.getResponseHeader('Location') or '/'
|
@@ -1,146 +0,0 @@
|
|
1
|
-
# TODO this is part of custom forms
|
2
|
-
# TODO registrable
|
3
|
-
# TODO may be, replace "clear immune" technique with something more effective, ex. additional class
|
4
|
-
|
5
|
-
( ( $ ) ->
|
6
|
-
|
7
|
-
$.errorableFields = {}
|
8
|
-
$.errorableFieldsSelector = ''
|
9
|
-
|
10
|
-
$.registerErrorableField = (selector, events, errorCleaner) ->
|
11
|
-
$.errorableFields[selector.split(/\s+/)[0]] = arguments
|
12
|
-
$.errorableFieldsSelector = _.keys($.errorableFields).join(', ')
|
13
|
-
true
|
14
|
-
|
15
|
-
$.fieldWithErrorsWrapperClass = 'field_with_errors'
|
16
|
-
$.fieldWithClearImmuneWrapperClass = 'immune'
|
17
|
-
$.labelForFieldWithErrorClass = 'with-error'
|
18
|
-
|
19
|
-
# [ selector: String = '.g-select, .g-text-field, .g-text-area' ]
|
20
|
-
# [ [, ]errors: Array = [] ]
|
21
|
-
# [ [, ]clearImmune: Boolean = false ]
|
22
|
-
$.fn.setFormErrors = ->
|
23
|
-
# dafault parameters
|
24
|
-
selector = $.errorableFieldsSelector # '.g-select, .g-text-field, .g-text-area'
|
25
|
-
errors = []
|
26
|
-
clearImmune = false
|
27
|
-
# parsing arguments
|
28
|
-
# TODO liquid arguments parser ( by arguments info, ex: {selector: String, errors: Array, clearImmune: Boolean} )
|
29
|
-
a = args arguments
|
30
|
-
if a.length
|
31
|
-
first = a.shift()
|
32
|
-
if _.isString first
|
33
|
-
selector = first
|
34
|
-
if a.length
|
35
|
-
first = a.shift()
|
36
|
-
if _.isString first
|
37
|
-
first = [first]
|
38
|
-
if _.isArray first
|
39
|
-
errors = _.uniq first
|
40
|
-
if a.length
|
41
|
-
first = a.shift()
|
42
|
-
if _.isBoolean first
|
43
|
-
clearImmune = first
|
44
|
-
# ui process
|
45
|
-
@clearFormErrors selector, clearImmune
|
46
|
-
wrapperSelector = ".#{$.fieldWithErrorsWrapperClass}"
|
47
|
-
if clearImmune
|
48
|
-
wrapperSelector += ".#{$.fieldWithClearImmuneWrapperClass}"
|
49
|
-
jErrorWrappers = @find(selector).wrap(selectorToHtml wrapperSelector).parent()
|
50
|
-
jErrorWrappers.append (for err in errors then content_tag('div', err, class: 'error')).join("\n")
|
51
|
-
jErrorWrappers.closestLabel().addClass($.labelForFieldWithErrorClass)
|
52
|
-
|
53
|
-
$.fn.setErrors = ->
|
54
|
-
deprecate('jQ.setErrors(...)', 'jQ.setFormErrors(...)')
|
55
|
-
@setFormErrors.apply(@, arguments)
|
56
|
-
|
57
|
-
# [selector]
|
58
|
-
# [clearImmune]
|
59
|
-
$.fn.clearFormErrors = ->
|
60
|
-
selector = $.errorableFieldsSelector # '.g-select, .g-text-field, .g-text-area'
|
61
|
-
clearImmune = false
|
62
|
-
# parsing arguments
|
63
|
-
# TODO liquid arguments parser ( by arguments info, ex: {selector: String, clearImmune: Boolean} )
|
64
|
-
a = args arguments
|
65
|
-
if a.length
|
66
|
-
first = a.shift()
|
67
|
-
if _.isString first
|
68
|
-
selector = first
|
69
|
-
if a.length
|
70
|
-
first = a.shift()
|
71
|
-
if _.isBoolean(first)
|
72
|
-
clearImmune = first
|
73
|
-
wrapperSelector = ".#{$.fieldWithErrorsWrapperClass}"
|
74
|
-
if clearImmune
|
75
|
-
wrapperSelector += ".#{$.fieldWithClearImmuneWrapperClass}"
|
76
|
-
else
|
77
|
-
wrapperSelector += ":not(.#{$.fieldWithClearImmuneWrapperClass})"
|
78
|
-
fullSelector = "#{wrapperSelector}:has(#{selector})"
|
79
|
-
jErrorWrappers = @find fullSelector
|
80
|
-
jErrorWrappers = @closest fullSelector unless jErrorWrappers.length
|
81
|
-
if jErrorWrappers.length
|
82
|
-
jErrorWrappers.closestLabel().removeClass($.labelForFieldWithErrorClass)
|
83
|
-
jErrorWrappers.children('.error').remove()
|
84
|
-
jErrorWrappers.children(selector).unwrap()
|
85
|
-
@
|
86
|
-
|
87
|
-
$.fn.clearFromErrors = ->
|
88
|
-
deprecate('jQ.clearFromErrors(...)', 'jQ.clearFormErrors(...)')
|
89
|
-
@clearFormErrors.apply(@, arguments)
|
90
|
-
|
91
|
-
$.ujsAjaxError = (event, jqXHR) ->
|
92
|
-
jForm = $(@).clearFormErrors()
|
93
|
-
try
|
94
|
-
responseJSON = $.parseJSON jqXHR.responseText
|
95
|
-
errors = responseJSON['errors'] or responseJSON
|
96
|
-
if errors
|
97
|
-
jFields = jForm.find '[name*="["]:input:visible' # TODO research without :visible, because has custom elements
|
98
|
-
if jFields.length
|
99
|
-
for fieldErrors, fieldName of errors
|
100
|
-
jField = jFields.filter "[name$=\"[#{fieldName}]\"]"
|
101
|
-
if jField.length
|
102
|
-
jField.closestEdge().setErrors fieldErrors
|
103
|
-
catch e
|
104
|
-
# nop
|
105
|
-
true
|
106
|
-
|
107
|
-
|
108
|
-
$.fn.customErrorsHandler = (suspend = true, eventName = 'ajax:error', selector = 'form[data-remote="true"]') ->
|
109
|
-
if @length
|
110
|
-
if @is 'form'
|
111
|
-
jForms = @filter selector
|
112
|
-
jForms.off eventName, $.ujsAjaxError
|
113
|
-
jForms.on eventName, $.ujsAjaxError if suspend
|
114
|
-
else
|
115
|
-
@off eventName, selector, $.ujsAjaxError
|
116
|
-
@on eventName, selector, $.ujsAjaxError if suspend
|
117
|
-
@
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
$.fn.errorCleaners = (suspend = true) ->
|
123
|
-
if @length
|
124
|
-
jDocks = if @is ':input' then @closestEdge() else @
|
125
|
-
for fieldWrapperSelector, [selector, events, errorCleaner] of $.errorableFields
|
126
|
-
fullSelector = ".#{$.fieldWithErrorsWrapperClass} > #{selector}"
|
127
|
-
jDocks.off events, fullSelector
|
128
|
-
jDocks.on events, fullSelector, errorCleaner if suspend
|
129
|
-
@
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
$.registerErrorableField '.g-text-field input:visible', 'change keyup', ->
|
134
|
-
# text-fields error cleaner
|
135
|
-
jTextField = $ @
|
136
|
-
unless jTextField.val() is '' # TODO may be use isEmptyString()
|
137
|
-
jTextField.clearFormErrors('.g-text-field').clearFormErrors('.g-text-field', true)
|
138
|
-
jTextField.change().focus() # unwraping break change, and there changing continue
|
139
|
-
|
140
|
-
$.registerErrorableField '.g-select select', 'change', ->
|
141
|
-
# selects error cleaner
|
142
|
-
jSelect = $ @
|
143
|
-
unless jSelect.val() is '' # TODO may be use isEmptyString()
|
144
|
-
jSelect.clearFormErrors('.g-select').clearFormErrors('.g-select', true)
|
145
|
-
|
146
|
-
)( jQuery )
|