small fix
This commit is contained in:
parent
21e2c0819b
commit
9731fa83f3
|
@ -52,20 +52,22 @@ class Admin::UniversalTablesController < OrbitAdminController
|
||||||
table = UTable.where(:uid => params["uid"]).first rescue nil
|
table = UTable.where(:uid => params["uid"]).first rescue nil
|
||||||
data = []
|
data = []
|
||||||
if !table.nil?
|
if !table.nil?
|
||||||
enteries = search_data(table, 50)
|
if params[:q].present?
|
||||||
ma = ModuleApp.find_by_key("universal_table")
|
enteries = search_data(table, 50)
|
||||||
enteries.each do |entry|
|
ma = ModuleApp.find_by_key("universal_table")
|
||||||
if params["links"].present?
|
enteries.each do |entry|
|
||||||
data << {
|
if params["links"].present?
|
||||||
"id" => entry.id.to_s,
|
data << {
|
||||||
"text" => entry.column_entries.first.text,
|
"id" => entry.id.to_s,
|
||||||
"link" => OrbitHelper.cal_url_to_show(ma,entry)
|
"text" => entry.column_entries.first.text,
|
||||||
}
|
"link" => OrbitHelper.cal_url_to_show(ma,entry)
|
||||||
else
|
}
|
||||||
data << {
|
else
|
||||||
"id" => entry.id.to_s,
|
data << {
|
||||||
"text" => entry.column_entries.first.text
|
"id" => entry.id.to_s,
|
||||||
}
|
"text" => entry.column_entries.first.text
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -69,34 +69,38 @@ $("#universal_table_tags").select2({
|
||||||
return { id: term, text: "#" + term.trim().toLowerCase() };
|
return { id: term, text: "#" + term.trim().toLowerCase() };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("#universal_table_tags").val(<%= raw(@entry.table_tags.collect { |tag| tag.id.to_s }) %>).trigger("change");
|
$("#universal_table_tags").val(<%= raw(@entry.table_tags. collect { |tag| tag.id.to_s }) %>).trigger("change");
|
||||||
|
|
||||||
var select2Options = {
|
const preselectedData = $("#table_entry_related_entries").data('value');
|
||||||
|
preselectedData.forEach(function(item) {
|
||||||
|
var option = new Option(item.text, item.id, true, true);
|
||||||
|
$('#table_entry_related_entries').append(option);
|
||||||
|
});
|
||||||
|
var select2Options = {
|
||||||
maximumSelectionSize: 10,
|
maximumSelectionSize: 10,
|
||||||
minimumResultsForSearch: Infinity,
|
minimumResultsForSearch: Infinity,
|
||||||
multiple: true,
|
multiple: true,
|
||||||
minimumInputLength: 2,
|
minimumInputLength: 2,
|
||||||
|
width: '100%',
|
||||||
placeholder: "<%= t("universal_table.search_entries") %>",
|
placeholder: "<%= t("universal_table.search_entries") %>",
|
||||||
ajax: {
|
ajax: {
|
||||||
type: 'get',
|
type: 'get',
|
||||||
url: "/admin/universal_tables/get_entries?uid=<%= @entry.u_table.uid %>",
|
url: "/admin/universal_tables/get_entries?uid=<%= @entry.u_table.uid %>",
|
||||||
allowClear: true,
|
allowClear: false,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
delay: 250,
|
delay: 250,
|
||||||
data: function (term) {
|
data: function (term) {
|
||||||
var query = {
|
return { q: term };
|
||||||
q: term
|
|
||||||
}
|
|
||||||
return query;
|
|
||||||
},
|
},
|
||||||
results: function(data, page) {
|
results: function(data, page) {
|
||||||
return {
|
return {
|
||||||
results: data
|
results: data
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
cache: true
|
cache: false
|
||||||
},
|
},
|
||||||
formatResult: function(i) {
|
formatResult: function(i) {
|
||||||
|
console.log(i)
|
||||||
return '<div>' + i.text + '</div>';
|
return '<div>' + i.text + '</div>';
|
||||||
}, // Formats results in drop down
|
}, // Formats results in drop down
|
||||||
formatSelection: function(i) {
|
formatSelection: function(i) {
|
||||||
|
@ -107,16 +111,5 @@ $("#universal_table_tags").select2({
|
||||||
} // we do not want to escape markup since we are displaying html in results
|
} // we do not want to escape markup since we are displaying html in results
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#table_entry_related_entries").select2(select2Options);
|
$("#table_entry_related_entries").select2(select2Options).trigger("change");
|
||||||
$('.select2').each(function () {
|
|
||||||
const data = $(this).data('value');
|
|
||||||
if (data) {
|
|
||||||
console.log($(this))
|
|
||||||
$(this).select2({
|
|
||||||
data: data,
|
|
||||||
multiple: true,
|
|
||||||
width: '100%'
|
|
||||||
}).val(data.map(i => i.id)).trigger('change');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue