diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index 0a6307c18..4f4d0edc0 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -6,7 +6,8 @@ //container=true is the area where the view will be loaded //load = true is used to load the submenu item by default //response-type = "json"|"script"|"xml|html" default is json -//autocomplete-list = "listname" an array from which autocomplete will be attached to its respective input or textarea +//autocomplete = "url" this will automatically convert textarea or input to autocomplete. +//autocomplete-format = "--:[text,email]" first one is seperator which will be put on between every field. //ajax-remote="get/delete/post/false" this will automatically bind the with remote ajax call. By default if the resposne is html, it ll be inserted in container=true, false option will not make any calls and also stop page refresh // content-holder = "jquery dom", the returned html of server will be put inside the dom mentioned in content-holder of a tag. this can be used in a tags as attributes //confirm-message ="Some message", this will prompt user with a confirm box and show the message before ajax call is made. @@ -342,38 +343,13 @@ var orbitDesktop = function(dom){ return split( term ).pop(); } - var autocompleteListName = null; - $("body").on("keydown","*[autocomplete-list]", function( event ) { - autocompleteListName = $(this).attr("autocomplete-list"); - if ( event.keyCode === $.ui.keyCode.TAB && - $( this ).data( "autocomplete" ).menu.active ) { - event.preventDefault(); - } - $(this).autocomplete({ - minLength: 0, - source: function( request, response ) { - // delegate back to autocomplete, but extract the last term - response( $.ui.autocomplete.filter( - window.o[o.data_method][autocompleteListName], extractLast( request.term ) ) ); - }, - focus: function() { - // prevent value inserted on focus - return false; - }, - select: function( event, ui ) { - var terms = split( this.value ); - // remove the current input - terms.pop(); - // add the selected item - terms.push( ui.item.value ); - // add placeholder to get the comma-and-space at the end - terms.push( "" ); - this.value = terms.join( ", " ); - return false; - } - }); - }); + // $("body").on("keydown","*[autocomplete]", function( event ) { + // var autocompleteList = $(this).attr("autocomplete-list"); + // console.log($(this)); + + // }); + // }; this.layout_data = function(h){ @@ -466,6 +442,8 @@ var orbitDesktop = function(dom){ } } o.tinyscrollbar_ext(settings,tsettings); + o.autocomplete(); + o.use_select2(); } this.paging = true; this.pagination = function(link,variable,page_no){ @@ -1611,6 +1589,53 @@ var orbitDesktop = function(dom){ // minimumInputLength: -1 }); } + + this.autocomplete = function(){ + $("*[autocomplete]").each(function(){ + $e = $(this); + var options = { + multiple:true, + minimumInputLength: -1, + width: "off", + ajax: { + url: $e.attr("autocomplete"), + dataType: 'json', + quietMillis: 100, + tokenSeparators: [","], + data: function (search, page) { + return {q: search}; + }, + results: function (data, page) { + return {results: data.results}; + } + } + } + var format = $e.attr("autocomplete-format"); + if(format){ + format = format.split(":"); + var seperator = format[0]; + var fields = format[1]; + fields = fields.replace("]",""); + fields = fields.replace("[",""); + fields = fields.split(","); + options.formatResult = function(data){ + var markup = ""; + var x = 0; + for(i in fields){ + if(x > 0)markup += " " + seperator + " "; + x++; + if(data[fields[i]]) + markup += data[fields[i]]; + else + markup += fields[i] + " not available"; + } + return markup; + } + } + $e.select2(options); + }) + } + this.appname_substr = function(target,length){ var $target = $(target), length = (length && typeof length == 'number') ? length : 12, diff --git a/vendor/built_in_modules/personal_conference/app/assets/javascripts/personal_conference/desktop/conference_pages.js b/vendor/built_in_modules/personal_conference/app/assets/javascripts/personal_conference/desktop/conference_pages.js index 83960d9ae..d9f98c606 100644 --- a/vendor/built_in_modules/personal_conference/app/assets/javascripts/personal_conference/desktop/conference_pages.js +++ b/vendor/built_in_modules/personal_conference/app/assets/javascripts/personal_conference/desktop/conference_pages.js @@ -62,51 +62,11 @@ orbitDesktop.prototype.initializeConferencePapers = function(target,url,cache){ }); } - var tokesplits = function(){ - $("#writing_conference_author_tokens").select2({ - multiple: true, - minimumInputLength: 1, - width: "300px;", - formatResult: function movieFormatResult(coAuthor) { - var markup = ""; - if (coAuthor.text !== undefined && coAuthor.email !== undefined) { - if(!coAuthor.email){ - markup += coAuthor.text + " -- none email"; - } else { - markup += coAuthor.text + " -- " + coAuthor.email; - } - }else if (coAuthor.email !== undefined) { - markup += coAuthor.text; - } - return markup; - }, - ajax: { - url: "/panel/personal_conference/desktop/conference_pages/new.json", - dataType: 'json', - quietMillis: 100, - tokenSeparators: [","], - data: function (search, page) { - return {q: search}; - }, - results: function (data, page) { - return {results: data.results}; - } - }, - }); - - $("#writing_conference_author_tokens").select2("container").find("ul.select2-choices").sortable({ - containment: 'parent', - start: function() { $("#writing_conference_author_tokens").select2("onSortStart"); }, - update: function() { $("#writing_conference_author_tokens").select2("onSortEnd"); } - }); - } - var preData = function(){ $("#writing_conference_author_tokens").select2('data', JSON.parse($("#writing_conference_author_tokens").attr('data-pre'))); } uploadFiles(); - tokesplits(); preData(); } @@ -130,53 +90,11 @@ orbitDesktop.prototype.initializeConferencePapers = function(target,url,cache){ }); } - console.log("hi"); var bindHandlers = function(){ o.simple_drop_down(); - } - - var tokesplits = function(){ - $("#writing_conference_author_tokens").select2({ - multiple: true, - minimumInputLength: 1, - width: "300px;", - formatResult: function movieFormatResult(coAuthor) { - var markup = ""; - if (coAuthor.text !== undefined && coAuthor.email !== undefined) { - if(!coAuthor.email){ - markup += coAuthor.text + " -- none email"; - } else { - markup += coAuthor.text + " -- " + coAuthor.email; - } - }else if (coAuthor.email !== undefined) { - markup += coAuthor.text; - } - return markup; - }, - ajax: { - url: "/panel/personal_conference/desktop/conference_pages/new.json", - dataType: 'json', - quietMillis: 100, - tokenSeparators: [","], - data: function (search, page) { - return {q: search}; - }, - results: function (data, page) { - return {results: data.results}; - } - }, - }); - - $("#writing_conference_author_tokens").select2("container").find("ul.select2-choices").sortable({ - containment: 'parent', - start: function() { $("#writing_conference_author_tokens").select2("onSortStart"); }, - update: function() { $("#writing_conference_author_tokens").select2("onSortEnd"); } - }); - } - + } bindHandlers(); uploadFiles(); - tokesplits(); } this.initializeConferencePapers.conference = function(){ // to open add pages in conference papers page diff --git a/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/desktop/conference_pages/_form.html.erb b/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/desktop/conference_pages/_form.html.erb index eadc9b490..e08201f7e 100644 --- a/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/desktop/conference_pages/_form.html.erb +++ b/vendor/built_in_modules/personal_conference/app/views/panel/personal_conference/desktop/conference_pages/_form.html.erb @@ -50,7 +50,8 @@ size: "20", placeholder: t("personal_conference.conference_title"), class: "s_grid_12 s_grid", - # "autocomplete-list" => "conference_title_autocomplete_list", + "autocomplete" => "/panel/personal_conference/desktop/conference_pages/new.json", + "autocomplete-format" => "--:[text,email]", value: (@writing_conference.conference_title_translations[locale.to_s] rescue nil) %> <% end %> @@ -109,6 +110,8 @@ class: "s_grid_12 s_grid", size: "20x2", placeholder: t("personal_conference.authors"), + "autocomplete" => "/panel/personal_conference/desktop/conference_pages/new.json", + "autocomplete-format" => "--:[text,email]", "data-pre" => generate_authors_name(@writing_conference.conference_co_author_ids) %> <%#= f.fields_for :authors_translations do |f| %> <%#= f.text_area locale, diff --git a/vendor/built_in_modules/personal_journal/app/assets/javascripts/personal_journal/desktop/journal_pages.js b/vendor/built_in_modules/personal_journal/app/assets/javascripts/personal_journal/desktop/journal_pages.js index f4b8c8069..68037a224 100644 --- a/vendor/built_in_modules/personal_journal/app/assets/javascripts/personal_journal/desktop/journal_pages.js +++ b/vendor/built_in_modules/personal_journal/app/assets/javascripts/personal_journal/desktop/journal_pages.js @@ -63,51 +63,11 @@ orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // }); } - var tokesplits = function(){ - $("#writing_journal_author_tokens").select2({ - multiple: true, - minimumInputLength: -1, - width: "off", - formatResult: function movieFormatResult(coAuthor) { - var markup = ""; - if (coAuthor.text !== undefined && coAuthor.email !== undefined) { - if(!coAuthor.email){ - markup += coAuthor.text + " -- none email"; - } else { - markup += coAuthor.text + " -- " + coAuthor.email; - } - }else if (coAuthor.email !== undefined) { - markup += coAuthor.text; - } - return markup; - }, - ajax: { - url: "/panel/personal_journal/desktop/journal_pages/new.json", - dataType: 'json', - quietMillis: 100, - tokenSeparators: [","], - data: function (search, page) { - return {q: search}; - }, - results: function (data, page) { - return {results: data.results}; - } - }, - }); - - $("#writing_journal_author_tokens").select2("container").find("ul.select2-choices").sortable({ - containment: 'parent', - start: function() { $("#writing_journal_author_tokens").select2("onSortStart"); }, - update: function() { $("#writing_journal_author_tokens").select2("onSortEnd"); } - }); - } - + var preData = function(){ $("#writing_journal_author_tokens").select2('data', JSON.parse($("#writing_journal_author_tokens").attr('data-pre'))); } - o.use_select2(); uploadFiles(); - tokesplits(); preData(); } @@ -134,51 +94,11 @@ orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // // console.log("hi"); var bindHandlers = function(){ o.simple_drop_down(); - o.use_select2(); + } - - var tokesplits = function(){ - $("#writing_journal_author_tokens").select2({ - multiple: true, - minimumInputLength: -1, - width: "off", - formatResult: function movieFormatResult(coAuthor, container, query, escapeMarkup) { - var markup = ""; - if (coAuthor.text !== undefined && coAuthor.email !== undefined) { - if(!coAuthor.email){ - markup += coAuthor.text + " -- none email"; - } else { - markup += coAuthor.text + " -- " + coAuthor.email; - } - }else if (coAuthor.email !== undefined) { - markup += coAuthor.text; - } - return markup; - }, - ajax: { - url: "/panel/personal_journal/desktop/journal_pages/new.json", - dataType: 'json', - quietMillis: 100, - tokenSeparators: [","], - data: function (search, page) { - return {q: search}; - }, - results: function (data, page) { - return {results: data.results}; - } - }, - }); - - $("#writing_journal_author_tokens").select2("container").find("ul.select2-choices").sortable({ - containment: 'parent', - start: function() { $("#writing_journal_author_tokens").select2("onSortStart"); }, - update: function() { $("#writing_journal_author_tokens").select2("onSortEnd"); } - }); - } - bindHandlers(); uploadFiles(); - tokesplits(); + } this.initializeJournalPapers.journal = function(){ // to open add pages in journal papers page diff --git a/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/_form.html.erb b/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/_form.html.erb index 1b6f929fd..2f3b3beaa 100644 --- a/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/_form.html.erb +++ b/vendor/built_in_modules/personal_journal/app/views/panel/personal_journal/desktop/journal_pages/_form.html.erb @@ -51,7 +51,8 @@ size: "20", placeholder: t("personal_journal.journal_title"), class: "s_grid_12 s_grid", - "autocomplete-list" => "journal_title_autocomplete_list", + "autocomplete" => "/panel/personal_journal/desktop/journal_pages/new.json", + "autocomplete-format" => "--:[text,email]", value: (@writing_journal.journal_title_translations[locale.to_s] rescue nil) %> <% end %> @@ -104,6 +105,8 @@ class: "s_grid_12 s_grid", size: "20x2", placeholder: t("personal_journal.authors"), + "autocomplete" => "/panel/personal_journal/desktop/journal_pages/new.json", + "autocomplete-format" => "--:[text,email]", "data-pre" => generate_authors_name(@writing_journal.journal_co_author_ids) %> <%#= f.fields_for :authors_translations do |f| %> <%#= f.text_area locale, @@ -232,25 +235,6 @@ --> - - - - -