From 7e91b86544d4d06e45c194b9b15b70db95762536 Mon Sep 17 00:00:00 2001 From: jwollert Date: Fri, 18 Oct 2013 12:13:27 +0200 Subject: [PATCH] remove timelines prefix from js autocompleter and move empty elements translations Conflicts: app/assets/javascripts/timelines_select_boxes.js config/locales/de.yml config/locales/en.yml --- ...ines_autocompleter.js => autocompleter.js} | 26 ++++++++++++------- .../javascripts/timelines_select_boxes.js | 21 +++++++++------ app/views/project_associations/new.html.erb | 2 +- app/views/reportings/edit.html.erb | 2 +- app/views/reportings/new.html.erb | 2 +- app/views/timelines/_form.html.erb | 2 +- app/views/timelines/_timeline.html.erb | 2 +- config/locales/de.yml | 6 ++--- config/locales/en.yml | 6 ++--- 9 files changed, 41 insertions(+), 28 deletions(-) rename app/assets/javascripts/{timelines_autocompleter.js => autocompleter.js} (91%) diff --git a/app/assets/javascripts/timelines_autocompleter.js b/app/assets/javascripts/autocompleter.js similarity index 91% rename from app/assets/javascripts/timelines_autocompleter.js rename to app/assets/javascripts/autocompleter.js index 60de5a7eab..acfb7c4618 100644 --- a/app/assets/javascripts/timelines_autocompleter.js +++ b/app/assets/javascripts/autocompleter.js @@ -33,7 +33,7 @@ (function ($, undefined) { "use strict"; - function TimelinesAutocompleter (object, args) { + function Autocompleter (object, args) { this.element = object; this.opts = null; this.fakeInput = null; @@ -42,10 +42,10 @@ this.initSelect2(); } - TimelinesAutocompleter.prototype = $.extend(TimelinesAutocompleter.prototype, { + Autocompleter.prototype = $.extend(Autocompleter.prototype, { initOptions: function (args) { var self = this; - this.opts = $.extend(true, {}, $.fn.timelinesAutocomplete.defaults); + this.opts = $.extend(true, {}, $.fn.autocomplete.defaults); this.opts = $.extend(true, this.opts, args[0]); if (!(this.element.attr("data-ajaxURL") === "" || this.element.attr("data-ajaxURL") === null || this.element.attr("data-ajaxURL") === undefined)) { this.opts.ajax.url = this.element.attr("data-ajaxURL"); @@ -105,17 +105,17 @@ } }); - $.fn.timelinesAutocomplete = function () { + $.fn.autocomplete = function () { var args = Array.prototype.slice.call(arguments, 0), autocompleter; $(this).each(function () { - autocompleter = new TimelinesAutocompleter($(this), args); + autocompleter = new Autocompleter($(this), args); }); }; - $.fn.timelinesAutocomplete.defaults = { - multiple: true, + $.fn.autocomplete.defaults = { + multiple: false, data: {}, allowedAttributes: ["title", "placeholder", "id", "name"], minimumInputLength: 0, @@ -170,10 +170,18 @@ return item.name; }, initSelection: function (element, callback) { - var data = []; + var data, + multiple = $(element).attr("multiple"); + if (multiple !== null && multiple !== undefined && multiple) { + data = [] + }; if (!($(element).attr("data-selected") === "" || $(element).attr("data-selected") === null || $(element).attr("data-selected") === undefined)) { JSON.parse($(element).attr('data-selected')).each(function (elem) { - data.push({id: elem[1], name: elem[0]}); + if (multiple) { + data.push({id: elem[1], name: elem[0]}); + } else { + data = {id: elem[1], name: elem[0]}; + } }); } else if (element.is("input") && !(element.attr("data-values") === "" || element.attr("data-values") === null || element.attr("data-values") === undefined)) { var possible = JSON.parse(element.attr('data-values')); diff --git a/app/assets/javascripts/timelines_select_boxes.js b/app/assets/javascripts/timelines_select_boxes.js index 08f86c7662..d7edf115b6 100644 --- a/app/assets/javascripts/timelines_select_boxes.js +++ b/app/assets/javascripts/timelines_select_boxes.js @@ -55,7 +55,9 @@ jQuery(document).ready(function($) { $("#timeline_options_planning_element_responsibles"), $("#timeline_options_grouping_two_selection") ].each(function (item) { - $(item).timelinesAutocomplete({ ajax: {null_element: {id: -1, name: I18n.t("js.timelines.filter.noneElement")}} }); + $(item).autocomplete({ multiple: true, + ajax: {null_element: {id: -1, name: I18n.t("js.filter.noneElement")}} + }); }); [ @@ -63,11 +65,12 @@ jQuery(document).ready(function($) { $("#timeline_options_planning_element_time_types"), $("#timeline_options_planning_element_status") ].each(function (item) { - $(item).timelinesAutocomplete({}); + $(item).autocomplete({}); }); var item = $("#timeline_options_columns_"); - item.timelinesAutocomplete({ + item.autocomplete({ + multiple: true, sortable: true }); @@ -76,7 +79,7 @@ jQuery(document).ready(function($) { $("#project_association_select_project_b_id") ].each(function (item) { // Stuff borrowed from Core application.js Project Jump Box - $(item).timelinesAutocomplete({ + $(item).autocomplete({ multiple: false, formatSelection: function (item) { return item.name || item.project.name; @@ -94,7 +97,8 @@ jQuery(document).ready(function($) { $("#timeline_options_grouping_one_selection") ].each(function (item) { // Stuff borrowed from Core application.js Project Jump Box - $(item).timelinesAutocomplete({ + $(item).autocomplete({ + multiple: true, sortable: true, formatSelection: function (item) { return item.name || item.project.name; @@ -104,7 +108,7 @@ jQuery(document).ready(function($) { query : OpenProject.Helpers.Search.projectQueryWithHierarchy( jQuery.proxy(openProject, 'fetchProjects'), 20), - ajax: {null_element: {id: -1, name: I18n.t("js.timelines.filter.noneElement")}} + ajax: {null_element: {id: -1, name: I18n.t("js.filter.noneElement")}} }); }); @@ -112,7 +116,8 @@ jQuery(document).ready(function($) { $("#timeline_options_parents") ].each(function (item) { // Stuff borrowed from Core application.js Project Jump Box - $(item).timelinesAutocomplete({ + $(item).autocomplete({ + multiple: true, formatSelection: function (item) { return item.name || item.project.name; }, @@ -121,7 +126,7 @@ jQuery(document).ready(function($) { query : OpenProject.Helpers.Search.projectQueryWithHierarchy( jQuery.proxy(openProject, 'fetchProjects'), 20), - ajax: {null_element: {id: -1, name: I18n.t("js.timelines.filter.noneElement")}} + ajax: {null_element: {id: -1, name: I18n.t("js.filter.noneElement")}} }); }); diff --git a/app/views/project_associations/new.html.erb b/app/views/project_associations/new.html.erb index 9455b62873..fa43f13862 100644 --- a/app/views/project_associations/new.html.erb +++ b/app/views/project_associations/new.html.erb @@ -33,7 +33,7 @@ See doc/COPYRIGHT.rdoc for more details. For lack of a requiring policy (such as requirejs), just include the autocompleter on its own. %> - <%= javascript_include_tag "timelines_autocompleter.js" %> + <%= javascript_include_tag "autocompleter.js" %> <%= javascript_include_tag "timelines_select_boxes.js" %> <% end %> diff --git a/app/views/reportings/edit.html.erb b/app/views/reportings/edit.html.erb index d6fd7b0e78..c7887b6a8c 100644 --- a/app/views/reportings/edit.html.erb +++ b/app/views/reportings/edit.html.erb @@ -33,7 +33,7 @@ See doc/COPYRIGHT.rdoc for more details. For lack of a requiring policy (such as requirejs), just include the autocompleter on its own. %> - <%= javascript_include_tag "timelines_autocompleter.js" %> + <%= javascript_include_tag "autocompleter.js" %> <%= javascript_include_tag "timelines_select_boxes.js" %> <% end %> diff --git a/app/views/reportings/new.html.erb b/app/views/reportings/new.html.erb index 06da8e41eb..ce81983514 100644 --- a/app/views/reportings/new.html.erb +++ b/app/views/reportings/new.html.erb @@ -33,7 +33,7 @@ See doc/COPYRIGHT.rdoc for more details. For lack of a requiring policy (such as requirejs), just include the autocompleter on its own. %> - <%= javascript_include_tag "timelines_autocompleter.js" %> + <%= javascript_include_tag "autocompleter.js" %> <%= javascript_include_tag "timelines_select_boxes.js" %> <% end %> diff --git a/app/views/timelines/_form.html.erb b/app/views/timelines/_form.html.erb index 49d46f12e9..105843bfaa 100644 --- a/app/views/timelines/_form.html.erb +++ b/app/views/timelines/_form.html.erb @@ -33,7 +33,7 @@ See doc/COPYRIGHT.rdoc for more details. For lack of a requiring policy (such as requirejs), just include the autocompleter on its own. %> - <%= javascript_include_tag "timelines_autocompleter.js" %> + <%= javascript_include_tag "autocompleter.js" %> <%= javascript_include_tag "timelines_select_boxes.js" %> <% end %> diff --git a/app/views/timelines/_timeline.html.erb b/app/views/timelines/_timeline.html.erb index 9a2c6a9b2a..accca71230 100644 --- a/app/views/timelines/_timeline.html.erb +++ b/app/views/timelines/_timeline.html.erb @@ -35,7 +35,7 @@ See doc/COPYRIGHT.rdoc for more details. For lack of a requiring policy (such as requirejs), just include the autocompleter on its own. %> - <%= javascript_include_tag "timelines_autocompleter.js" %> + <%= javascript_include_tag "autocompleter.js" %> <%= javascript_include_tag "timelines_select_boxes.js" %> <% end %> diff --git a/config/locales/de.yml b/config/locales/de.yml index 7a63117f7b..8f18821b7f 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -556,9 +556,6 @@ de: create_planning_select_project: "Projekt:" due_date: "Abschlussdatum" error: "Ein Fehler ist aufgetreten." - filter: - noneElement: "(keines)" - noneSelection: "(keine)" name: "Name" project_status: "Projekt-Status" project_type: "Projekt-Typ" @@ -566,6 +563,9 @@ de: save: "Speichern" start_date: "Startdatum" really_close_dialog: "Dialog schließen und eingegebene Daten verwerfen?" + filter: + noneElement: "(keines)" + noneSelection: "(keine)" label_account: "Konto" label_activity: "Aktivität" diff --git a/config/locales/en.yml b/config/locales/en.yml index 7cd950c1b1..aed0d1a7a7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -559,9 +559,9 @@ en: error: "An error has occured." create_planning_select_project: "Project:" really_close_dialog: "Do you really want to close the dialog and loose the entered data?" - filter: - noneElement: "(none)" - noneSelection: "(none)" + filter: + noneElement: "(none)" + noneSelection: "(none)" label_account: "Account" label_activity: "Activity"