card-mod-script 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/db/migrate_core_cards/20200804112348_add_mod_script_assets_type.rb +30 -0
- data/file/mod_script_script_decko_machine_output/file.js +2710 -0
- data/file/mod_script_script_jquery_machine_output/file.js +12924 -0
- data/set/abstract/{script.rb → 00_script.rb} +7 -3
- data/set/abstract/01_asset_script.rb +25 -0
- data/set/abstract/01_java_script.rb +9 -0
- data/set/abstract/02_coffee_script.rb +25 -0
- data/set/abstract/03_asset_java_script.rb +4 -0
- data/set/abstract/04_asset_coffee_script.rb +4 -0
- data/set/abstract/script_asset_list.rb +32 -0
- data/set/all/head_javascript.rb +75 -0
- data/set/right/script.rb +18 -7
- data/set/type/coffee_script.rb +1 -23
- data/set/type/java_script.rb +1 -7
- data/set/type/local_script_folder_group.rb +2 -0
- data/set/type/local_script_manifest_group.rb +2 -0
- data/set/type/mod_script_assets.rb +21 -0
- metadata +38 -48
- data/lib/javascript/decko/autosave.js.coffee +0 -30
- data/lib/javascript/decko/bridge.js.coffee +0 -31
- data/lib/javascript/decko/card_menu.js.coffee +0 -26
- data/lib/javascript/decko/components.js.coffee +0 -51
- data/lib/javascript/decko/decko.js.coffee +0 -100
- data/lib/javascript/decko/doubleclick.js.coffee +0 -30
- data/lib/javascript/decko/editor.js.coffee +0 -55
- data/lib/javascript/decko/filter.js.coffee +0 -176
- data/lib/javascript/decko/filter_items.js.coffee +0 -128
- data/lib/javascript/decko/filter_links.js.coffee +0 -81
- data/lib/javascript/decko/follow.js.coffee +0 -22
- data/lib/javascript/decko/layout.js.coffee +0 -76
- data/lib/javascript/decko/link_editor.js.coffee +0 -61
- data/lib/javascript/decko/mod.js.coffee +0 -85
- data/lib/javascript/decko/modal.js.coffee +0 -113
- data/lib/javascript/decko/name_editor.js.coffee +0 -59
- data/lib/javascript/decko/navbox.js.coffee +0 -74
- data/lib/javascript/decko/nest_editor.js.coffee +0 -166
- data/lib/javascript/decko/nest_editor_name.js.coffee +0 -102
- data/lib/javascript/decko/nest_editor_options.js.coffee +0 -93
- data/lib/javascript/decko/nest_editor_rules.js.coffee +0 -3
- data/lib/javascript/decko/overlay.js.coffee +0 -57
- data/lib/javascript/decko/recaptcha.js.coffee +0 -19
- data/lib/javascript/decko/selectable_filtered_content.js.coffee +0 -12
- data/lib/javascript/decko/slot.js.coffee +0 -178
- data/lib/javascript/decko/slot_ready.js.coffee +0 -11
- data/lib/javascript/decko/slotter.js.coffee +0 -276
- data/lib/javascript/decko/upload.js.coffee +0 -57
- data/lib/javascript/jquery-ui.js +0 -10
- data/lib/javascript/jquery.autosize.js +0 -274
- data/lib/javascript/script_pointer_config.js.coffee +0 -80
- data/lib/javascript/script_pointer_list_editor.js.coffee +0 -67
- data/set/self/01_script_libraries.rb +0 -1
- data/set/self/script_decko.rb +0 -12
- data/set/self/script_editors.rb +0 -1
- data/set/self/script_jquery.rb +0 -10
- data/set/self/script_jquery_helper.rb +0 -14
- data/set/self/script_pointer_config.rb +0 -9
@@ -1,93 +0,0 @@
|
|
1
|
-
$(document).ready ->
|
2
|
-
$('body').on 'keyup', 'input._nest-option-value', () ->
|
3
|
-
nest.updatePreview()
|
4
|
-
|
5
|
-
$('body').on "select2:select", "._nest-option-name", () ->
|
6
|
-
nest.toggleOptionName($(this).closest("._options-select"), $(this).val(), true)
|
7
|
-
nest.updatePreview()
|
8
|
-
|
9
|
-
$('body').on "select2:selecting", "._nest-option-name", () ->
|
10
|
-
nest.toggleOptionName($(this).closest("._options-select"), $(this).val(), false)
|
11
|
-
|
12
|
-
$('body').on "select2:select", "._nest-option-name._new-row", () ->
|
13
|
-
$(this).closest(".input-group").find(".input-group-prepend").removeClass("d-none")
|
14
|
-
row = $(this).closest("._nest-option-row")
|
15
|
-
row.find("._nest-option-value").removeAttr("disabled")
|
16
|
-
template = row.parent().find("._nest-option-row._template")
|
17
|
-
$(this).removeClass("_new-row")
|
18
|
-
nest.addRow(template)
|
19
|
-
|
20
|
-
$('body').on "click", "._configure-items-button", () ->
|
21
|
-
nest.addItemsOptions($(this))
|
22
|
-
|
23
|
-
$('body').on 'click', 'button._nest-delete-option', () ->
|
24
|
-
nest.removeRow $(this).closest("._nest-option-row")
|
25
|
-
|
26
|
-
$.extend nest,
|
27
|
-
showTemplate: (elem) ->
|
28
|
-
elem.removeClass("_template") #.removeClass("_#{name}-template").addClass("_#{name}")
|
29
|
-
|
30
|
-
addRow: (template) ->
|
31
|
-
select_tag = template.find("select")
|
32
|
-
select_tag.select2("destroy")
|
33
|
-
select_tag.removeAttr("data-select2-id")
|
34
|
-
double = template.clone()
|
35
|
-
#double = template.cloneSelect2(true, true)
|
36
|
-
decko.initSelect2(select_tag)
|
37
|
-
nest.showTemplate template
|
38
|
-
template.after(double)
|
39
|
-
decko.initSelect2(double.find("select"))
|
40
|
-
|
41
|
-
removeRow: (row) ->
|
42
|
-
name = row.find("._nest-option-name").val()
|
43
|
-
nest.toggleOptionName(row.closest("._options-select"), name,false)
|
44
|
-
row.remove()
|
45
|
-
nest.updatePreview()
|
46
|
-
|
47
|
-
addItemsOptions: (button) ->
|
48
|
-
container = button.closest("._configure-items")
|
49
|
-
next = container.cloneSelect2(true)
|
50
|
-
title = button.text()
|
51
|
-
button.replaceWith($("<h6>#{title.substr(9)}<h6>"))
|
52
|
-
nest.showTemplate container.find("._options-select._template")
|
53
|
-
next.find("._configure-items-button").text(title.replace("items", "subitems"))
|
54
|
-
container.after(next)
|
55
|
-
nest.updatePreview()
|
56
|
-
|
57
|
-
options: () ->
|
58
|
-
options = []
|
59
|
-
for ele in $("._options-select:not(._template")
|
60
|
-
options.push nest.extractOptions($(ele))
|
61
|
-
|
62
|
-
level_options = options.map (opts) ->
|
63
|
-
nest.toNestSyntax(opts)
|
64
|
-
level_options.join "|"
|
65
|
-
|
66
|
-
# extract options for one item level
|
67
|
-
extractOptions: (ele) ->
|
68
|
-
options = {}
|
69
|
-
nest.addOption(options, $(row)) for row in ele.find("._nest-option-row:not(.template)")
|
70
|
-
options
|
71
|
-
|
72
|
-
addOption: (options, row) ->
|
73
|
-
val = row.find("._nest-option-value").val()
|
74
|
-
return unless val? && val.length > 0
|
75
|
-
|
76
|
-
name = row.find("._nest-option-name").val()
|
77
|
-
if options[name]?
|
78
|
-
options[name].push val
|
79
|
-
else
|
80
|
-
options[name] = [val]
|
81
|
-
|
82
|
-
toggleOptionName: (container, name, active) ->
|
83
|
-
return true if name == "show" || name == "hide"
|
84
|
-
for sel in container.find("._nest-option-name")
|
85
|
-
if $(sel).val() != name
|
86
|
-
$(sel).find("option[value=#{name}]").attr "disabled", active
|
87
|
-
# $(sel).find("option[value=#{val}]").removeAttr "disabled"
|
88
|
-
decko.initSelect2($(sel))
|
89
|
-
|
90
|
-
toNestSyntax: (opts) ->
|
91
|
-
str = []
|
92
|
-
str.push "#{name}: #{values.join ', '}" for name, values of opts
|
93
|
-
str.join "; "
|
@@ -1,57 +0,0 @@
|
|
1
|
-
jQuery.fn.extend
|
2
|
-
overlaySlot: ->
|
3
|
-
oslot = @closest(".card-slot._overlay")
|
4
|
-
return oslot if oslot[0]?
|
5
|
-
oslot = @closest(".overlay-container").find("._overlay")
|
6
|
-
oslot[0]? && $(oslot[0])
|
7
|
-
|
8
|
-
addOverlay: (overlay, $slotter) ->
|
9
|
-
if @parent().hasClass("overlay-container")
|
10
|
-
if $(overlay).hasClass("_stack-overlay")
|
11
|
-
@before overlay
|
12
|
-
else
|
13
|
-
$("._overlay-origin").removeClass("_overlay-origin")
|
14
|
-
@replaceOverlay(overlay)
|
15
|
-
else
|
16
|
-
#@find(".tinymce-textarea").each ->
|
17
|
-
# tinymce.remove("##{$(this).attr("id")}")
|
18
|
-
# #tinyMCE.execCommand('mceRemoveControl', false, $(this).attr("id"))
|
19
|
-
if @parent().hasClass("_overlay-container-placeholder")
|
20
|
-
@parent().addClass("overlay-container")
|
21
|
-
else
|
22
|
-
@wrapAll('<div class="overlay-container">')
|
23
|
-
@addClass("_bottomlay-slot")
|
24
|
-
@before overlay
|
25
|
-
|
26
|
-
$slotter.registerAsOrigin("overlay", overlay)
|
27
|
-
decko.contentLoaded(overlay, $slotter)
|
28
|
-
|
29
|
-
replaceOverlay: (overlay) ->
|
30
|
-
@overlaySlot().trigger "slotDestroy"
|
31
|
-
@overlaySlot().replaceWith overlay
|
32
|
-
$(".bridge-sidebar .tab-pane:not(.active) .bridge-pills > .nav-item > .nav-link.active").removeClass("active")
|
33
|
-
|
34
|
-
isInOverlay: ->
|
35
|
-
return @closest(".card-slot._overlay").length
|
36
|
-
|
37
|
-
removeOverlay: () ->
|
38
|
-
slot = @overlaySlot()
|
39
|
-
if slot
|
40
|
-
slot.removeOverlaySlot()
|
41
|
-
|
42
|
-
removeOverlaySlot: () ->
|
43
|
-
@trigger "slotDestroy"
|
44
|
-
if @siblings().length == 1
|
45
|
-
bottomlay = $(@siblings()[0])
|
46
|
-
if bottomlay.hasClass("_bottomlay-slot")
|
47
|
-
if bottomlay.parent().hasClass("_overlay-container-placeholder")
|
48
|
-
bottomlay.parent().removeClass("overlay-container")
|
49
|
-
else
|
50
|
-
bottomlay.unwrap()
|
51
|
-
bottomlay.removeClass("_bottomlay-slot").updateBridge(true, bottomlay)
|
52
|
-
|
53
|
-
#bottomlay.find(".tinymce-textarea").each ->
|
54
|
-
# tinymce.EditorManager.execCommand('mceAddControl',true, editor_id);
|
55
|
-
# decko.initTinyMCE($(this).attr("id"))
|
56
|
-
|
57
|
-
@remove()
|
@@ -1,19 +0,0 @@
|
|
1
|
-
jQuery.fn.extend {
|
2
|
-
updateRecaptchaToken: (event) ->
|
3
|
-
recaptcha = @find("input._recaptcha-token")
|
4
|
-
|
5
|
-
if !recaptcha[0]?
|
6
|
-
recaptcha.val "recaptcha-token-field-missing"
|
7
|
-
else if !grecaptcha?
|
8
|
-
recaptcha.val("grecaptcha-undefined")
|
9
|
-
else
|
10
|
-
$slotter = $(this)
|
11
|
-
event.stopPropagation() if event
|
12
|
-
grecaptcha.execute(recaptcha.data("site-key"), action: recaptcha.data("action"))
|
13
|
-
.then (token) ->
|
14
|
-
recaptcha.val(token)
|
15
|
-
recaptcha.addClass("_token-updated")
|
16
|
-
if event
|
17
|
-
$slotter.submit()
|
18
|
-
false
|
19
|
-
}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
$(window).ready ->
|
2
|
-
|
3
|
-
# TODO: generalize so this works with item views other than bar
|
4
|
-
$("body").on "click", "._selectable-filtered-content .bar-body", (e) ->
|
5
|
-
item = $(this)
|
6
|
-
name = item.slot().data("card-name")
|
7
|
-
container = item.closest("._selectable-filtered-content")
|
8
|
-
input = $(container.data("input-selector"))
|
9
|
-
input.val name
|
10
|
-
item.closest('.modal').modal('hide')
|
11
|
-
e.preventDefault()
|
12
|
-
e.stopPropagation()
|
@@ -1,178 +0,0 @@
|
|
1
|
-
$.extend decko,
|
2
|
-
# returns full path with slot parameters
|
3
|
-
slotPath: (path, slot)->
|
4
|
-
params = decko.slotData(slot)
|
5
|
-
decko.path(path) + ( (if path.match /\?/ then '&' else '?') + $.param(params) )
|
6
|
-
|
7
|
-
slotData: (slot) ->
|
8
|
-
xtra = {}
|
9
|
-
main = $('#main').children('.card-slot').data 'cardName'
|
10
|
-
xtra['main'] = main if main?
|
11
|
-
|
12
|
-
if slot
|
13
|
-
xtra['is_main'] = true if slot.isMain()
|
14
|
-
slotdata = slot.data 'slot'
|
15
|
-
if slotdata?
|
16
|
-
decko.slotParams slotdata, xtra, 'slot'
|
17
|
-
xtra['type'] = slotdata['type'] if slotdata['type']
|
18
|
-
xtra
|
19
|
-
|
20
|
-
slotEditView: (slot) ->
|
21
|
-
data = decko.slotData(slot)
|
22
|
-
switch data["slot[edit]"]
|
23
|
-
when "inline" then "edit_inline"
|
24
|
-
when "full" then "bridge"
|
25
|
-
else "edit"
|
26
|
-
|
27
|
-
slotEditLink: (slot) ->
|
28
|
-
edit_links =
|
29
|
-
slot.find(".edit-link").filter (i, el) ->
|
30
|
-
$(el).slot().data('slotId') == slot.data('slotId')
|
31
|
-
|
32
|
-
if edit_links[0] then $(edit_links[0]) else false
|
33
|
-
|
34
|
-
slotParams: (raw, processed, prefix)->
|
35
|
-
$.each raw, (key, value)->
|
36
|
-
cgiKey = prefix + '[' + snakeCase(key) + ']'
|
37
|
-
if key == 'items'
|
38
|
-
decko.slotParams value, processed, cgiKey
|
39
|
-
else
|
40
|
-
processed[cgiKey] = value
|
41
|
-
|
42
|
-
contentLoaded: (el, slotter)->
|
43
|
-
decko.initializeEditors(el)
|
44
|
-
notice = slotter.attr('notify-success')
|
45
|
-
if notice?
|
46
|
-
el.notify notice, "success"
|
47
|
-
el.triggerSlotReady(slotter)
|
48
|
-
|
49
|
-
slotReady: (func)->
|
50
|
-
$('document').ready ->
|
51
|
-
$('body').on 'slotReady', '.card-slot', (e, slotter) ->
|
52
|
-
e.stopPropagation()
|
53
|
-
if slotter?
|
54
|
-
func.call this, $(this), $(slotter)
|
55
|
-
else
|
56
|
-
func.call this, $(this)
|
57
|
-
|
58
|
-
slotDestroy: (func)->
|
59
|
-
$('document').ready ->
|
60
|
-
$('body').on 'slotDestroy', '.card-slot, ._modal-slot', (e) ->
|
61
|
-
e.stopPropagation()
|
62
|
-
func.call this, $(this)
|
63
|
-
|
64
|
-
jQuery.fn.extend
|
65
|
-
slot: (status="success", mode="replace") ->
|
66
|
-
if mode == "modal"
|
67
|
-
@modalSlot()
|
68
|
-
else
|
69
|
-
@selectSlot("slot-#{status}-selector") ||
|
70
|
-
@selectSlot("slot-selector") ||
|
71
|
-
@closest(".card-slot")
|
72
|
-
|
73
|
-
selectSlot: (selectorName) ->
|
74
|
-
if selector = @data(selectorName)
|
75
|
-
slot = @findSlot selector
|
76
|
-
slot && slot[0] && slot
|
77
|
-
|
78
|
-
isSlot: ->
|
79
|
-
$(this).hasClass "card-slot"
|
80
|
-
|
81
|
-
isMain: ->
|
82
|
-
@slot().parent('#main')[0]
|
83
|
-
|
84
|
-
isMainOrMainModal: ->
|
85
|
-
el = $(this)
|
86
|
-
el = el.findOriginSlot("modal") if el.closest(".modal")[0]
|
87
|
-
el.isMain()
|
88
|
-
|
89
|
-
findSlot: (selector) ->
|
90
|
-
if selector == "modal-origin"
|
91
|
-
@findOriginSlot("modal")
|
92
|
-
else if selector == "overlay-origin"
|
93
|
-
@findOriginSlot("overlay")
|
94
|
-
else
|
95
|
-
target_slot = @closest(selector)
|
96
|
-
parent_slot = @closest '.card-slot'
|
97
|
-
|
98
|
-
# if slot-selector doesn't apply to a child, search in all parent slots and finally in the body
|
99
|
-
while target_slot.length == 0 and parent_slot.length > 0
|
100
|
-
target_slot = $(parent_slot).find(selector)
|
101
|
-
parent_slot = $(parent_slot).parent().closest '.card-slot'
|
102
|
-
if target_slot.length == 0
|
103
|
-
$(selector)
|
104
|
-
else
|
105
|
-
target_slot
|
106
|
-
|
107
|
-
# type can be "modal" or "overlay"
|
108
|
-
findOriginSlot: (type) ->
|
109
|
-
overlaySlot = @closest("[data-#{type}-origin-slot-id]")
|
110
|
-
origin_slot_id = overlaySlot.data("#{type}-origin-slot-id")
|
111
|
-
origin_slot = $("[data-slot-id=#{origin_slot_id}]")
|
112
|
-
if origin_slot[0]?
|
113
|
-
origin_slot
|
114
|
-
else
|
115
|
-
console.log "couldn't find origin with slot id #{origin_slot_id}"
|
116
|
-
|
117
|
-
reloadSlot: (url) ->
|
118
|
-
$slot = $(this)
|
119
|
-
if $slot.length > 1
|
120
|
-
$slot.each ->
|
121
|
-
$(this).reloadSlot url
|
122
|
-
return
|
123
|
-
|
124
|
-
$slot = $slot.slot() unless $slot.isSlot
|
125
|
-
return unless $slot[0]
|
126
|
-
|
127
|
-
unless url?
|
128
|
-
url = $slot.slotUrl()
|
129
|
-
$slot.addClass 'slotter'
|
130
|
-
$slot.attr 'href', url
|
131
|
-
$slot.data "url", url
|
132
|
-
this[0].href = url # that's where handleRemote gets the url from
|
133
|
-
# .attr(href, url) only works for anchors
|
134
|
-
$slot.data "remote", true
|
135
|
-
$.rails.handleRemote($slot)
|
136
|
-
|
137
|
-
clearSlot: () ->
|
138
|
-
@triggerSlotDestroy()
|
139
|
-
@empty()
|
140
|
-
|
141
|
-
slotUrl: ->
|
142
|
-
decko.slotPath "#{this.slotMark()}?view=#{@data("slot")["view"]}"
|
143
|
-
|
144
|
-
slotMark: ->
|
145
|
-
if @data('cardId') then "~#{@data('cardId')}" else @data("cardName")
|
146
|
-
|
147
|
-
setSlotContent: (val, mode, $slotter) ->
|
148
|
-
v = $(val)[0] && $(val) || val
|
149
|
-
|
150
|
-
if typeof(v) == "string"
|
151
|
-
# Needed to support "TEXT: result" pattern in success (eg deleting nested cards)
|
152
|
-
@slot("success", mode).replaceWith v
|
153
|
-
else
|
154
|
-
if v.hasClass("_overlay")
|
155
|
-
mode = "overlay"
|
156
|
-
else if v.hasClass("_modal")
|
157
|
-
mode = "modal"
|
158
|
-
@slot("success", mode).setSlotContentFromElement v, mode, $slotter
|
159
|
-
v
|
160
|
-
|
161
|
-
setSlotContentFromElement: (el, mode, $slotter) ->
|
162
|
-
if mode == "overlay"
|
163
|
-
@addOverlay(el, $slotter)
|
164
|
-
else if el.hasClass("_modal-slot") or mode == "modal"
|
165
|
-
el.showAsModal($slotter)
|
166
|
-
else
|
167
|
-
slot_id = @data("slot-id")
|
168
|
-
el.attr("data-slot-id", slot_id) if slot_id
|
169
|
-
@triggerSlotDestroy()
|
170
|
-
@replaceWith el
|
171
|
-
decko.contentLoaded(el, $slotter)
|
172
|
-
|
173
|
-
triggerSlotReady: (slotter) ->
|
174
|
-
@trigger "slotReady", slotter if @isSlot()
|
175
|
-
@find(".card-slot").trigger "slotReady", slotter
|
176
|
-
|
177
|
-
triggerSlotDestroy: () ->
|
178
|
-
@trigger "slotDestroy"
|
@@ -1,276 +0,0 @@
|
|
1
|
-
# There are three places that can control what happens after an ajax request
|
2
|
-
# 1. the element that triggered the request (eg. a link or a button)
|
3
|
-
# 2. the closest ".slotter" element
|
4
|
-
# (if the trigger itself isn't a slotter,
|
5
|
-
# a common example is that a form is a slotter but the form buttons aren't)
|
6
|
-
# 3. the slot returned by the request
|
7
|
-
#
|
8
|
-
# A slot is an element marked with "card-slot" class, a slotter has a "slotter" class.
|
9
|
-
# By the default, the closest slot of the slotter is replaced with the new slot that the
|
10
|
-
# request returned. The behavior can be changed with css classes and data attributes.
|
11
|
-
#
|
12
|
-
# To 1. The trigger element has only a few options to override the slotter.
|
13
|
-
# classes:
|
14
|
-
# "_close-modal-on-success"
|
15
|
-
# "_close-overlay-on-success"
|
16
|
-
# "_update-origin"
|
17
|
-
#
|
18
|
-
# To 2. The slotter is the standard way to define what happens with request result
|
19
|
-
# data:
|
20
|
-
# slot-selector
|
21
|
-
# a css selector that defines which slot will be replaced.
|
22
|
-
# You can also use "modal-origin" and "overlay-origin" to refer to the origin slots.
|
23
|
-
# slot-success-selector/slot-error-selector
|
24
|
-
# the same as slot-selector but only used
|
25
|
-
# for success case or error case, respectively
|
26
|
-
# update-foreign-slot
|
27
|
-
# a css selector to specify an additional slot that will be
|
28
|
-
# updated after the request.
|
29
|
-
# update-foreign-slot-url
|
30
|
-
# a url to fetch the new content for the additional slot
|
31
|
-
# if not given the slot is updated with the same card and view that was used before
|
32
|
-
# update-origin
|
33
|
-
# if present then the slot from where the current modal or overlay slot was opened
|
34
|
-
# will be updated
|
35
|
-
# slotter-mode
|
36
|
-
# possible values are
|
37
|
-
# replace (default)
|
38
|
-
# replace the closest slot with new slot
|
39
|
-
# modal
|
40
|
-
# show new slot in modal; if there is already a modal then put it on top
|
41
|
-
# modal-replace
|
42
|
-
# replace existing modal
|
43
|
-
# overlay
|
44
|
-
# show new slot in overlay
|
45
|
-
# update-origin
|
46
|
-
# update closest slot of the slotter that opened the modal or overlay
|
47
|
-
# (assumes that the request was triggered from a modal or overlay)
|
48
|
-
# If you need the update-origin mode together with another mode then use
|
49
|
-
# data-update-origin="true".
|
50
|
-
# silent-success
|
51
|
-
# do nothing
|
52
|
-
#
|
53
|
-
# classes:
|
54
|
-
# _close-overlay
|
55
|
-
# _close-modal
|
56
|
-
#
|
57
|
-
# To 3. Similar as 1, the slot has only overlay and modal options.
|
58
|
-
# classes:
|
59
|
-
# _modal
|
60
|
-
# show slot in modal
|
61
|
-
# _overlay
|
62
|
-
# show slot in overlay
|
63
|
-
#
|
64
|
-
#
|
65
|
-
$(window).ready ->
|
66
|
-
$('body').on 'ajax:success', '.slotter', (event, data, c, d) ->
|
67
|
-
$(this).slotterSuccess event, data
|
68
|
-
|
69
|
-
$('body').on 'ajax:error', '.slotter', (event, xhr) ->
|
70
|
-
$(this).showErrorResponse xhr.status, xhr.responseText
|
71
|
-
|
72
|
-
$('body').on 'click', 'button.slotter', (event)->
|
73
|
-
return false if !$.rails.allowAction $(this)
|
74
|
-
$.rails.handleRemote $(this)
|
75
|
-
|
76
|
-
$('body').on 'click', '._clickable.slotter', (event)->
|
77
|
-
$(this)[0].href = $(this).attr("href") # that's where rails.handleRemote
|
78
|
-
# expects the url
|
79
|
-
$.rails.handleRemote $(this)
|
80
|
-
|
81
|
-
$('body').on 'click', '[data-dismiss="overlay"]', (event) ->
|
82
|
-
$(this).findSlot(".card-slot._overlay").removeOverlay()
|
83
|
-
|
84
|
-
$('body').on 'click', '._close-overlay-on-success', (event) ->
|
85
|
-
$(this).closeOnSuccess("overlay")
|
86
|
-
|
87
|
-
$('body').on 'click', '._close-modal-on-success', (event) ->
|
88
|
-
$(this).closeOnSuccess("modal")
|
89
|
-
|
90
|
-
$('body').on 'click', '._close-on-success', (event) ->
|
91
|
-
$(this).closeOnSuccess()
|
92
|
-
|
93
|
-
$('body').on 'click', '._update-origin', (event) ->
|
94
|
-
$(this).closest('.slotter').data("slotter-mode", "update-origin")
|
95
|
-
|
96
|
-
$('body').on 'submit', 'form.slotter', (event)->
|
97
|
-
form = $(this)
|
98
|
-
if form.data("main-success") and form.isMainOrMainModal()
|
99
|
-
form.mainSuccess()
|
100
|
-
if form.data('recaptcha') == 'on'
|
101
|
-
return form.handleRecaptchaBeforeSubmit(event)
|
102
|
-
|
103
|
-
$('body').on 'ajax:beforeSend', '.slotter', (event, xhr, opt)->
|
104
|
-
$(this).slotterBeforeSend opt
|
105
|
-
|
106
|
-
jQuery.fn.extend
|
107
|
-
mainSuccess: ()->
|
108
|
-
form = $(this)
|
109
|
-
$.each form.data("main-success"), (key, value)->
|
110
|
-
inputSelector = "[name=success\\[" + key + "\\]]"
|
111
|
-
input = form.find inputSelector
|
112
|
-
unless input[0]
|
113
|
-
input = $('<input type="hidden" name="success[' + key + ']"/>')
|
114
|
-
form.append input
|
115
|
-
input.val value
|
116
|
-
|
117
|
-
slotterSuccess: (event, data) ->
|
118
|
-
unless @hasClass("slotter")
|
119
|
-
console.log "warning: slotterSuccess called on non-slotter element #{this}"
|
120
|
-
return
|
121
|
-
|
122
|
-
return if event.slotSuccessful
|
123
|
-
|
124
|
-
if @data("reload")
|
125
|
-
window.location.reload(true)
|
126
|
-
|
127
|
-
if @data("update-modal-origin")
|
128
|
-
@updateModalOrigin()
|
129
|
-
|
130
|
-
if @data("update-origin")
|
131
|
-
@updateOrigin()
|
132
|
-
|
133
|
-
if @data('original-slotter-mode')
|
134
|
-
@attr 'data-slotter-mode', @data('original-slotter-mode')
|
135
|
-
|
136
|
-
mode = @data("slotter-mode")
|
137
|
-
@showSuccessResponse data, mode
|
138
|
-
|
139
|
-
if @hasClass "_close-overlay"
|
140
|
-
@removeOverlay()
|
141
|
-
if @hasClass "_close-modal"
|
142
|
-
@closest('.modal').modal('hide')
|
143
|
-
|
144
|
-
# should scroll to top after clicking on new page
|
145
|
-
if @hasClass "card-paging-link"
|
146
|
-
slot_top_pos = @slot().offset().top
|
147
|
-
$("body").scrollTop slot_top_pos
|
148
|
-
if @data("update-foreign-slot")
|
149
|
-
$slot = @findSlot @data("update-foreign-slot")
|
150
|
-
reload_url = @data("update-foreign-slot-url")
|
151
|
-
$slot.reloadSlot reload_url
|
152
|
-
|
153
|
-
event.slotSuccessful = true
|
154
|
-
|
155
|
-
showSuccessResponse: (data, mode) ->
|
156
|
-
if mode == "silent-success"
|
157
|
-
return
|
158
|
-
else if mode == "update-modal-origin"
|
159
|
-
@updateModalOrigin()
|
160
|
-
else if mode == "update-origin"
|
161
|
-
@updateOrigin()
|
162
|
-
else if data.redirect
|
163
|
-
window.location = data.redirect
|
164
|
-
else if data.reload
|
165
|
-
window.location.reload(true)
|
166
|
-
else
|
167
|
-
@updateSlot data, mode
|
168
|
-
|
169
|
-
showErrorResponse: (status, result) ->
|
170
|
-
if status == 403 #permission denied
|
171
|
-
$(result).showAsModal $(this)
|
172
|
-
else if status == 900
|
173
|
-
$(result).showAsModal $(this)
|
174
|
-
else
|
175
|
-
@notify result, "error"
|
176
|
-
|
177
|
-
if status == 409 #edit conflict
|
178
|
-
@slot().find('.current_revision_id').val(
|
179
|
-
@slot().find('.new-current-revision-id').text()
|
180
|
-
)
|
181
|
-
|
182
|
-
updateModalOrigin: () ->
|
183
|
-
if @overlaySlot()
|
184
|
-
overlayOrigin = @findOriginSlot("overlay")
|
185
|
-
overlayOrigin.updateOrigin()
|
186
|
-
else if @closest("#modal-container")[0]
|
187
|
-
@updateOrigin()
|
188
|
-
|
189
|
-
updateOrigin: () ->
|
190
|
-
type = if @overlaySlot()
|
191
|
-
"overlay"
|
192
|
-
else if @closest("#modal-container")[0]
|
193
|
-
"modal"
|
194
|
-
|
195
|
-
return unless type?
|
196
|
-
|
197
|
-
origin = @findOriginSlot(type)
|
198
|
-
if origin && origin[0]?
|
199
|
-
origin.reloadSlot()
|
200
|
-
|
201
|
-
registerAsOrigin: (type, slot) ->
|
202
|
-
if slot.hasClass("_modal-slot")
|
203
|
-
slot = slot.find(".modal-body .card-slot")
|
204
|
-
slot.attr("data-#{type}-origin-slot-id", @closest(".card-slot").data("slot-id"))
|
205
|
-
|
206
|
-
updateSlot: (data, mode) ->
|
207
|
-
mode ||= "replace"
|
208
|
-
@setSlotContent data, mode, $(this)
|
209
|
-
|
210
|
-
# close modal or overlay
|
211
|
-
closeOnSuccess: (type) ->
|
212
|
-
slotter = @closest('.slotter')
|
213
|
-
if !type?
|
214
|
-
type = if @isInOverlay() then "overlay" else "modal"
|
215
|
-
slotter.addClass "_close-#{type}"
|
216
|
-
|
217
|
-
slotterBeforeSend: (opt) ->
|
218
|
-
return if opt.skip_before_send
|
219
|
-
|
220
|
-
# avoiding duplication. could be better test?
|
221
|
-
unless (opt.url.match(/home_view/) or @data("slotter-mode") == "modal")
|
222
|
-
opt.url = decko.slotPath opt.url, @slot()
|
223
|
-
|
224
|
-
if @is('form')
|
225
|
-
if data = @data 'file-data'
|
226
|
-
# NOTE - this entire solution is temporary.
|
227
|
-
@uploadWithBlueimp(data, opt)
|
228
|
-
false
|
229
|
-
|
230
|
-
uploadWithBlueimp: (data, opt) ->
|
231
|
-
input = @find '.file-upload'
|
232
|
-
if input[1]
|
233
|
-
@notify(
|
234
|
-
"Decko does not yet support multiple files in a single form.",
|
235
|
-
"error"
|
236
|
-
)
|
237
|
-
return false
|
238
|
-
|
239
|
-
widget = input.data 'blueimpFileupload' #jQuery UI widget
|
240
|
-
|
241
|
-
# browsers that can't do ajax uploads use iframe
|
242
|
-
unless widget._isXHRUpload(widget.options)
|
243
|
-
# can't do normal redirects.
|
244
|
-
@find('[name=success]').val('_self')
|
245
|
-
# iframe response not passed back;
|
246
|
-
# all responses treated as success. boo
|
247
|
-
opt.url += '&simulate_xhr=true'
|
248
|
-
# iframe is not xhr request,
|
249
|
-
# so would otherwise get full response with layout
|
250
|
-
iframeUploadFilter = (data)-> data.find('body').html()
|
251
|
-
opt.dataFilter = iframeUploadFilter
|
252
|
-
# gets rid of default html and body tags
|
253
|
-
|
254
|
-
args = $.extend opt, (widget._getAJAXSettings data), url: opt.url
|
255
|
-
# combines settings from decko's slotter and jQuery UI's upload widget
|
256
|
-
args.skip_before_send = true #avoid looping through this method again
|
257
|
-
|
258
|
-
$.ajax( args )
|
259
|
-
|
260
|
-
handleRecaptchaBeforeSubmit: (event) ->
|
261
|
-
recaptcha = @find("input._recaptcha-token")
|
262
|
-
|
263
|
-
if !recaptcha[0]?
|
264
|
-
# monkey error (bad form)
|
265
|
-
recaptcha.val "recaptcha-token-field-missing"
|
266
|
-
else if recaptcha.hasClass "_token-updated"
|
267
|
-
# recaptcha token is fine - continue submitting
|
268
|
-
recaptcha.removeClass "_token-updated"
|
269
|
-
else if !grecaptcha?
|
270
|
-
# shark error (probably recaptcha keys of pre v3 version)
|
271
|
-
recaptcha.val "grecaptcha-undefined"
|
272
|
-
else
|
273
|
-
@updateRecaptchaToken(event)
|
274
|
-
# this stops the submit here
|
275
|
-
# and submits again when the token is ready
|
276
|
-
|