diff --git a/app/controllers/box_organizer_controller.rb b/app/controllers/box_organizer_controller.rb index 4add4bc..7735890 100644 --- a/app/controllers/box_organizer_controller.rb +++ b/app/controllers/box_organizer_controller.rb @@ -80,6 +80,18 @@ class BoxOrganizerController < ApplicationController render :action => 'edit', :layout => false end + def search_autocomplete + if request.xhr? and params[:query] + search = params[:query] + articles = @profile.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20) + path_list = articles.map { |content| content.path } + + render :json => path_list.to_json + else + redirect_to "/" + end + end + def save @block = boxes_holder.blocks.find(params[:id]) @block.update_attributes(params[:block]) diff --git a/app/helpers/token_helper.rb b/app/helpers/token_helper.rb index e33d77e..bb601b8 100644 --- a/app/helpers/token_helper.rb +++ b/app/helpers/token_helper.rb @@ -27,7 +27,7 @@ module TokenHelper hintText: #{options[:hint_text].to_json}, noResultsText: #{options[:no_results_text].to_json}, searchingText: #{options[:searching_text].to_json}, - searchDelay: #{options[:serach_delay].to_json}, + searchDelay: #{options[:search_delay].to_json}, preventDuplicates: #{options[:prevent_duplicates].to_json}, backspaceDeleteItem: #{options[:backspace_delete_item].to_json}, queryParam: #{name.to_json}, diff --git a/app/views/box_organizer/_link_list_block.rhtml b/app/views/box_organizer/_link_list_block.rhtml index 746446d..14c5b3d 100644 --- a/app/views/box_organizer/_link_list_block.rhtml +++ b/app/views/box_organizer/_link_list_block.rhtml @@ -1,32 +1,49 @@ +<%= javascript_include_tag "edit-link-list.js" %> + <%= _('Links') %> <%= link_to_function(_('New link'), nil, :class => 'button icon-add with-text') do |page| - page.insert_html :bottom, 'links', content_tag('tr', - content_tag('td', icon_selector('ok')) + - content_tag('td', text_field_tag('block[links][][name]', '', :maxlength => 20)) + - content_tag('td', text_field_tag('block[links][][address]', nil, :class => 'link-address'), :class => 'cel-address') + - content_tag('td', text_field_tag('block[links][][title]', '', :class => 'link-title')) + - content_tag('td', select_tag('block[links][][target]', options_for_select(LinkListBlock::TARGET_OPTIONS, '_self'))) + page.insert_html :bottom, 'dropable-link-list', content_tag('li', + content_tag('ul', + content_tag('li', icon_selector('ok')) + + content_tag('li', text_field_tag('block[links][][name]', '', :maxlength => 20)) + + content_tag('li', text_field_tag('block[links][][address]', nil, :class => 'link-address')) + + content_tag('li', select_tag('block[links][][target]', + options_for_select(LinkListBlock::TARGET_OPTIONS, '_self'))) + + content_tag('li', button_without_text("", _('Delete'), "#" , :class=>"icon-delete delete-link-list-row")), + :class=>"link-list-row new_link_row") ) + - javascript_tag("$('edit-link-list-block').scrollTop = $('edit-link-list-block').scrollHeight") + javascript_tag("new_link_action()") end %> diff --git a/public/images/drag-and-drop.png b/public/images/drag-and-drop.png new file mode 100644 index 0000000..600612c Binary files /dev/null and b/public/images/drag-and-drop.png differ diff --git a/public/javascripts/edit-link-list.js b/public/javascripts/edit-link-list.js new file mode 100644 index 0000000..18e69de --- /dev/null +++ b/public/javascripts/edit-link-list.js @@ -0,0 +1,48 @@ +function send_ajax(source_url) { + jQuery(".link-address").autocomplete({ + source : function(request, response){ + jQuery.ajax({ + type: "GET", + url: source_url, + data: {query: request.term}, + success: function(result){ + response(result); + }, + error: function(ajax, stat, errorThrown) { + console.log('Link not found : ' + errorThrown); + } + }); + }, + + minLength: 3 + }); +} + +function new_link_action(){ + send_ajax(jQuery("#page_url").val()); + + jQuery(".delete-link-list-row").click(function(){ + jQuery(this).parent().parent().remove(); + }); + + jQuery(".link-address").blur(function(){ + var value = jQuery(this).val(); + var search = /(^$)|(^\/$)|(http|www).*|.*\{profile\}.*|.*(\.com|\.org|\.net|\.edu|\.gov|\.info|\.eu)/; + + if( !search.test(value) ) { + value = "/{profile}/"+value; + jQuery(this).val(value); + } + }); + + jQuery(document).scrollTop(jQuery('#dropable-link-list').scrollTop()); +} + +jQuery(document).ready(function(){ + new_link_action(); + + jQuery("#dropable-link-list").sortable({ + revert: true, + axis: "y" + }); +}); \ No newline at end of file diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 137821b..17a424d 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1859,21 +1859,85 @@ a.button.disabled, input.disabled { text-decoration: none; } /* ==> blocks/link-list-block.css <<= */ - #edit-link-list-block { - width: 820px; + width: 620px; + position: relative; + left: -24px; } -#edit-link-list-block table { - width: auto; - margin-bottom: 10px; +.link-list-header { + width: 98%; + height: 25px; + padding: 10px 1px 10px 10px; + margin-bottom: 5px; + cursor: pointer; } -#edit-link-list-block table .cel-address { - width: 220px; + +#dropable-link-list { + padding-left: 23px; + margin-top: -12px; } -#edit-link-list-block table .cel-address input { - width: 100%; + +#dropable-link-list li { + list-style-type: none; +} + +.link-list-row { + line-height: 25px; + margin-bottom: 5px; + padding: 10px 1px 10px 10px; + cursor: pointer; + width: 90%; +} +.link-list-row:hover { + background: #aaa url(/images/drag-and-drop.png) no-repeat; + background-position: 98% 15px; +} + +.link-list-row li { + list-style-type: none; + display: inline; + margin-left: 5px; } + +.link-list-row li div { + float: left; + margin-top: 4px; +} + +.link-list-row li a { + line-height: 27px !important; + padding-right: 5px; +} + +.link-list-header li { + list-style-type: none; + display: inline; + font-weight: bold; + font-size: 14px; + text-align: center; +} + +.link-list-icon { + margin-left: 14px; +} + +.link-list-name { + margin-left: 40px; +} + +.link-list-address { + margin-left: 90px; +} + +.link-list-target { + margin-left: 77px; +} + +.new_link_row li { + margin-left: 7px; +} + #content .link-list-block { padding: 10px 0px 10px 10px; } diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb index 173b613..641c014 100644 --- a/test/functional/profile_design_controller_test.rb +++ b/test/functional/profile_design_controller_test.rb @@ -320,6 +320,17 @@ class ProfileDesignControllerTest < ActionController::TestCase assert_tag :input, :attributes => { :type => 'radio', :value => 'except_home_page'} end + should 'return a list of paths related to the words used in the query search' do + article1 = fast_create(Article, :profile_id => @profile.id, :name => "Some thing") + article2 = fast_create(Article, :profile_id => @profile.id, :name => "Some article") + article3 = fast_create(Article, :profile_id => @profile.id, :name => "Not an article") + + xhr :get, :search_autocomplete, :profile => 'designtestuser' , :query => 'Some' + assert_response :success + assert_equal @response.body.include?(article1.path), true + assert_equal @response.body.include?(article2.path), true + assert_equal @response.body.include?(article3.path), false + end ###################################################### # END - tests for BoxOrganizerController features -- libgit2 0.21.2