mod/machines/lib/javascript/decko_slot.js.coffee in card-1.96.8 vs mod/machines/lib/javascript/decko_slot.js.coffee in card-1.97.0
- old
+ new
@@ -19,19 +19,25 @@
else
processed[cgiKey] = value
slotReady: (func)->
$('document').ready ->
- $('body').on 'slotReady', '.card-slot', (e) ->
+ $('body').on 'slotReady', '.card-slot', (e, slotter) ->
e.stopPropagation()
- func.call this, $(this)
+ if slotter?
+ func.call this, $(this), $(slotter)
+ else
+ func.call this, $(this)
-jQuery.fn.extend {
- slot: (status="success") ->
- @selectSlot("slot-#{status}-selector") ||
- @selectSlot("slot-selector") ||
- @closest(".card-slot")
+jQuery.fn.extend
+ slot: (status="success", mode="replace") ->
+ if mode == "modal"
+ @modalSlot()
+ else
+ @selectSlot("slot-#{status}-selector") ||
+ @selectSlot("slot-selector") ||
+ @closest(".card-slot")
selectSlot: (selectorName) ->
if selector = @data(selectorName)
slot = @findSlot selector
slot[0] && slot
@@ -52,66 +58,56 @@
if target_slot.length == 0
$(selector)
else
target_slot
- updateSlot: (url) ->
+ reloadSlot: (url) ->
$slot = $(this)
+ if $slot.length > 1
+ $slot.each ->
+ $(this).reloadSlot url
+ return
+
$slot = $slot.slot() unless $slot.isSlot
+ return unless $slot[0]
+
unless url?
- path = '~' + $slot.data('cardId') + "?view=" + $slot.data("slot")["view"]
- url = decko.slotPath path, $slot
+ url = $slot.slotUrl()
$slot.addClass 'slotter'
$slot.attr 'href', url
$slot.data "url", url
this[0].href = url # that's where handleRemote gets the url from
# .attr(href, url) only works for anchors
$slot.data "remote", true
$.rails.handleRemote($slot)
- setSlotContent: (val, _overlay=false) ->
- s = @slot()
+ slotUrl: ->
+ mark = if @data('cardId') then "~#{@data('cardId')}" else @data("cardName")
+ decko.slotPath "#{mark}?view=#{@data("slot")["view"]}"
+
+ setSlotContent: (val, mode, $slotter) ->
v = $(val)[0] && $(val) || val
+
if typeof(v) == "string"
- # needed to support unwrapped views
- s.replaceWith v
+ # Needed to support "TEXT: result" pattern in success (eg deleting nested cards)
+ @slot("success", mode).replaceWith v
else
- s.setSlotContentFromElement v
+ if v.hasClass("_overlay")
+ mode = "overlay"
+ else if v.hasClass("_modal")
+ mode = "modal"
+ @slot("success", mode).setSlotContentFromElement v, mode, $slotter
v
- setSlotContentFromElement: (el) ->
- s = $(this)
- if el.hasClass("_overlay")
- s.wrapAll('<div class="overlay-container">')
- s.before el
+ setSlotContentFromElement: (el, mode, $slotter) ->
+ if mode == "overlay"
+ @addOverlay(el, $slotter)
+ else if el.hasClass("_modal-slot") or mode == "modal"
+ el.showAsModal($slotter)
else
- s.replaceWith el
- el.triggerSlotReady()
+ @replaceWith el
- triggerSlotReady: () ->
- @trigger "slotReady"
- @find(".card-slot").trigger "slotReady"
+ el.triggerSlotReady($slotter)
- slotSuccess: (data, overlay) ->
- if data.redirect
- window.location=data.redirect
- else
- notice = @attr('notify-success')
- newslot = @setSlotContent data, overlay
-
- if newslot.jquery # sometimes response is plaintext
- decko.initializeEditors newslot
- if notice?
- newslot.notify notice, "success"
-
- slotError: (status, result) ->
- if status == 403 #permission denied
- @setSlotContent result
- else
- @notify result, "error"
- if status == 409 #edit conflict
- @slot().find('.current_revision_id').val(
- @slot().find('.new-current-revision-id').text()
- )
- else if status == 449
- @slot().find('g-recaptcha').reloadCaptcha()
-}
+ triggerSlotReady: (slotter) ->
+ @trigger "slotReady", slotter
+ @find(".card-slot").trigger "slotReady", slotter