app/assets/javascripts/input-connected.coffee in ui_bibz-2.3.11 vs app/assets/javascripts/input-connected.coffee in ui_bibz-2.3.12

- old
+ new

@@ -54,40 +54,48 @@ self = this return this.each -> component = $(this) connect = component.data().connect - connect.target = connect.target || {} + + if ! connect.targets? + connect.target = connect.target || {} + connect.target.url = connect.target.url || settings.target.url + connect.target.data = connect.target.data || settings.target.data + connect.target.selector = connect.target.selector || settings.target.selector + + connect.targets = connect.targets || [] + connect.targets.push(connect.target) if connect.target? + return unless connect? - mode = connect.mode || settings.mode + connectMode = connect.mode || settings.mode events = connect.events || settings.events - target = - url: connect.target.url || settings.target.url - data: connect.target.data || settings.target.data - selector: connect.target.selector || settings.target.selector - componentTarget = $("#{ target.selector }") - component.on events, (e) -> e.preventDefault() values = component.val() name = component.attr('name') #name = if name? then name.replace(' ', '_').split('[')[0] else "id" name = if name? then name else "id" #name = if Array.isArray(values) then "#{ name }s" else name - if mode == "remote" - params = { "#{ name }": values } - $.ajax({ url: target.url, data: params }).done (data) -> - updateTargetComponent(data, componentTarget, component) + connect.targets.forEach (target) -> + componentTarget = $("#{ target.selector }") - if mode == "local" - data = target.data || settings.target.data - data = data.filter (value) -> - values = [].concat.apply([], [values]) # flatten - return values.includes(String(value.connect_option_id)) + mode = target.mode || connectMode - updateTargetComponent(data, componentTarget, component) + if mode == "remote" + params = { "#{ name }": values } + $.ajax({ url: target.url, data: params }).done (data) -> + updateTargetComponent(data, componentTarget, component) + + if mode == "local" + data = target.data || settings.target.data + data = data.filter (value) -> + values = [].concat.apply([], [values]) # flatten + return values.includes(String(value.connect_option_id)) + + updateTargetComponent(data, componentTarget, component) )(jQuery)