From 525d62c7c7dfca214d16343f3d8aeabfba2e87d5 Mon Sep 17 00:00:00 2001 From: radhika Date: Wed, 3 Dec 2014 18:16:08 -0500 Subject: [PATCH] 4525: restore add_form_selection_sources function --- .../app/assets/javascripts/selection.js.erb | 55 +++++++++++++++++++ .../app/helpers/application_helper.rb | 7 +++ 2 files changed, 62 insertions(+) diff --git a/apps/workbench/app/assets/javascripts/selection.js.erb b/apps/workbench/app/assets/javascripts/selection.js.erb index 34a5d7a838..b483c2cd47 100644 --- a/apps/workbench/app/assets/javascripts/selection.js.erb +++ b/apps/workbench/app/assets/javascripts/selection.js.erb @@ -14,6 +14,61 @@ jQuery(function($){ }); }); +add_form_selection_sources = null; +select_form_sources = null; + +(function() { + var form_selection_sources = {}; + add_form_selection_sources = function (src) { + for (var i = 0; i < src.length; i++) { + var t = form_selection_sources[src[i].type]; + if (!t) { + t = form_selection_sources[src[i].type] = {}; + } + if (!t[src[i].uuid]) { + t[src[i].uuid] = src[i]; + } + } + }; + + select_form_sources = function(type) { + var ret = []; + + if (get_selection_list) { + var lst = get_selection_list(); + if (lst.length > 0) { + var text = "― Selections ―"; + var span = document.createElement('span'); + span.innerHTML = text; + ret.push({text: span.innerHTML, value: "***invalid***"}); + + for (var i = 0; i < lst.length; i++) { + if (lst[i].type == type) { + var n = lst[i].name; + n = n.replace(/]*>/i, "["); + n = n.replace(/<\/span>/i, "]"); + ret.push({text: n, value: lst[i].uuid}) + } + } + } + } + + var text = "― Recent ―"; + var span = document.createElement('span'); + span.innerHTML = text; + ret.push({text: span.innerHTML, value: "***invalid***"}); + + var t = form_selection_sources[type]; + for (var key in t) { + if (t.hasOwnProperty(key)) { + var obj = t[key]; + ret.push({text: obj.name, value: obj.uuid}) + } + } + return ret; + }; +})(); + function dispatch_selection_action() { // Build a new "href" attribute for this link by starting with the // "data-href" attribute and appending ?foo[]=bar&foo[]=baz (or diff --git a/apps/workbench/app/helpers/application_helper.rb b/apps/workbench/app/helpers/application_helper.rb index ff7c80f724..c8c4ccc1a9 100644 --- a/apps/workbench/app/helpers/application_helper.rb +++ b/apps/workbench/app/helpers/application_helper.rb @@ -380,6 +380,13 @@ module ApplicationHelper }.merge(htmloptions) lt += raw("\n") lt -- 2.30.2