jqajax_core2 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/assets/javascripts/jqac2/core.js.coffee.erb +109 -0
- data/app/assets/javascripts/jqac2/helpers.js.coffee.erb +52 -0
- data/app/assets/javascripts/jqac2/initializer.js.coffee.erb +30 -0
- data/app/assets/javascripts/jqac2/loading.js.coffee.erb +58 -0
- data/app/assets/javascripts/jqac2/modal.js.coffee.erb +83 -0
- data/app/assets/javascripts/jqac2/validation.js.coffee.erb +244 -0
- data/app/assets/javascripts/jqac2/widget_classes/checkbox_slidedown.coffee +33 -0
- data/app/assets/javascripts/jqac2/widgets.js.coffee +27 -0
- data/app/assets/javascripts/jqajax-core2.js.erb +8 -0
- data/app/assets/stylesheets/jqajax-core2.scss.erb +54 -0
- data/app/assets/stylesheets/jqajax2-variables.scss +10 -0
- data/app/controllers/jqac2_controller.rb +9 -0
- data/app/helpers/jqajax_core_helper.rb +139 -0
- data/app/helpers/jqajax_validation_helper.rb +76 -0
- data/app/helpers/jqajax_view_helper.rb +29 -0
- data/app/views/jqajax/_flash.html.erb +9 -0
- data/app/views/jqajax/_loader.html.erb +4 -0
- data/app/views/jqajax/_modal.html.erb +14 -0
- data/app/views/jqajax/_overlay.html.erb +11 -0
- data/app/views/layouts/_ajax_overlay.html.erb +5 -0
- data/app/views/layouts/_info_overlay.html.erb +9 -0
- data/app/views/layouts/jqac2_modal.html.erb +9 -0
- data/config/locales/jqac2.validations.de.yml +12 -0
- data/config/routes.rb +10 -0
- data/lib/jqajax_core2/application_controller_ext.rb +17 -0
- data/lib/jqajax_core2/config.rb +31 -0
- data/lib/jqajax_core2/engine.rb +10 -0
- data/lib/jqajax_core2/validations.rb +147 -0
- data/lib/jqajax_core2.rb +107 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c33f2459d45b3e3b72d1733224c92a3b27029a1b
|
4
|
+
data.tar.gz: 7f00bf6b9b0aa00d5507064ff1a68c2c00a5b2a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '09d2abfff9674248ed7e375df4a817e293f0301e0d2a00188faa7f6e942a2c4ba034575317cbbbd8d5eb771d8208c4e8a8c931b82a0de348c3036e91af64748a'
|
7
|
+
data.tar.gz: d9dcb7f5e0777cb17da6715daf94018a25e46c660aaa6412cd19c9a8f3c7b28f6584d56ff2bf5db2370e12f13a9393989b91d76f45839faa7c822d1dc8850a59
|
@@ -0,0 +1,109 @@
|
|
1
|
+
window.JqAjaxCore2= {} if typeof(window.JqAjaxCore2) is 'undefined'
|
2
|
+
|
3
|
+
window.JqAjaxCore2.Core =
|
4
|
+
|
5
|
+
# initialisierung des Default Links
|
6
|
+
initDefaultLink: ->
|
7
|
+
# Default Ajax Link, formerly known as 'ajax_default_link'-Helper
|
8
|
+
# Data will be automatically rendered into ajax overlay container, after showing loading message
|
9
|
+
# add 'update-div-...' to set custom div to render data in!
|
10
|
+
|
11
|
+
unloadedLinks = $("a.<%= JqajaxCore2::Config.core[:ajax_link_class] %>.<%= JqajaxCore2::Config.core[:no_ajax_link_class] %>, form.<%= JqajaxCore2::Config.core[:ajax_link_class] %>.<%= JqajaxCore2::Config.core[:no_ajax_link_class] %>")
|
12
|
+
|
13
|
+
# XHR Data Handler - beforeSend
|
14
|
+
# Loading information should be displayed
|
15
|
+
unloadedLinks.bind 'ajax:beforeSend', (xhr,settings) ->
|
16
|
+
link_options = JqAjaxCore2.Helpers.linkOptionsFromElement(this)
|
17
|
+
# Checking if data should be submitted
|
18
|
+
# TODO: Does not work because of rails jquery_ujs shizznit...
|
19
|
+
# settings.data is not passed back to ajax handler
|
20
|
+
if link_options['submit_data'] != ''
|
21
|
+
form_data = jQuery("#" + link_options['submit_data'] + " :input").serialize()
|
22
|
+
settings.data = form_data
|
23
|
+
settings.type = "post"
|
24
|
+
|
25
|
+
if link_options['confirm'] == true
|
26
|
+
return confirm link_options['confirm_message']
|
27
|
+
|
28
|
+
if link_options['load_message'] != ''
|
29
|
+
JqAjaxCore2.Loading.addLoader(link_options['target_div'], link_options['load_message'])
|
30
|
+
else
|
31
|
+
JqAjaxCore2.Loading.showLoading()
|
32
|
+
|
33
|
+
|
34
|
+
# XHR Data Handler - Success
|
35
|
+
# The response should be handled and placed in the content
|
36
|
+
unloadedLinks.bind 'ajax:success', (xhr, data, status) ->
|
37
|
+
link_options = JqAjaxCore2.Helpers.linkOptionsFromElement($(this))
|
38
|
+
target = $("#"+link_options['target_div'])
|
39
|
+
if link_options['append'] == true
|
40
|
+
target.append(data)
|
41
|
+
else
|
42
|
+
target.html(data)
|
43
|
+
|
44
|
+
JqAjaxCore2.Loading.hideLoading()
|
45
|
+
|
46
|
+
if link_options['callback'] != ''
|
47
|
+
eval(link_options['callback'])
|
48
|
+
|
49
|
+
JqAjaxCore2.Initializer.initJqAc2()
|
50
|
+
|
51
|
+
# XHR Data Handler - Error
|
52
|
+
unloadedLinks.bind 'ajax:error', (xhr, status, error) ->
|
53
|
+
<% if Rails.env == 'development' %>
|
54
|
+
JqAjaxCore2.Loading.flashNoticeDisplay("Error - see log for details", 'error')
|
55
|
+
<% end %>
|
56
|
+
JqAjaxCore2.Loading.hideLoading()
|
57
|
+
|
58
|
+
unloadedLinks.removeClass("<%= JqajaxCore2::Config.core[:no_ajax_link_class] %>");
|
59
|
+
|
60
|
+
initSelectOnchange: ->
|
61
|
+
# Default Ajax Link, formerly known as 'ajax_default_link'-Helper
|
62
|
+
# Data will be automatically rendered into ajax overlay container, after showing loading message
|
63
|
+
# add 'update-div-...' to set custom div to render data in!
|
64
|
+
|
65
|
+
select_actions = $("select.<%= JqajaxCore2::Config.core[:select_onchange_selector] %>.<%= JqajaxCore2::Config.core[:no_ajax_link_class] %>");
|
66
|
+
select_actions.change ->
|
67
|
+
#Daten zusammenladen
|
68
|
+
link_options = JqAjaxCore2.Helpers.linkOptionsFromElement($(this))
|
69
|
+
|
70
|
+
if link_options['confirm'] == true
|
71
|
+
return confirm link_options['confirm_message']
|
72
|
+
|
73
|
+
# Url erstellen
|
74
|
+
url = $(this).attr('<%= JqajaxCore2::Config.html_data[:target_url] %>').replace('<%= JqajaxCore2::Config.core[:url_placeholder] %>', this.value);
|
75
|
+
|
76
|
+
# Feuer frei
|
77
|
+
JqAjaxCore2.Core.remoteFunction(url, link_options['target_div'], link_options['load_message'], link_options['submit_data']);
|
78
|
+
|
79
|
+
select_actions.removeClass("<%= JqajaxCore2::Config.core[:no_ajax_link_class] %>")
|
80
|
+
|
81
|
+
# JavaScript Makeover of Rails 2.3 'remote_function' helper
|
82
|
+
remoteFunction: (path_url, div, load_message, submit) ->
|
83
|
+
if typeof submit != 'undefined' && submit != ''
|
84
|
+
submit = ("#"+submit).replace("##", "#")
|
85
|
+
request_data = $(submit + " :input").serialize()
|
86
|
+
request_type = "post"
|
87
|
+
else
|
88
|
+
request_type = "get"
|
89
|
+
request_data = ""
|
90
|
+
|
91
|
+
div = div || '<%= JqajaxCore2::Config.core[:ajax_content_container_id] %>'
|
92
|
+
$.ajax
|
93
|
+
success: (request) ->
|
94
|
+
$('#'+div).html(request)
|
95
|
+
JqAjaxCore2.Loading.hideLoading()
|
96
|
+
JqAjaxCore2.Initializer.initJqAc2()
|
97
|
+
|
98
|
+
beforeSend: (data) ->
|
99
|
+
if load_message != ''
|
100
|
+
JqAjaxCore2.Loading.addLoader(div, load_message)
|
101
|
+
else
|
102
|
+
JqAjaxCore2.Loading.showLoading()
|
103
|
+
|
104
|
+
url: path_url,
|
105
|
+
data: request_data,
|
106
|
+
type: request_type
|
107
|
+
|
108
|
+
|
109
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
window.JqAjaxCore2= {} if typeof(window.JqAjaxCore2) is 'undefined'
|
2
|
+
window.JqAjaxCore2.Helpers =
|
3
|
+
|
4
|
+
linkOptionsFromElement: (item) =>
|
5
|
+
# Item is passed as $() object
|
6
|
+
item = $(item)
|
7
|
+
link_options = {};
|
8
|
+
|
9
|
+
link_options['target_div'] = item.attr('<%= JqajaxCore2::Config.core[:update_div] %>') || '<%= JqajaxCore2::Config.core[:ajax_content_container_id] %>'
|
10
|
+
link_options['load_message'] = item.attr('<%= JqajaxCore2::Config.loading[:load_message] %>') || ''
|
11
|
+
link_options['submit_data'] = item.attr('<%= JqajaxCore2::Config.html_data[:submit_data] %>') || ''
|
12
|
+
link_options['callback'] = item.attr('<%= JqajaxCore2::Config.html_data[:callback] %>') || ''
|
13
|
+
link_options['append'] = item.attr('<%= JqajaxCore2::Config.html_data[:append] %>') ? true : false
|
14
|
+
|
15
|
+
# Checking for confirmation
|
16
|
+
link_options['confirm_message'] = (item.attr('<%= JqajaxCore2::Config.html_data[:confirm] %>') || '')
|
17
|
+
link_options['confirm'] = link_options['confirm_message'] != ''
|
18
|
+
|
19
|
+
return link_options
|
20
|
+
|
21
|
+
|
22
|
+
# Element ausblenden - verwendung als Callback nach löschen etc...
|
23
|
+
hideItem: (id) ->
|
24
|
+
$("#"+id).fadeOut(300);
|
25
|
+
|
26
|
+
assignTooltipDimensions: (el) ->
|
27
|
+
$(el).css({display: 'none', opacity: 0})
|
28
|
+
$(el).css({ height: $(el).height()+'px' })
|
29
|
+
|
30
|
+
|
31
|
+
# Element löschen - verwendung als Callback nach löschen etc...
|
32
|
+
removeItem: (id) ->
|
33
|
+
$("#"+id).remove();
|
34
|
+
|
35
|
+
getJsonData: (url, type) ->
|
36
|
+
type = 'get' if type == undefined
|
37
|
+
result = []
|
38
|
+
$.ajax({ url: url,async: false, type: type }).done (response) ->
|
39
|
+
result = response
|
40
|
+
|
41
|
+
return result
|
42
|
+
|
43
|
+
|
44
|
+
randomString: ->
|
45
|
+
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"
|
46
|
+
string_length = 8
|
47
|
+
randomstring = ''
|
48
|
+
rnum = 0
|
49
|
+
for i in [0..string_length]
|
50
|
+
rnum = Math.floor(Math.random() * chars.length)
|
51
|
+
randomstring += chars.substring(rnum,rnum+1)
|
52
|
+
return randomstring
|
@@ -0,0 +1,30 @@
|
|
1
|
+
window.JqAjaxCore2.Initializer =
|
2
|
+
initJqAc2: ->
|
3
|
+
JqAjaxCore2.Core.initDefaultLink()
|
4
|
+
JqAjaxCore2.Core.initSelectOnchange()
|
5
|
+
JqAjaxCore2.Widgets.initSlidedownBoxes()
|
6
|
+
JqAjaxCore2.Validation.initForms()
|
7
|
+
|
8
|
+
#== Initalize
|
9
|
+
# Regular JS
|
10
|
+
$(document).ready ->
|
11
|
+
JqAjaxCore2.Initializer.initJqAc2()
|
12
|
+
return
|
13
|
+
|
14
|
+
# Turbolinks JS
|
15
|
+
$(document).on 'page:load', ->
|
16
|
+
$.ready();
|
17
|
+
JqAjaxCore2.Initializer.initJqAc2()
|
18
|
+
return
|
19
|
+
|
20
|
+
#== Load info between page reloads
|
21
|
+
<% if JqajaxCore2::Config.overlay[:enable_on_page_unload] %>
|
22
|
+
# Regular JS
|
23
|
+
$(document).on 'page:before-change', ->
|
24
|
+
JqAjaxCore2.Loading.showLoading()
|
25
|
+
return
|
26
|
+
# Turbolinks JS
|
27
|
+
$(window).bind "beforeunload", ->
|
28
|
+
JqAjaxCore2.Loading.showLoading()
|
29
|
+
return
|
30
|
+
<% end %>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
window.JqAjaxCore2= {} if typeof(window.JqAjaxCore2) is 'undefined'
|
2
|
+
window.JqAjaxCore2.Loading =
|
3
|
+
<% actionview = ActionView::Base.new %>
|
4
|
+
<% actionview.view_paths += [File.expand_path("../../../../views", __FILE__)] %>
|
5
|
+
|
6
|
+
showLoading: ->
|
7
|
+
<% if JqajaxCore2::Config.overlay[:enable] == true %>
|
8
|
+
@overlay().height($("body").height());
|
9
|
+
@overlay().width($("body").width());
|
10
|
+
|
11
|
+
# Center the info container
|
12
|
+
info = $(@overlay().children()[0])
|
13
|
+
|
14
|
+
w_info = info.width()
|
15
|
+
h_info = info.height()
|
16
|
+
w_window = $(window).width()
|
17
|
+
h_window = $(window).height()
|
18
|
+
|
19
|
+
info.css({left: (w_window*0.5)-(w_info*0.5)+"px" })
|
20
|
+
info.css({top: (h_window*0.5)-(h_info*0.5)+"px" })
|
21
|
+
|
22
|
+
@overlay().fadeIn(200);
|
23
|
+
<% end %>
|
24
|
+
|
25
|
+
hideLoading: ->
|
26
|
+
@overlay().fadeOut(200);
|
27
|
+
|
28
|
+
# get the overlay
|
29
|
+
overlay: ->
|
30
|
+
$("#<%= JqajaxCore2::Config.overlay[:div_id] %>")
|
31
|
+
|
32
|
+
# get The flash Area
|
33
|
+
flashArea: ->
|
34
|
+
$('#<%= JqajaxCore2::Config.loading[:flash_area_div] %>')
|
35
|
+
|
36
|
+
# Flash Notify Tools
|
37
|
+
flashNoticeDisplay: (text, mode) ->
|
38
|
+
|
39
|
+
mode = mode || 'ok'
|
40
|
+
text = text.replace(/\'/g, "\"")
|
41
|
+
html_notice = "<div class='jqac2-notify " + mode + "' style='display:none'>" + text + "</div>"
|
42
|
+
|
43
|
+
@flashArea().html(html_notice)
|
44
|
+
@flashArea().children().slideDown(500)
|
45
|
+
window.setTimeout('JqAjaxCore2.Loading.flashFadeOut()', <%= JqajaxCore2::Config.loading[:notify_display_duration] %>)
|
46
|
+
|
47
|
+
flashFadeOut: ->
|
48
|
+
@flashArea().children().fadeOut(500)
|
49
|
+
|
50
|
+
loadAjaxFlashNotice: ->
|
51
|
+
$.getJSON '/jqca2/jqac2_flash', (data) ->
|
52
|
+
$(data).each ->
|
53
|
+
@flashNoticeDisplay(this[1], this[0])
|
54
|
+
|
55
|
+
addLoader: (div, text) ->
|
56
|
+
$('#'+div).html(JqAjaxCore2.Loading.loaderHtml.replace('{TXT}', text))
|
57
|
+
|
58
|
+
loaderHtml: '<%= actionview.render "/jqajax/loader" %>'
|
@@ -0,0 +1,83 @@
|
|
1
|
+
window.JqAjaxCore2= {} if typeof(window.JqAjaxCore2) is 'undefined'
|
2
|
+
window.JqAjaxCore2.Modal =
|
3
|
+
|
4
|
+
# Init position of overlay Modal
|
5
|
+
initModal: (id) ->
|
6
|
+
overlay = $("#"+id)
|
7
|
+
overlay.hide()
|
8
|
+
|
9
|
+
dwidth = window.innerWidth
|
10
|
+
dheight = window.innerHeight
|
11
|
+
|
12
|
+
max_width = dwidth * <%= JqajaxCore2::Config.modal[:max_width_factor] %> + 'px'
|
13
|
+
max_height = dheight * <%= JqajaxCore2::Config.modal[:max_height_factor] %> + 'px'
|
14
|
+
|
15
|
+
overlay.css({'max-width': max_width, 'max-height': max_height})
|
16
|
+
|
17
|
+
owidth = overlay.width()
|
18
|
+
oheight = overlay.height()
|
19
|
+
|
20
|
+
dimensions =
|
21
|
+
left: ((dwidth * 0.5)-(owidth * 0.5))+'px'
|
22
|
+
top: ((dheight* 0.5)-(oheight* 0.5))+'px'
|
23
|
+
height: (oheight+25)+'px'
|
24
|
+
position: 'fixed'
|
25
|
+
|
26
|
+
overlay.css(dimensions);
|
27
|
+
overlay.fadeIn(500);
|
28
|
+
|
29
|
+
@initModelZindexSetter(id)
|
30
|
+
|
31
|
+
|
32
|
+
# Z-Index setzen
|
33
|
+
# Modal Z-Index Setter
|
34
|
+
# Bring modal to front if clicked
|
35
|
+
initModelZindexSetter: (id) ->
|
36
|
+
overlay = $("#"+id)
|
37
|
+
|
38
|
+
zindexes = []
|
39
|
+
|
40
|
+
$("div.<%= JqajaxCore2::Config.modal[:css_class] %>").each ->
|
41
|
+
zindexes.push(parseInt($(this).css('z-index')))
|
42
|
+
|
43
|
+
zindex_max = parseInt(zindexes.sort().reverse()[0])
|
44
|
+
|
45
|
+
# neues Overlay z-index setzen
|
46
|
+
overlay.css('z-index', zindex_max+1)
|
47
|
+
zindex_max = parseInt(overlay.css('z-index'))
|
48
|
+
|
49
|
+
$('#'+overlay .attr('id')).bind 'click', ->
|
50
|
+
$(this).css('z-index', zindex_max+1)
|
51
|
+
zindex_max = parseInt($(this).css('z-index'))
|
52
|
+
|
53
|
+
setModalDraggable: (id) ->
|
54
|
+
overlay = $("#"+id)
|
55
|
+
|
56
|
+
overlay.draggable
|
57
|
+
handle: ".<%= JqajaxCore2::Config.modal[:drag_handle] %>"
|
58
|
+
stop: (event, ui) ->
|
59
|
+
$(this).css("top",ui.position.top).css("left",ui.position.left)
|
60
|
+
|
61
|
+
hideModal: (id) ->
|
62
|
+
$("#"+id).slideUp()
|
63
|
+
|
64
|
+
|
65
|
+
#
|
66
|
+
#// Ajax Fullscreen Overlay
|
67
|
+
#setAjaxFullscreen = function(id){
|
68
|
+
#
|
69
|
+
# overlay = $("#"+id);
|
70
|
+
#
|
71
|
+
# dwidth = window.innerWidth
|
72
|
+
# dheight = window.innerHeight
|
73
|
+
#
|
74
|
+
# overlay.css({'width': (dwidth*0.9)+'px', 'height': (dheight*0.8)+'px'});
|
75
|
+
#
|
76
|
+
# //
|
77
|
+
# // overlay.animate({left: "0px", top: "49px", width: ($(document).width())+"px", height: (window.outerHeight-154)+"px"}, 200);
|
78
|
+
# // overlay.css("max-width", "100%");
|
79
|
+
#
|
80
|
+
#}
|
81
|
+
|
82
|
+
|
83
|
+
|
@@ -0,0 +1,244 @@
|
|
1
|
+
window.JqAjaxCore2= {} if typeof(window.JqAjaxCore2) is 'undefined'
|
2
|
+
window.JqAjaxCore2.Validation =
|
3
|
+
|
4
|
+
<% JqajaxCore2::Validations.settings.each do |name, settings| %>
|
5
|
+
<% if settings[:regexp] %>
|
6
|
+
validate<%= name.to_s.camelize %>: (el) ->
|
7
|
+
attr = $(el).val()
|
8
|
+
result = {}
|
9
|
+
result.status = JqAjaxCore2.Validation.validateFormat(attr, <%= settings[:regexp] %>, <%= settings[:empty] == false ? 'false' : 'true' %>)
|
10
|
+
result.message = JqAjaxCore2.ValidationErrorMessages.<%= name.to_s.camelize %>
|
11
|
+
return result
|
12
|
+
<% end %>
|
13
|
+
# Provide getter for data attributes defined in th
|
14
|
+
<% if settings[:data] %>
|
15
|
+
get<%= name.to_s.camelize %>Data: (el) ->
|
16
|
+
data = {}
|
17
|
+
<% settings[:data].each do |m, d| %>
|
18
|
+
data.<%= m.to_s.camelize %> = $(el).attr("<%= "data-#{JqajaxCore2::Validations.data_prefix}-#{m.to_s.dasherize}" %>") || "<%= d %>"
|
19
|
+
<% end %>
|
20
|
+
return data
|
21
|
+
<% end %>
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
|
25
|
+
# Define Custom methods for complex validation
|
26
|
+
validatePasswordSimple: (el) ->
|
27
|
+
value = $(el).val()
|
28
|
+
|
29
|
+
settings = JqAjaxCore2.Validation.getPasswordSimpleData(el)
|
30
|
+
result = {}
|
31
|
+
|
32
|
+
if value == ""
|
33
|
+
result.status = true
|
34
|
+
return result
|
35
|
+
else
|
36
|
+
result.status = false
|
37
|
+
result.message = JqAjaxCore2.Validation.renderErrorMessage(JqAjaxCore2.ValidationErrorMessages.PasswordSimple, settings)
|
38
|
+
|
39
|
+
if JqAjaxCore2.Validation.validateRequired(el) && value.length >= parseInt(settings.Length)
|
40
|
+
result.status = true
|
41
|
+
result.status = false if value.match(/[A-Za-z]/) == null
|
42
|
+
result.status = false if value.match(/[0-9]/) == null
|
43
|
+
return result
|
44
|
+
|
45
|
+
validateConfirmation: (el) ->
|
46
|
+
value = $(el).val()
|
47
|
+
|
48
|
+
settings = JqAjaxCore2.Validation.getConfirmationData(el)
|
49
|
+
result = {}
|
50
|
+
result.status = false
|
51
|
+
result.message = JqAjaxCore2.Validation.renderErrorMessage(JqAjaxCore2.ValidationErrorMessages.Confirmation, settings)
|
52
|
+
|
53
|
+
ref_value = $("#"+settings.ConfirmField).val()
|
54
|
+
|
55
|
+
if JqAjaxCore2.Validation.validateRequired(el) && value == ref_value
|
56
|
+
result.status = true
|
57
|
+
return result
|
58
|
+
|
59
|
+
validateExact: (el) ->
|
60
|
+
value = $(el).val()
|
61
|
+
|
62
|
+
settings = JqAjaxCore2.Validation.getExactData(el)
|
63
|
+
result = {}
|
64
|
+
result.status = false
|
65
|
+
result.message = JqAjaxCore2.Validation.renderErrorMessage(JqAjaxCore2.ValidationErrorMessages.Exact, settings)
|
66
|
+
|
67
|
+
if value == settings.Value
|
68
|
+
result.status = true
|
69
|
+
|
70
|
+
return result
|
71
|
+
|
72
|
+
validateLength: (el) ->
|
73
|
+
value = $(el).val()
|
74
|
+
|
75
|
+
settings = JqAjaxCore2.Validation.getLengthData(el)
|
76
|
+
result = {}
|
77
|
+
result.status = false
|
78
|
+
|
79
|
+
result.message = JqAjaxCore2.Validation.renderErrorMessage(JqAjaxCore2.ValidationErrorMessages.Length, settings)
|
80
|
+
length_settings = JqAjaxCore2.Validation.getLengthData(el).Length
|
81
|
+
|
82
|
+
length_range = length_settings.split("-")
|
83
|
+
|
84
|
+
if length_range.length == 1
|
85
|
+
if value.length == parseInt(length_range[0])
|
86
|
+
result.status = true
|
87
|
+
else
|
88
|
+
if value.length >= parseInt(length_range[0]) && value.length <= parseInt(length_range[1])
|
89
|
+
result.status = true
|
90
|
+
|
91
|
+
return result
|
92
|
+
|
93
|
+
validateFromService: (el) ->
|
94
|
+
value = $(el).val()
|
95
|
+
|
96
|
+
json_url = JqAjaxCore2.Validation.getFromServiceData(el).Url
|
97
|
+
result = {}
|
98
|
+
values_hash = {value: value}
|
99
|
+
|
100
|
+
# loading additional fields
|
101
|
+
additional_fields = JSON.parse(JqAjaxCore2.Validation.getFromServiceData(el).AdditionalValues)
|
102
|
+
|
103
|
+
for id, name of additional_fields
|
104
|
+
values_hash[name] = $("#"+id).val()
|
105
|
+
|
106
|
+
request = $.ajax
|
107
|
+
dataType: "json",
|
108
|
+
method: 'POST',
|
109
|
+
url: json_url,
|
110
|
+
data: values_hash,
|
111
|
+
async: false
|
112
|
+
success: (data) ->
|
113
|
+
result = data
|
114
|
+
|
115
|
+
console.log(request)
|
116
|
+
|
117
|
+
return result
|
118
|
+
|
119
|
+
renderErrorMessage: (text, vars) ->
|
120
|
+
t = text
|
121
|
+
for attr, value of vars
|
122
|
+
t = t.replace('['+attr+']', value)
|
123
|
+
return t
|
124
|
+
|
125
|
+
# Helper method for string validation with given regular expression
|
126
|
+
validateFormat: (string, regexp, empty) ->
|
127
|
+
if (!string || 0 == string.length) && empty == true
|
128
|
+
return true
|
129
|
+
else if string.match(regexp) == null
|
130
|
+
return false
|
131
|
+
else
|
132
|
+
return true
|
133
|
+
|
134
|
+
# run the complete validation for the given form
|
135
|
+
validateForm: (form) ->
|
136
|
+
form = $(form)
|
137
|
+
|
138
|
+
# check if there are any fields with errors
|
139
|
+
formStatus = true
|
140
|
+
submitButton = $(form.find("input[type=submit]"))
|
141
|
+
|
142
|
+
$(".error-description").remove()
|
143
|
+
console.log
|
144
|
+
JqAjaxCore2.Validation.removeErrorFromInput(form.find(":input.error"))
|
145
|
+
|
146
|
+
$(form.find("input")).bind 'change keydown click', ->
|
147
|
+
submitButton.removeAttr("disabled")
|
148
|
+
submitButton.removeClass("disabled")
|
149
|
+
|
150
|
+
<% JqajaxCore2::Validations.settings.keys.each do |mode| %>
|
151
|
+
inputsForValidation = form.find(":input.<%= JqajaxCore2::Validations.settings[mode][:class] %>").not("[type='hidden']")
|
152
|
+
inputsForValidation.each ->
|
153
|
+
if !$(this).is(":disabled")
|
154
|
+
validationResult = JqAjaxCore2.Validation.validate<%= mode.to_s.camelize %>($(this))
|
155
|
+
if validationResult.status == false && !$(this).hasClass("<%= JqajaxCore2::Validations.skip_validation_class %>") && $(this).parents(".<%= JqajaxCore2::Validations.skip_validation_class %>").length == 0
|
156
|
+
formStatus = false;
|
157
|
+
JqAjaxCore2.Validation.addErrorToInput($(this), validationResult.message)
|
158
|
+
#else
|
159
|
+
# JqAjaxCore2.Validation.removeErrorFromInput($(this))
|
160
|
+
<% end %>
|
161
|
+
|
162
|
+
checkboxesForValidation = form.find("input.<%= JqajaxCore2::Validations.checkbox_validation_class %>")
|
163
|
+
checkboxesForValidation.each ->
|
164
|
+
# Find the label for the checkbox
|
165
|
+
checkbox_id = $(this).attr("id")
|
166
|
+
label = $("label[for="+checkbox_id+"]")
|
167
|
+
|
168
|
+
if !$(this).is(":checked") && !$(this).hasClass("<%= JqajaxCore2::Validations.skip_validation_class %>") && $(this).parents(".<%= JqajaxCore2::Validations.skip_validation_class %>").length == 0
|
169
|
+
formStatus = false
|
170
|
+
label.addClass("error")
|
171
|
+
alert("Bitte bestätigen Sie: " + label.text())
|
172
|
+
else
|
173
|
+
label.removeClass("error")
|
174
|
+
|
175
|
+
if formStatus == false || $(form).attr("data-has-error") == "true"
|
176
|
+
submitButton.attr("disabled", true)
|
177
|
+
submitButton.addClass("disabled")
|
178
|
+
##alert("Bei der Eingabe sind Fehler aufgetreten. Bitte prüfen Sie die markierten Felder.")
|
179
|
+
if $(".error-description")[0]
|
180
|
+
$('html, body').animate
|
181
|
+
scrollTop: $($(".error-description")[0]).offset().top-100, 250
|
182
|
+
|
183
|
+
return formStatus
|
184
|
+
|
185
|
+
|
186
|
+
# Bind validation to all forms that can be found
|
187
|
+
initForms: ->
|
188
|
+
|
189
|
+
main_selector = "[class*=<%= JqajaxCore2::Validations.prefix %>]"
|
190
|
+
|
191
|
+
for field in $("input"+main_selector+":first, :input"+main_selector+":first")
|
192
|
+
$("form").addClass("<%= JqajaxCore2::Validations.form_validation_class %>")
|
193
|
+
|
194
|
+
for field in $("input"+main_selector+", :input"+main_selector)
|
195
|
+
wrapper_class = "<%= JqajaxCore2::Validations.prefix %>-wrapper"
|
196
|
+
wrapper_class = wrapper_class + " " + $(field).attr("type") + "-wrapper"
|
197
|
+
if $(field).attr('data-wrapper-class')
|
198
|
+
wrapper_class = wrapper_class + ' ' + $(field).attr('data-wrapper-class')
|
199
|
+
|
200
|
+
wrapper = '<span class="'+ wrapper_class + '"></span>'
|
201
|
+
if field.type == 'checkbox' && $(field).siblings('label[for="' + field.id + '"]').length != 0
|
202
|
+
$('#' + field.id + ', label[for="' + field.id + '"]').wrapAll(wrapper)
|
203
|
+
else
|
204
|
+
$(field).wrap(wrapper)
|
205
|
+
<% if JqajaxCore2::Config.core[:show_validation_hints] == true %>
|
206
|
+
if $(field).attr('data-validation-messages')
|
207
|
+
messages_converted = $(field).attr('data-validation-messages').split(";").join("<br />")
|
208
|
+
$(field).before("<div data-<%= JqajaxCore2::Config.prefix %>-validation-hint class='<%= JqajaxCore2::Validations.validation_description_class %>'><span class='validation_tooltip'>"+ messages_converted + "</span></div>");
|
209
|
+
if $(field).is(':visible') == false
|
210
|
+
$(field).prev().hide()
|
211
|
+
JqAjaxCore2.Helpers.assignTooltipDimensions($(field).prev().find(".validation_tooltip"))
|
212
|
+
<% end %>
|
213
|
+
|
214
|
+
$("form.<%= JqajaxCore2::Validations.form_validation_class %>").submit ->
|
215
|
+
|
216
|
+
return JqAjaxCore2.Validation.validateForm(this)
|
217
|
+
|
218
|
+
# Helper methods
|
219
|
+
addErrorToInput: (el, message) ->
|
220
|
+
# remove old error msg if present
|
221
|
+
if $(el).prev().hasClass("<%= JqajaxCore2::Validations.error_description_class %>")
|
222
|
+
$(el).prev().remove()
|
223
|
+
|
224
|
+
$(el).addClass("error")
|
225
|
+
$(el).parent().addClass("error")
|
226
|
+
|
227
|
+
console.log $(el).parent()
|
228
|
+
|
229
|
+
# label form as error
|
230
|
+
$($(el).parents("form")[0]).attr("data-has-error", "true")
|
231
|
+
$(el).before("<div data-<%= JqajaxCore2::Config.prefix %>-error-indicator class='<%= JqajaxCore2::Validations.error_description_class %>'><span class='error_tooltip'>"+ message + "</span></div>");
|
232
|
+
JqAjaxCore2.Helpers.assignTooltipDimensions($(el).prev().find(".error_tooltip"))
|
233
|
+
|
234
|
+
removeErrorFromInput: (el) ->
|
235
|
+
$(el).removeClass("error")
|
236
|
+
$(el).parent().removeClass("error")
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
JqAjaxCore2.ValidationErrorMessages =
|
242
|
+
<% JqajaxCore2::Validations.settings.each do |name, settings| %>
|
243
|
+
<%= name.to_s.camelize %>: '<%= settings[:message] %>'
|
244
|
+
<% end %>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class JqAjaxCore2.CheckboxSlidedown
|
2
|
+
constructor: (el) ->
|
3
|
+
@$el = $(el)
|
4
|
+
|
5
|
+
@settings =
|
6
|
+
content_selector: @$el.data("jqac2-checkbox-slidedown-content")
|
7
|
+
trigger_selector: @$el.data("jqac2-checkbox-slidedown-trigger")
|
8
|
+
open: @$el.data("jqac2-checkbox-slidedown-open") || 'false'
|
9
|
+
|
10
|
+
@$content = @$el.find(@settings.content_selector)
|
11
|
+
@$trigger = @$el.find(@settings.trigger_selector)
|
12
|
+
|
13
|
+
@element_id = "s" + Math.random()+Math.random()
|
14
|
+
|
15
|
+
@$checkbox = $('<input id=" ' + @element_id + ' " class="jqac2-checkbox-slidedown-trigger" type="checkbox"></input>')
|
16
|
+
|
17
|
+
init: ->
|
18
|
+
# content should be hidden until checkbox was checked
|
19
|
+
@$content.hide()
|
20
|
+
|
21
|
+
# Add checkbox before the trigger element
|
22
|
+
@$trigger.before(@$checkbox)
|
23
|
+
@$checkbox.on 'change', @setContentVisibility
|
24
|
+
|
25
|
+
@setContentVisibility
|
26
|
+
|
27
|
+
|
28
|
+
setContentVisibility: =>
|
29
|
+
if @$checkbox.is(":checked")
|
30
|
+
@$content.show()
|
31
|
+
else
|
32
|
+
@$content.hide()
|
33
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
window.JqAjaxCore2= {} if typeof(window.JqAjaxCore2) is 'undefined'
|
2
|
+
window.JqAjaxCore2.Widgets =
|
3
|
+
initSlidedownBoxes: ->
|
4
|
+
boxes = $(".js-slide-down-box.plain")
|
5
|
+
|
6
|
+
boxes.each ->
|
7
|
+
ident = JqAjaxCore2.Helpers.randomString()
|
8
|
+
|
9
|
+
$(this).removeClass("plain")
|
10
|
+
$(this).addClass(ident)
|
11
|
+
btn = $($(this).children(".js-slidedown-button")[0])
|
12
|
+
cont = $($(this).children(".js-slidedown-content")[0])
|
13
|
+
|
14
|
+
btn.addClass(ident)
|
15
|
+
cont.addClass(ident)
|
16
|
+
|
17
|
+
btn = $(".js-slidedown-button."+ident)
|
18
|
+
|
19
|
+
btn.bind "click", ->
|
20
|
+
x = $(this).attr('class').split(' ')
|
21
|
+
btn_ident = x[x.length-1]
|
22
|
+
cont = $(".js-slidedown-content."+btn_ident)
|
23
|
+
|
24
|
+
box = $(".js-slide-down-box."+btn_ident)
|
25
|
+
|
26
|
+
session_id = box.attr("data-session-id")
|
27
|
+
$(box).toggleClass("open")
|