Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge commit 'ab908b268cb06ac17aba98cf8be2fb95d1af0cd3' into HEAD

  • Loading branch information...
commit cd4d7c7869574753a513f8b6efcbbb65bd085794 2 parents 99f0963 + ab908b2
Jenkins authored
View
4 Gemfile
@@ -28,12 +28,12 @@ gem 'rails', '~> 3.1.1'
gem 'colorize', '~> 0.5.8'
-gem "mongoid", "~> 2.3"
+gem "mongoid", "~> 2.4.2"
gem "mongo", "1.5.2"
gem "bson_ext", "1.5.2"
gem "bson", "1.5.2"
-gem "govuk_content_models", "0.0.1"
+gem "govuk_content_models", "0.0.5"
if ENV['BUNDLE_DEV']
gem 'gds-sso', :path => '../gds-sso'
View
25 Gemfile.lock
@@ -54,7 +54,7 @@ GEM
activesupport (= 3.1.3)
activesupport (3.1.3)
multi_json (~> 1.0)
- addressable (2.2.7)
+ addressable (2.2.8)
ansi (1.4.1)
arel (2.2.3)
aws-ses (0.4.4)
@@ -94,6 +94,7 @@ GEM
nokogiri (>= 1.5.0)
database_cleaner (0.7.1)
diff-lcs (1.1.3)
+ differ (0.1.2)
erubis (2.7.0)
exception_notification (2.5.2)
actionmailer (>= 3.0.4)
@@ -114,7 +115,7 @@ GEM
lrucache (~> 0.1.1)
null_logger
plek
- gds-sso (0.5.2)
+ gds-sso (0.5.4)
oa-core (~> 0.3.2)
oa-oauth (~> 0.3.2)
oauth2 (= 0.5.2)
@@ -128,14 +129,17 @@ GEM
json
gherkin (2.7.3)
json (>= 1.4.6)
- govuk_content_models (0.0.1)
+ govuk_content_models (0.0.5)
bson_ext
- gds-api-adapters (~> 0.0.47)
+ differ
+ gds-api-adapters
+ gds-sso
mongoid (~> 2.4.10)
- plek (~> 0.1.21)
+ plek (~> 0.1.22)
+ state_machine
hike (1.2.1)
i18n (0.6.0)
- json (1.6.6)
+ json (1.7.3)
launchy (2.0.5)
addressable (~> 2.2.6)
libv8 (3.3.10.4)
@@ -184,7 +188,7 @@ GEM
oauth2 (0.5.2)
faraday (~> 0.7)
multi_json (~> 1.0)
- plek (0.1.21)
+ plek (0.1.22)
builder
polyglot (0.3.3)
rack (1.3.5)
@@ -228,13 +232,14 @@ GEM
simplecov-html (0.4.5)
simplecov-rcov (0.2.3)
simplecov (>= 0.4.1)
- sprockets (2.0.3)
+ sprockets (2.0.4)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
+ state_machine (1.1.2)
stomp (1.2.0)
term-ansicolor (1.0.7)
test-unit (2.4.5)
@@ -286,13 +291,13 @@ DEPENDENCIES
gds-sso (~> 0.5)
gds-warmup-controller
gelf
- govuk_content_models (= 0.0.1)
+ govuk_content_models (= 0.0.5)
launchy
marples (~> 1.0)
minitest
mocha
mongo (= 1.5.2)
- mongoid (~> 2.3)
+ mongoid (~> 2.4.2)
nokogiri
null_logger
plek (~> 0)
View
2  app/assets/javascripts/artefacts.js
@@ -19,7 +19,7 @@ $(function() {
// no_results_text: "No results matched"
// });
- $('select#artefact_section').chosen({
+ $('select#artefact_sections').chosen({
allow_single_deselect: true,
no_results_text: "Section not found"
});
View
2  app/assets/javascripts/chosen.jquery.min.js
@@ -6,4 +6,4 @@
// Copyright (c) 2011 Harvest http://getharvest.com
// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
// This file is generated by `cake build`, do not edit it by hand.
-((function(){var a;a=function(){function a(){this.options_index=0,this.parsed=[]}return a.prototype.add_node=function(a){return a.nodeName==="OPTGROUP"?this.add_group(a):this.add_option(a)},a.prototype.add_group=function(a){var b,c,d,e,f,g;b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:a.label,children:0,disabled:a.disabled}),f=a.childNodes,g=[];for(d=0,e=f.length;d<e;d++)c=f[d],g.push(this.add_option(c,b,a.disabled));return g},a.prototype.add_option=function(a,b,c){if(a.nodeName==="OPTION")return a.text!==""?(b!=null&&(this.parsed[b].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:a.value,text:a.text,html:a.innerHTML,selected:a.selected,disabled:c===!0?c:a.disabled,group_array_index:b,classes:a.className,style:a.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1},a}(),a.select_to_array=function(b){var c,d,e,f,g;d=new a,g=b.childNodes;for(e=0,f=g.length;e<f;e++)c=g[e],d.add_node(c);return d.parsed},this.SelectParser=a})).call(this),function(){var a,b,c=function(a,b){return function(){return a.apply(b,arguments)}};b=this,a=function(){function a(a,b){this.form_field=a,this.options=b!=null?b:{},this.set_default_values(),this.is_multiple=this.form_field.multiple,this.default_text_default=this.is_multiple?"Select Some Options":"Select an Option",this.setup(),this.set_up_html(),this.register_observers(),this.finish_setup()}return a.prototype.set_default_values=function(){return this.click_test_action=c(function(a){return this.test_active_click(a)},this),this.activate_action=c(function(a){return this.activate_field(a)},this),this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.result_single_selected=null,this.allow_single_deselect=this.options.allow_single_deselect!=null&&this.form_field.options[0]!=null&&this.form_field.options[0].text===""?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.choices=0,this.results_none_found=this.options.no_results_text||"No results match"},a.prototype.mouse_enter=function(){return this.mouse_on_container=!0},a.prototype.mouse_leave=function(){return this.mouse_on_container=!1},a.prototype.input_focus=function(a){if(!this.active_field)return setTimeout(c(function(){return this.container_mousedown()},this),50)},a.prototype.input_blur=function(a){if(!this.mouse_on_container)return this.active_field=!1,setTimeout(c(function(){return this.blur_test()},this),100)},a.prototype.result_add_option=function(a){var b,c;return a.disabled?"":(a.dom_id=this.container_id+"_o_"+a.array_index,b=a.selected&&this.is_multiple?[]:["active-result"],a.selected&&b.push("result-selected"),a.group_array_index!=null&&b.push("group-option"),a.classes!==""&&b.push(a.classes),c=a.style.cssText!==""?' style="'+a.style+'"':"",'<li id="'+a.dom_id+'" class="'+b.join(" ")+'"'+c+">"+a.html+"</li>")},a.prototype.results_update_field=function(){return this.result_clear_highlight(),this.result_single_selected=null,this.results_build()},a.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},a.prototype.results_search=function(a){return this.results_showing?this.winnow_results():this.results_show()},a.prototype.keyup_checker=function(a){var b,c;b=(c=a.which)!=null?c:a.keyCode,this.search_field_scale();switch(b){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:a.preventDefault();if(this.results_showing)return this.result_select(a);break;case 27:if(this.results_showing)return this.results_hide();break;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},a.prototype.generate_field_id=function(){var a;return a=this.generate_random_id(),this.form_field.id=a,a},a.prototype.generate_random_char=function(){var a,b,c;return a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ",c=Math.floor(Math.random()*a.length),b=a.substring(c,c+1)},a}(),b.AbstractChosen=a}.call(this),function(){var a,b,c,d,e=Object.prototype.hasOwnProperty,f=function(a,b){function c(){this.constructor=a}for(var d in b)e.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},g=function(a,b){return function(){return a.apply(b,arguments)}};d=this,a=jQuery,a.fn.extend({chosen:function(c){return!a.browser.msie||a.browser.version!=="6.0"&&a.browser.version!=="7.0"?a(this).each(function(d){if(!a(this).hasClass("chzn-done"))return new b(this,c)}):this}}),b=function(){function b(){b.__super__.constructor.apply(this,arguments)}return f(b,AbstractChosen),b.prototype.setup=function(){return this.form_field_jq=a(this.form_field),this.is_rtl=this.form_field_jq.hasClass("chzn-rtl")},b.prototype.finish_setup=function(){return this.form_field_jq.addClass("chzn-done")},b.prototype.set_up_html=function(){var b,d,e,f;return this.container_id=this.form_field.id.length?this.form_field.id.replace(/(:|\.)/g,"_"):this.generate_field_id(),this.container_id+="_chzn",this.f_width=this.form_field_jq.outerWidth(),this.default_text=this.form_field_jq.data("placeholder")?this.form_field_jq.data("placeholder"):this.default_text_default,b=a("<div />",{id:this.container_id,"class":"chzn-container"+(this.is_rtl?" chzn-rtl":""),style:"width: "+this.f_width+"px;"}),this.is_multiple?b.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="'+this.default_text+'" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>'):b.html('<a href="javascript:void(0)" class="chzn-single"><span>'+this.default_text+'</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'),this.form_field_jq.hide().after(b),this.container=a("#"+this.container_id),this.container.addClass("chzn-container-"+(this.is_multiple?"multi":"single")),this.dropdown=this.container.find("div.chzn-drop").first(),d=this.container.height(),e=this.f_width-c(this.dropdown),this.dropdown.css({width:e+"px",top:d+"px"}),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chzn-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chzn-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chzn-search").first(),this.selected_item=this.container.find(".chzn-single").first(),f=e-c(this.search_container)-c(this.search_field),this.search_field.css({width:f+"px"})),this.results_build(),this.set_tab_index(),this.form_field_jq.trigger("liszt:ready",{chosen:this})},b.prototype.register_observers=function(){this.container.mousedown(g(function(a){return this.container_mousedown(a)},this)),this.container.mouseup(g(function(a){return this.container_mouseup(a)},this)),this.container.mouseenter(g(function(a){return this.mouse_enter(a)},this)),this.container.mouseleave(g(function(a){return this.mouse_leave(a)},this)),this.search_results.mouseup(g(function(a){return this.search_results_mouseup(a)},this)),this.search_results.mouseover(g(function(a){return this.search_results_mouseover(a)},this)),this.search_results.mouseout(g(function(a){return this.search_results_mouseout(a)},this)),this.form_field_jq.bind("liszt:updated",g(function(a){return this.results_update_field(a)},this)),this.search_field.blur(g(function(a){return this.input_blur(a)},this)),this.search_field.keyup(g(function(a){return this.keyup_checker(a)},this)),this.search_field.keydown(g(function(a){return this.keydown_checker(a)},this));if(this.is_multiple)return this.search_choices.click(g(function(a){return this.choices_click(a)},this)),this.search_field.focus(g(function(a){return this.input_focus(a)},this))},b.prototype.search_field_disabled=function(){this.is_disabled=this.form_field_jq[0].disabled;if(this.is_disabled)return this.container.addClass("chzn-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus",this.activate_action),this.close_field();this.container.removeClass("chzn-disabled"),this.search_field[0].disabled=!1;if(!this.is_multiple)return this.selected_item.bind("focus",this.activate_action)},b.prototype.container_mousedown=function(b){var c;if(!this.is_disabled)return c=b!=null?a(b.target).hasClass("search-choice-close"):!1,b&&b.type==="mousedown"&&b.stopPropagation(),!this.pending_destroy_click&&!c?(this.active_field?!this.is_multiple&&b&&(a(b.target)[0]===this.selected_item[0]||a(b.target).parents("a.chzn-single").length)&&(b.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),a(document).click(this.click_test_action),this.results_show()),this.activate_field()):this.pending_destroy_click=!1},b.prototype.container_mouseup=function(a){if(a.target.nodeName==="ABBR")return this.results_reset(a)},b.prototype.blur_test=function(a){if(!this.active_field&&this.container.hasClass("chzn-container-active"))return this.close_field()},b.prototype.close_field=function(){return a(document).unbind("click",this.click_test_action),this.is_multiple||(this.selected_item.attr("tabindex",this.search_field.attr("tabindex")),this.search_field.attr("tabindex",-1)),this.active_field=!1,this.results_hide(),this.container.removeClass("chzn-container-active"),this.winnow_results_clear(),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},b.prototype.activate_field=function(){return!this.is_multiple&&!this.active_field&&(this.search_field.attr("tabindex",this.selected_item.attr("tabindex")),this.selected_item.attr("tabindex",-1)),this.container.addClass("chzn-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},b.prototype.test_active_click=function(b){return a(b.target).parents("#"+this.container_id).length?this.active_field=!0:this.close_field()},b.prototype.results_build=function(){var a,b,c,e,f;this.parsing=!0,this.results_data=d.SelectParser.select_to_array(this.form_field),this.is_multiple&&this.choices>0?(this.search_choices.find("li.search-choice").remove(),this.choices=0):this.is_multiple||(this.selected_item.find("span").text(this.default_text),this.form_field.options.length>this.disable_search_threshold?this.container.removeClass("chzn-container-single-nosearch"):this.container.addClass("chzn-container-single-nosearch")),a="",f=this.results_data;for(c=0,e=f.length;c<e;c++)b=f[c],b.group?a+=this.result_add_group(b):b.empty||(a+=this.result_add_option(b),b.selected&&this.is_multiple?this.choice_build(b):b.selected&&!this.is_multiple&&(this.selected_item.find("span").text(b.text),this.allow_single_deselect&&this.single_deselect_control_build()));return this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.search_results.html(a),this.parsing=!1},b.prototype.result_add_group=function(b){return b.disabled?"":(b.dom_id=this.container_id+"_g_"+b.array_index,'<li id="'+b.dom_id+'" class="group-result">'+a("<div />").text(b.label).html()+"</li>")},b.prototype.result_do_highlight=function(a){var b,c,d,e,f;if(a.length){this.result_clear_highlight(),this.result_highlight=a,this.result_highlight.addClass("highlighted"),d=parseInt(this.search_results.css("maxHeight"),10),f=this.search_results.scrollTop(),e=d+f,c=this.result_highlight.position().top+this.search_results.scrollTop(),b=c+this.result_highlight.outerHeight();if(b>=e)return this.search_results.scrollTop(b-d>0?b-d:0);if(c<f)return this.search_results.scrollTop(c)}},b.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClass("highlighted"),this.result_highlight=null},b.prototype.results_show=function(){var a;return this.is_multiple||(this.selected_item.addClass("chzn-single-with-drop"),this.result_single_selected&&this.result_do_highlight(this.result_single_selected)),a=this.is_multiple?this.container.height():this.container.height()-1,this.dropdown.css({top:a+"px",left:0}),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.search_field.val()),this.winnow_results()},b.prototype.results_hide=function(){return this.is_multiple||this.selected_item.removeClass("chzn-single-with-drop"),this.result_clear_highlight(),this.dropdown.css({left:"-9000px"}),this.results_showing=!1},b.prototype.set_tab_index=function(a){var b;if(this.form_field_jq.attr("tabindex"))return b=this.form_field_jq.attr("tabindex"),this.form_field_jq.attr("tabindex",-1),this.is_multiple?this.search_field.attr("tabindex",b):(this.selected_item.attr("tabindex",b),this.search_field.attr("tabindex",-1))},b.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},b.prototype.search_results_mouseup=function(b){var c;c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first();if(c.length)return this.result_highlight=c,this.result_select(b)},b.prototype.search_results_mouseover=function(b){var c;c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first();if(c)return this.result_do_highlight(c)},b.prototype.search_results_mouseout=function(b){if(a(b.target).hasClass("active-result"))return this.result_clear_highlight()},b.prototype.choices_click=function(b){b.preventDefault();if(this.active_field&&!a(b.target).hasClass("search-choice")&&!this.results_showing)return this.results_show()},b.prototype.choice_build=function(b){var c,d;return c=this.container_id+"_c_"+b.array_index,this.choices+=1,this.search_container.before('<li class="search-choice" id="'+c+'"><span>'+b.html+'</span><a href="javascript:void(0)" class="search-choice-close" rel="'+b.array_index+'"></a></li>'),d=a("#"+c).find("a").first(),d.click(g(function(a){return this.choice_destroy_link_click(a)},this))},b.prototype.choice_destroy_link_click=function(b){return b.preventDefault(),this.is_disabled?b.stopPropagation:(this.pending_destroy_click=!0,this.choice_destroy(a(b.target)))},b.prototype.choice_destroy=function(a){return this.choices-=1,this.show_search_field_default(),this.is_multiple&&this.choices>0&&this.search_field.val().length<1&&this.results_hide(),this.result_deselect(a.attr("rel")),a.parents("li").first().remove()},b.prototype.results_reset=function(b){this.form_field.options[0].selected=!0,this.selected_item.find("span").text(this.default_text),this.show_search_field_default(),a(b.target).remove(),this.form_field_jq.trigger("change");if(this.active_field)return this.results_hide()},b.prototype.result_select=function(a){var b,c,d,e;if(this.result_highlight)return b=this.result_highlight,c=b.attr("id"),this.result_clear_highlight(),this.is_multiple?this.result_deactivate(b):(this.search_results.find(".result-selected").removeClass("result-selected"),this.result_single_selected=b),b.addClass("result-selected"),e=c.substr(c.lastIndexOf("_")+1),d=this.results_data[e],d.selected=!0,this.form_field.options[d.options_index].selected=!0,this.is_multiple?this.choice_build(d):(this.selected_item.find("span").first().text(d.text),this.allow_single_deselect&&this.single_deselect_control_build()),(!a.metaKey||!this.is_multiple)&&this.results_hide(),this.search_field.val(""),this.form_field_jq.trigger("change"),this.search_field_scale()},b.prototype.result_activate=function(a){return a.addClass("active-result")},b.prototype.result_deactivate=function(a){return a.removeClass("active-result")},b.prototype.result_deselect=function(b){var c,d;return d=this.results_data[b],d.selected=!1,this.form_field.options[d.options_index].selected=!1,c=a("#"+this.container_id+"_o_"+b),c.removeClass("result-selected").addClass("active-result").show(),this.result_clear_highlight(),this.winnow_results(),this.form_field_jq.trigger("change"),this.search_field_scale()},b.prototype.single_deselect_control_build=function(){if(this.allow_single_deselect&&this.selected_item.find("abbr").length<1)return this.selected_item.find("span").first().after('<abbr class="search-choice-close"></abbr>')},b.prototype.winnow_results=function(){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r;this.no_results_clear(),i=0,j=this.search_field.val()===this.default_text?"":a("<div/>").text(a.trim(this.search_field.val())).html(),f=new RegExp("^"+j.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),m=new RegExp(j.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),r=this.results_data;for(n=0,p=r.length;n<p;n++){c=r[n];if(!c.disabled&&!c.empty)if(c.group)a("#"+c.dom_id).css("display","none");else if(!this.is_multiple||!c.selected){b=!1,h=c.dom_id,g=a("#"+h);if(f.test(c.html))b=!0,i+=1;else if(c.html.indexOf(" ")>=0||c.html.indexOf("[")===0){e=c.html.replace(/\[|\]/g,"").split(" ");if(e.length)for(o=0,q=e.length;o<q;o++)d=e[o],f.test(d)&&(b=!0,i+=1)}b?(j.length?(k=c.html.search(m),l=c.html.substr(0,k+j.length)+"</em>"+c.html.substr(k+j.length),l=l.substr(0,k)+"<em>"+l.substr(k)):l=c.html,g.html(l),this.result_activate(g),c.group_array_index!=null&&a("#"+this.results_data[c.group_array_index].dom_id).css("display","list-item")):(this.result_highlight&&h===this.result_highlight.attr("id")&&this.result_clear_highlight(),this.result_deactivate(g))}}return i<1&&j.length?this.no_results(j):this.winnow_results_set_highlight()},b.prototype.winnow_results_clear=function(){var b,c,d,e,f;this.search_field.val(""),c=this.search_results.find("li"),f=[];for(d=0,e=c.length;d<e;d++)b=c[d],b=a(b),f.push(b.hasClass("group-result")?b.css("display","auto"):!this.is_multiple||!b.hasClass("result-selected")?this.result_activate(b):void 0);return f},b.prototype.winnow_results_set_highlight=function(){var a,b;if(!this.result_highlight){b=this.is_multiple?[]:this.search_results.find(".result-selected.active-result"),a=b.length?b.first():this.search_results.find(".active-result").first();if(a!=null)return this.result_do_highlight(a)}},b.prototype.no_results=function(b){var c;return c=a('<li class="no-results">'+this.results_none_found+' "<span></span>"</li>'),c.find("span").first().html(b),this.search_results.append(c)},b.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},b.prototype.keydown_arrow=function(){var b,c;this.result_highlight?this.results_showing&&(c=this.result_highlight.nextAll("li.active-result").first(),c&&this.result_do_highlight(c)):(b=this.search_results.find("li.active-result").first(),b&&this.result_do_highlight(a(b)));if(!this.results_showing)return this.results_show()},b.prototype.keyup_arrow=function(){var a;if(!this.results_showing&&!this.is_multiple)return this.results_show();if(this.result_highlight)return a=this.result_highlight.prevAll("li.active-result"),a.length?this.result_do_highlight(a.first()):(this.choices>0&&this.results_hide(),this.result_clear_highlight())},b.prototype.keydown_backstroke=function(){return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(this.pending_backstroke=this.search_container.siblings("li.search-choice").last(),this.pending_backstroke.addClass("search-choice-focus"))},b.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},b.prototype.keydown_checker=function(a){var b,c;b=(c=a.which)!=null?c:a.keyCode,this.search_field_scale(),b!==8&&this.pending_backstroke&&this.clear_backstroke();switch(b){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(a),this.mouse_on_container=!1;break;case 13:a.preventDefault();break;case 38:a.preventDefault(),this.keyup_arrow();break;case 40:this.keydown_arrow()}},b.prototype.search_field_scale=function(){var b,c,d,e,f,g,h,i,j;if(this.is_multiple){d=0,h=0,f="position:absolute; left: -1000px; top: -1000px; display:none;",g=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"];for(i=0,j=g.length;i<j;i++)e=g[i],f+=e+":"+this.search_field.css(e)+";";return c=a("<div />",{style:f}),c.text(this.search_field.val()),a("body").append(c),h=c.width()+25,c.remove(),h>this.f_width-10&&(h=this.f_width-10),this.search_field.css({width:h+"px"}),b=this.container.height(),this.dropdown.css({top:b+"px"})}},b.prototype.generate_random_id=function(){var b;b="sel"+this.generate_random_char()+this.generate_random_char()+this.generate_random_char();while(a("#"+b).length>0)b+=this.generate_random_char();return b},b}(),c=function(a){var b;return b=a.outerWidth()-a.width()},d.get_side_border_padding=c}.call(this)
+((function(){var a;a=function(){function a(){this.options_index=0,this.parsed=[]}return a.prototype.add_node=function(a){return a.nodeName==="OPTGROUP"?this.add_group(a):this.add_option(a)},a.prototype.add_group=function(a){var b,c,d,e,f,g;b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:a.label,children:0,disabled:a.disabled}),f=a.childNodes,g=[];for(d=0,e=f.length;d<e;d++)c=f[d],g.push(this.add_option(c,b,a.disabled));return g},a.prototype.add_option=function(a,b,c){if(a.nodeName==="OPTION")return a.text!==""?(b!=null&&(this.parsed[b].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:a.value,text:a.text,html:a.innerHTML,selected:a.selected,disabled:c===!0?c:a.disabled,group_array_index:b,classes:a.className,style:a.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1},a}(),a.select_to_array=function(b){var c,d,e,f,g;d=new a,g=b.childNodes;for(e=0,f=g.length;e<f;e++)c=g[e],d.add_node(c);return d.parsed},this.SelectParser=a})).call(this),function(){var a,b,c=function(a,b){return function(){return a.apply(b,arguments)}};b=this,a=function(){function a(a,b){this.form_field=a,this.options=b!=null?b:{},this.set_default_values(),this.is_multiple=this.form_field.multiple,this.default_text_default=this.is_multiple?"Type to show options":"Type to show an option",this.setup(),this.set_up_html(),this.register_observers(),this.finish_setup()}return a.prototype.set_default_values=function(){return this.click_test_action=c(function(a){return this.test_active_click(a)},this),this.activate_action=c(function(a){return this.activate_field(a)},this),this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.result_single_selected=null,this.allow_single_deselect=this.options.allow_single_deselect!=null&&this.form_field.options[0]!=null&&this.form_field.options[0].text===""?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.choices=0,this.results_none_found=this.options.no_results_text||"No results match"},a.prototype.mouse_enter=function(){return this.mouse_on_container=!0},a.prototype.mouse_leave=function(){return this.mouse_on_container=!1},a.prototype.input_focus=function(a){if(!this.active_field)return setTimeout(c(function(){return this.container_mousedown()},this),50)},a.prototype.input_blur=function(a){if(!this.mouse_on_container)return this.active_field=!1,setTimeout(c(function(){return this.blur_test()},this),100)},a.prototype.result_add_option=function(a){var b,c;return a.disabled?"":(a.dom_id=this.container_id+"_o_"+a.array_index,b=a.selected&&this.is_multiple?[]:["active-result"],a.selected&&b.push("result-selected"),a.group_array_index!=null&&b.push("group-option"),a.classes!==""&&b.push(a.classes),c=a.style.cssText!==""?' style="'+a.style+'"':"",'<li id="'+a.dom_id+'" class="'+b.join(" ")+'"'+c+">"+a.html+"</li>")},a.prototype.results_update_field=function(){return this.result_clear_highlight(),this.result_single_selected=null,this.results_build()},a.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},a.prototype.results_search=function(a){return this.results_showing?this.winnow_results():this.results_show()},a.prototype.keyup_checker=function(a){var b,c;b=(c=a.which)!=null?c:a.keyCode,this.search_field_scale();switch(b){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:a.preventDefault();if(this.results_showing)return this.result_select(a);break;case 27:if(this.results_showing)return this.results_hide();break;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},a.prototype.generate_field_id=function(){var a;return a=this.generate_random_id(),this.form_field.id=a,a},a.prototype.generate_random_char=function(){var a,b,c;return a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ",c=Math.floor(Math.random()*a.length),b=a.substring(c,c+1)},a}(),b.AbstractChosen=a}.call(this),function(){var a,b,c,d,e=Object.prototype.hasOwnProperty,f=function(a,b){function c(){this.constructor=a}for(var d in b)e.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},g=function(a,b){return function(){return a.apply(b,arguments)}};d=this,a=jQuery,a.fn.extend({chosen:function(c){return!a.browser.msie||a.browser.version!=="6.0"&&a.browser.version!=="7.0"?a(this).each(function(d){if(!a(this).hasClass("chzn-done"))return new b(this,c)}):this}}),b=function(){function b(){b.__super__.constructor.apply(this,arguments)}return f(b,AbstractChosen),b.prototype.setup=function(){return this.form_field_jq=a(this.form_field),this.is_rtl=this.form_field_jq.hasClass("chzn-rtl")},b.prototype.finish_setup=function(){return this.form_field_jq.addClass("chzn-done")},b.prototype.set_up_html=function(){var b,d,e,f;return this.container_id=this.form_field.id.length?this.form_field.id.replace(/(:|\.)/g,"_"):this.generate_field_id(),this.container_id+="_chzn",this.f_width=this.form_field_jq.outerWidth(),this.default_text=this.form_field_jq.data("placeholder")?this.form_field_jq.data("placeholder"):this.default_text_default,b=a("<div />",{id:this.container_id,"class":"chzn-container"+(this.is_rtl?" chzn-rtl":""),style:"width: "+this.f_width+"px;"}),this.is_multiple?b.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="'+this.default_text+'" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>'):b.html('<a href="javascript:void(0)" class="chzn-single"><span>'+this.default_text+'</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'),this.form_field_jq.hide().after(b),this.container=a("#"+this.container_id),this.container.addClass("chzn-container-"+(this.is_multiple?"multi":"single")),this.dropdown=this.container.find("div.chzn-drop").first(),d=this.container.height(),e=this.f_width-c(this.dropdown),this.dropdown.css({width:e+"px",top:d+"px"}),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chzn-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chzn-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chzn-search").first(),this.selected_item=this.container.find(".chzn-single").first(),f=e-c(this.search_container)-c(this.search_field),this.search_field.css({width:f+"px"})),this.results_build(),this.set_tab_index(),this.form_field_jq.trigger("liszt:ready",{chosen:this})},b.prototype.register_observers=function(){this.container.mousedown(g(function(a){return this.container_mousedown(a)},this)),this.container.mouseup(g(function(a){return this.container_mouseup(a)},this)),this.container.mouseenter(g(function(a){return this.mouse_enter(a)},this)),this.container.mouseleave(g(function(a){return this.mouse_leave(a)},this)),this.search_results.mouseup(g(function(a){return this.search_results_mouseup(a)},this)),this.search_results.mouseover(g(function(a){return this.search_results_mouseover(a)},this)),this.search_results.mouseout(g(function(a){return this.search_results_mouseout(a)},this)),this.form_field_jq.bind("liszt:updated",g(function(a){return this.results_update_field(a)},this)),this.search_field.blur(g(function(a){return this.input_blur(a)},this)),this.search_field.keyup(g(function(a){return this.keyup_checker(a)},this)),this.search_field.keydown(g(function(a){return this.keydown_checker(a)},this));if(this.is_multiple)return this.search_choices.click(g(function(a){return this.choices_click(a)},this)),this.search_field.focus(g(function(a){return this.input_focus(a)},this))},b.prototype.search_field_disabled=function(){this.is_disabled=this.form_field_jq[0].disabled;if(this.is_disabled)return this.container.addClass("chzn-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus",this.activate_action),this.close_field();this.container.removeClass("chzn-disabled"),this.search_field[0].disabled=!1;if(!this.is_multiple)return this.selected_item.bind("focus",this.activate_action)},b.prototype.container_mousedown=function(b){var c;if(!this.is_disabled)return c=b!=null?a(b.target).hasClass("search-choice-close"):!1,b&&b.type==="mousedown"&&b.stopPropagation(),!this.pending_destroy_click&&!c?(this.active_field?!this.is_multiple&&b&&(a(b.target)[0]===this.selected_item[0]||a(b.target).parents("a.chzn-single").length)&&(b.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),a(document).click(this.click_test_action),this.results_show()),this.activate_field()):this.pending_destroy_click=!1},b.prototype.container_mouseup=function(a){if(a.target.nodeName==="ABBR")return this.results_reset(a)},b.prototype.blur_test=function(a){if(!this.active_field&&this.container.hasClass("chzn-container-active"))return this.close_field()},b.prototype.close_field=function(){return a(document).unbind("click",this.click_test_action),this.is_multiple||(this.selected_item.attr("tabindex",this.search_field.attr("tabindex")),this.search_field.attr("tabindex",-1)),this.active_field=!1,this.results_hide(),this.container.removeClass("chzn-container-active"),this.winnow_results_clear(),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},b.prototype.activate_field=function(){return!this.is_multiple&&!this.active_field&&(this.search_field.attr("tabindex",this.selected_item.attr("tabindex")),this.selected_item.attr("tabindex",-1)),this.container.addClass("chzn-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},b.prototype.test_active_click=function(b){return a(b.target).parents("#"+this.container_id).length?this.active_field=!0:this.close_field()},b.prototype.results_build=function(){var a,b,c,e,f;this.parsing=!0,this.results_data=d.SelectParser.select_to_array(this.form_field),this.is_multiple&&this.choices>0?(this.search_choices.find("li.search-choice").remove(),this.choices=0):this.is_multiple||(this.selected_item.find("span").text(this.default_text),this.form_field.options.length>this.disable_search_threshold?this.container.removeClass("chzn-container-single-nosearch"):this.container.addClass("chzn-container-single-nosearch")),a="",f=this.results_data;for(c=0,e=f.length;c<e;c++)b=f[c],b.group?a+=this.result_add_group(b):b.empty||(a+=this.result_add_option(b),b.selected&&this.is_multiple?this.choice_build(b):b.selected&&!this.is_multiple&&(this.selected_item.find("span").text(b.text),this.allow_single_deselect&&this.single_deselect_control_build()));return this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.search_results.html(a),this.parsing=!1},b.prototype.result_add_group=function(b){return b.disabled?"":(b.dom_id=this.container_id+"_g_"+b.array_index,'<li id="'+b.dom_id+'" class="group-result">'+a("<div />").text(b.label).html()+"</li>")},b.prototype.result_do_highlight=function(a){var b,c,d,e,f;if(a.length){this.result_clear_highlight(),this.result_highlight=a,this.result_highlight.addClass("highlighted"),d=parseInt(this.search_results.css("maxHeight"),10),f=this.search_results.scrollTop(),e=d+f,c=this.result_highlight.position().top+this.search_results.scrollTop(),b=c+this.result_highlight.outerHeight();if(b>=e)return this.search_results.scrollTop(b-d>0?b-d:0);if(c<f)return this.search_results.scrollTop(c)}},b.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClass("highlighted"),this.result_highlight=null},b.prototype.results_show=function(){var a;return this.is_multiple||(this.selected_item.addClass("chzn-single-with-drop"),this.result_single_selected&&this.result_do_highlight(this.result_single_selected)),a=this.is_multiple?this.container.height():this.container.height()-1,this.dropdown.css({top:a+"px",left:0}),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.search_field.val()),this.winnow_results()},b.prototype.results_hide=function(){return this.is_multiple||this.selected_item.removeClass("chzn-single-with-drop"),this.result_clear_highlight(),this.dropdown.css({left:"-9000px"}),this.results_showing=!1},b.prototype.set_tab_index=function(a){var b;if(this.form_field_jq.attr("tabindex"))return b=this.form_field_jq.attr("tabindex"),this.form_field_jq.attr("tabindex",-1),this.is_multiple?this.search_field.attr("tabindex",b):(this.selected_item.attr("tabindex",b),this.search_field.attr("tabindex",-1))},b.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},b.prototype.search_results_mouseup=function(b){var c;c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first();if(c.length)return this.result_highlight=c,this.result_select(b)},b.prototype.search_results_mouseover=function(b){var c;c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first();if(c)return this.result_do_highlight(c)},b.prototype.search_results_mouseout=function(b){if(a(b.target).hasClass("active-result"))return this.result_clear_highlight()},b.prototype.choices_click=function(b){b.preventDefault();if(this.active_field&&!a(b.target).hasClass("search-choice")&&!this.results_showing)return this.results_show()},b.prototype.choice_build=function(b){var c,d;return c=this.container_id+"_c_"+b.array_index,this.choices+=1,this.search_container.before('<li class="search-choice" id="'+c+'"><span>'+b.html+'</span><a href="javascript:void(0)" class="search-choice-close" rel="'+b.array_index+'"></a></li>'),d=a("#"+c).find("a").first(),d.click(g(function(a){return this.choice_destroy_link_click(a)},this))},b.prototype.choice_destroy_link_click=function(b){return b.preventDefault(),this.is_disabled?b.stopPropagation:(this.pending_destroy_click=!0,this.choice_destroy(a(b.target)))},b.prototype.choice_destroy=function(a){return this.choices-=1,this.show_search_field_default(),this.is_multiple&&this.choices>0&&this.search_field.val().length<1&&this.results_hide(),this.result_deselect(a.attr("rel")),a.parents("li").first().remove()},b.prototype.results_reset=function(b){this.form_field.options[0].selected=!0,this.selected_item.find("span").text(this.default_text),this.show_search_field_default(),a(b.target).remove(),this.form_field_jq.trigger("change");if(this.active_field)return this.results_hide()},b.prototype.result_select=function(a){var b,c,d,e;if(this.result_highlight)return b=this.result_highlight,c=b.attr("id"),this.result_clear_highlight(),this.is_multiple?this.result_deactivate(b):(this.search_results.find(".result-selected").removeClass("result-selected"),this.result_single_selected=b),b.addClass("result-selected"),e=c.substr(c.lastIndexOf("_")+1),d=this.results_data[e],d.selected=!0,this.form_field.options[d.options_index].selected=!0,this.is_multiple?this.choice_build(d):(this.selected_item.find("span").first().text(d.text),this.allow_single_deselect&&this.single_deselect_control_build()),(!a.metaKey||!this.is_multiple)&&this.results_hide(),this.search_field.val(""),this.form_field_jq.trigger("change"),this.search_field_scale()},b.prototype.result_activate=function(a){return a.addClass("active-result")},b.prototype.result_deactivate=function(a){return a.removeClass("active-result")},b.prototype.result_deselect=function(b){var c,d;return d=this.results_data[b],d.selected=!1,this.form_field.options[d.options_index].selected=!1,c=a("#"+this.container_id+"_o_"+b),c.removeClass("result-selected").addClass("active-result").show(),this.result_clear_highlight(),this.winnow_results(),this.form_field_jq.trigger("change"),this.search_field_scale()},b.prototype.single_deselect_control_build=function(){if(this.allow_single_deselect&&this.selected_item.find("abbr").length<1)return this.selected_item.find("span").first().after('<abbr class="search-choice-close"></abbr>')},b.prototype.winnow_results=function(){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r;this.no_results_clear(),i=0,j=this.search_field.val()===this.default_text?"":a("<div/>").text(a.trim(this.search_field.val())).html(),f=new RegExp("^"+j.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),m=new RegExp(j.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),r=this.results_data;for(n=0,p=r.length;n<p;n++){c=r[n];if(!c.disabled&&!c.empty)if(c.group)a("#"+c.dom_id).css("display","none");else if(!this.is_multiple||!c.selected){b=!1,h=c.dom_id,g=a("#"+h);if(f.test(c.html))b=!0,i+=1;else if(c.html.indexOf(" ")>=0||c.html.indexOf("[")===0){e=c.html.replace(/\[|\]/g,"").split(" ");if(e.length)for(o=0,q=e.length;o<q;o++)d=e[o],f.test(d)&&(b=!0,i+=1)}b?(j.length?(k=c.html.search(m),l=c.html.substr(0,k+j.length)+"</em>"+c.html.substr(k+j.length),l=l.substr(0,k)+"<em>"+l.substr(k)):l=c.html,g.html(l),this.result_activate(g),c.group_array_index!=null&&a("#"+this.results_data[c.group_array_index].dom_id).css("display","list-item")):(this.result_highlight&&h===this.result_highlight.attr("id")&&this.result_clear_highlight(),this.result_deactivate(g))}}return i<1&&j.length?this.no_results(j):this.winnow_results_set_highlight()},b.prototype.winnow_results_clear=function(){var b,c,d,e,f;this.search_field.val(""),c=this.search_results.find("li"),f=[];for(d=0,e=c.length;d<e;d++)b=c[d],b=a(b),f.push(b.hasClass("group-result")?b.css("display","auto"):!this.is_multiple||!b.hasClass("result-selected")?this.result_activate(b):void 0);return f},b.prototype.winnow_results_set_highlight=function(){var a,b;if(!this.result_highlight){b=this.is_multiple?[]:this.search_results.find(".result-selected.active-result"),a=b.length?b.first():this.search_results.find(".active-result").first();if(a!=null)return this.result_do_highlight(a)}},b.prototype.no_results=function(b){var c;return c=a('<li class="no-results">'+this.results_none_found+' "<span></span>"</li>'),c.find("span").first().html(b),this.search_results.append(c)},b.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},b.prototype.keydown_arrow=function(){var b,c;this.result_highlight?this.results_showing&&(c=this.result_highlight.nextAll("li.active-result").first(),c&&this.result_do_highlight(c)):(b=this.search_results.find("li.active-result").first(),b&&this.result_do_highlight(a(b)));if(!this.results_showing)return this.results_show()},b.prototype.keyup_arrow=function(){var a;if(!this.results_showing&&!this.is_multiple)return this.results_show();if(this.result_highlight)return a=this.result_highlight.prevAll("li.active-result"),a.length?this.result_do_highlight(a.first()):(this.choices>0&&this.results_hide(),this.result_clear_highlight())},b.prototype.keydown_backstroke=function(){return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(this.pending_backstroke=this.search_container.siblings("li.search-choice").last(),this.pending_backstroke.addClass("search-choice-focus"))},b.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},b.prototype.keydown_checker=function(a){var b,c;b=(c=a.which)!=null?c:a.keyCode,this.search_field_scale(),b!==8&&this.pending_backstroke&&this.clear_backstroke();switch(b){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(a),this.mouse_on_container=!1;break;case 13:a.preventDefault();break;case 38:a.preventDefault(),this.keyup_arrow();break;case 40:this.keydown_arrow()}},b.prototype.search_field_scale=function(){var b,c,d,e,f,g,h,i,j;if(this.is_multiple){d=0,h=0,f="position:absolute; left: -1000px; top: -1000px; display:none;",g=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"];for(i=0,j=g.length;i<j;i++)e=g[i],f+=e+":"+this.search_field.css(e)+";";return c=a("<div />",{style:f}),c.text(this.search_field.val()),a("body").append(c),h=c.width()+25,c.remove(),h>this.f_width-10&&(h=this.f_width-10),this.search_field.css({width:h+"px"}),b=this.container.height(),this.dropdown.css({top:b+"px"})}},b.prototype.generate_random_id=function(){var b;b="sel"+this.generate_random_char()+this.generate_random_char()+this.generate_random_char();while(a("#"+b).length>0)b+=this.generate_random_char();return b},b}(),c=function(a){var b;return b=a.outerWidth()-a.width()},d.get_side_border_padding=c}.call(this)
View
17 app/controllers/artefacts_controller.rb
@@ -28,7 +28,7 @@ def create
end
def update
- parameters_to_use = params[:artefact] || params.slice(*Artefact.fields.keys)
+ parameters_to_use = extract_parameters(params)
saved = @artefact.update_attributes(parameters_to_use)
flash[:notice] = saved ? 'Panopticon item updated' : 'Failed to save item'
@@ -53,6 +53,19 @@ def find_artefact
end
def build_artefact
- @artefact = Artefact.new(params[:artefact] || params.slice(*Artefact.fields.keys))
+ @artefact = Artefact.new(extract_parameters(params))
end
+
+ def extract_parameters(params)
+ fields_to_update = Artefact.fields.keys + ['sections']
+ parameters_to_use = params[:artefact] || params.slice(*fields_to_update)
+
+ # Strip out the empty submit option for sections
+ ['sections'].each do |param|
+ param_value = parameters_to_use[param]
+ param_value.reject! &:blank? if param_value
+ end
+ parameters_to_use
+ end
+
end
View
23 app/helpers/sections_helper.rb
@@ -0,0 +1,23 @@
+module SectionsHelper
+
+ def all_sections(options = {})
+ section_tags = TagRepository.load_all(:type => 'section')
+
+ title_counts = Hash.new(0)
+ section_tags.each { |tag| title_counts[tag.title] += 1 }
+
+ sections = section_tags.map do |tag|
+ # Annotate tags, where necessary, with their IDs
+ if title_counts[tag.title] > 1
+ display_name = "#{tag.title} [#{tag.tag_id}]"
+ else
+ display_name = tag.title
+ end
+ [display_name, tag.tag_id]
+ end
+
+ return sections unless options[:except]
+ sections.reject { |s| s[1] == options[:except] }
+ end
+
+end
View
35 app/views/artefacts/_form.html.erb
@@ -13,7 +13,7 @@
<% end %>
<div class="well">
- <%= semantic_form_for(artefact, :html => { :class => '' }) do |f| %>
+ <%= semantic_form_for(artefact, :html => { :class => '', :id => 'edit_artefact'}) do |f| %>
<%= f.inputs do %>
<%= f.input :name, :input_html => { :class => "span6" } %>
<%= f.input :slug, :input_html => { :class => "span6", :disabled => f.object.persisted? } %>
@@ -25,21 +25,23 @@
<hr>
- <%= f.input :business_proposition, :label => 'Business Content?', :as => :boolean %>
+ <%= f.input :business_proposition, :label => 'Is this business content?', :as => :boolean %>
<hr>
<% if artefact.new_record? %>
<%= f.input :kind, :collection => Artefact::FORMATS.map { |s| [s.humanize, s]}, :as => :select, :class => "span6", :prompt => "Select a kind" %>
<% end %>
- <%= f.input :section, :as => :select, :collection => Section.all.map { |s| [s.to_s, s.slug] }, :prompt => "Select a section" %>
+ <%= f.input :primary_section, :as => :select, :collection => all_sections, :input_html => { :multiple => false, :class => "span6 chzn-select" }, :hint => "This is the primary section the content will live in. This will form the content breadcrumb." %>
+ <input name="artefact[sections][]" type="hidden" value="">
+ <%= f.input :sections, :as => :select, :collection => all_sections(:except=> artefact.primary_section), :input_html => { :multiple => true, :class => "span6 chzn-select" }, :hint => "Pick some extra sections that the content will also appear in." %>
<% end %>
<hr>
<%= f.inputs do %>
<input name="artefact[related_artefact_ids][]" type="hidden" value="">
- <%= f.input :related_artefacts, :collection => Artefact.in_alphabetical_order, :input_html => { :multiple => true, :class => "span6 chzn-select" } %>
+ <%= f.input :related_artefacts, :label => "Related content", :collection => Artefact.in_alphabetical_order, :input_html => { :multiple => true, :class => "span6 chzn-select" }, :hint => "Start typing in to search for and select related links to be associated with this." %>
<%= f.input :relatedness_done, :label => "Is relatedness done?", :as => :boolean %>
<% end %>
@@ -58,8 +60,7 @@
<% end %>
<hr>
-
- <%= f.input :tags, :input_html => {:class => "span6"} %>
+ <%= f.input :tags, :label => "Keyword tags", :input_html => {:class => "span6"}, :hint => "Comma seperated keyword tags." %>
<% if f.object.persisted? %>
<%= f.submit :value => "Save and continue editing", :class => "btn" %>
@@ -70,6 +71,26 @@
<%= content_for :extra_javascript do %>
<%= javascript_include_tag('chosen.jquery.min.js', 'artefacts') %>
- <script type="text/javascript"> $(".chzn-select").chosen(); </script>
+ <script type="text/javascript">
+ $(".chzn-select").chosen();
+
+ // Need to prevent our selected primary section from appearing in the sections box
+ var current_primary_section = $("select#artefact_primary_section option:selected").clone();
+ // onchange event listener of chosen we want to append/remove some section options
+ $("#artefact_primary_section").chosen().change(function() {
+ var new_primary_section = $("select#artefact_primary_section option:selected").clone();
+ new_primary_section.removeAttr('selected');
+ $("select#artefact_sections").find("option[value='" + new_primary_section.val() + "']").remove();
+
+ if (current_primary_section.val() != "") {
+ current_primary_section.removeAttr('selected');
+ $("select#artefact_sections").append(current_primary_section);
+ }
+ current_primary_section = new_primary_section;
+
+ // this trigger will cause chosen to update its own lists
+ $("select#artefact_sections").trigger("liszt:updated");
+ });
+ </script>
<% end %>
<% content_for :extra_headers, stylesheet_link_tag('chosen') %>
View
15 features/editing.feature
@@ -64,3 +64,18 @@ Feature: Editing artefacts
# Then I should be redirected to Publisher
# And the API should say that the artefact does not have the contact
# And the rest of the system should be notified that the artefact has been updated
+
+ Scenario: Add a section
+ Given an artefact exists
+ And a section exists
+ When I add the section to the artefact
+ Then I should be redirected to Publisher
+ And the API should say that the artefact has the section
+
+ Scenario: Remove a section
+ Given an artefact exists
+ And a section exists
+ And the artefact has the section
+ When I remove the section from the artefact
+ Then I should be redirected to Publisher
+ And the API should say that the artefact does not have the section
View
8 features/step_definitions/api_steps.rb
@@ -22,3 +22,11 @@
Then /^the API should say that the artefact does not have the contact$/ do
check_artefact_does_not_have_contact_in_api @artefact, @contact
end
+
+Then /^the API should say that the artefact has the section$/ do
+ check_artefact_has_tag_in_api @artefact, @section.tag_id
+end
+
+Then /^the API should say that the artefact does not have the section$/ do
+ check_artefact_does_not_have_tag_in_api @artefact, @section.tag_id
+end
View
20 features/step_definitions/artefact_steps.rb
@@ -88,6 +88,10 @@
flush_notifications
end
+Given /^a section exists$/ do
+ @section = create_section
+end
+
When /^I add the contact to the artefact$/ do
visit edit_artefact_path(@artefact)
select_contact @contact
@@ -99,12 +103,28 @@
flush_notifications
end
+Given /^the artefact has the section$/ do
+ add_section @artefact, @section
+end
+
When /^I remove the contact from the artefact$/ do
visit edit_artefact_path(@artefact)
unselect_contact @contact
submit_artefact_form
end
+When /^I add the section to the artefact$/ do
+ visit edit_artefact_path(@artefact)
+ select_section @section
+ submit_artefact_form
+end
+
+When /^I remove the section from the artefact$/ do
+ visit edit_artefact_path(@artefact)
+ unselect_section @section
+ submit_artefact_form
+end
+
When /^I visit the homepage$/ do
visit root_path
end
View
12 features/support/api.rb
@@ -7,6 +7,10 @@ def related_artefact_ids_from_api(artefact)
artefact_data_from_api(artefact)[:related_items].map { |related_item| related_item[:artefact][:id] }
end
+def tag_ids_from_api(artefact)
+ artefact_data_from_api(artefact)[:tag_ids].map { |tag| tag['id'] }
+end
+
def contact_id_from_api(artefact)
artefact_data_from_api(artefact)[:contact].try(:[], :id)
end
@@ -41,3 +45,11 @@ def check_artefact_has_contact_in_api(artefact, contact)
def check_artefact_does_not_have_contact_in_api(artefact, contact)
assert_not_equal contact_id_from_api(artefact), contact.id.to_s
end
+
+def check_artefact_has_tag_in_api(artefact, tag_id)
+ assert_include tag_ids_from_api(artefact), tag_id
+end
+
+def check_artefact_does_not_have_tag_in_api(artefact, tag_id)
+ assert_not_include tag_ids_from_api(artefact), tag_id
+end
View
4 features/support/artefacts.rb
@@ -31,11 +31,11 @@ def add_related_artefacts(artefact, related_artefacts)
end
def select_related_artefact(artefact)
- select artefact.name, :from => 'Related artefacts'
+ select artefact.name, :from => 'Related content'
end
def unselect_related_artefact(artefact)
- unselect artefact.name, :from => 'Related artefacts'
+ unselect artefact.name, :from => 'Related content'
end
def select_related_artefacts(artefacts)
View
16 features/support/sections.rb
@@ -0,0 +1,16 @@
+def create_section
+ TagRepository.put :tag_id => 'crime', :tag_type => 'section', :title => 'Crime'
+ return TagRepository.load 'crime'
+end
+
+def select_section(section)
+ select section.title, :from => 'Sections'
+end
+
+def unselect_section(section)
+ unselect section.title, :from => 'Sections'
+end
+
+def add_section(artefact, section)
+ artefact.sections += [section.tag_id]
+end
View
46 lib/bulk_section_setter.rb
@@ -1,46 +0,0 @@
-class BulkSectionSetter
- attr_accessor :artefacts
-
- def initialize(filename, logger = nil)
- @artefacts = load(filename)
- @logger = logger || NullLogger.instance
- end
-
- def load(filename)
- artefacts = []
- section = nil
- subsection = nil
- File.open(filename, 'r').each do |line|
- if line =~ /^ /
- artefacts << {
- title: line.strip,
- subsection: subsection,
- section: section
- }
- elsif line =~ /^ /
- subsection = line.strip
- else
- section = line.strip
- end
- end
- artefacts
- end
-
- def set_all
- @artefacts.each do |record|
- artefact = Artefact.find_by_name(record[:title])
- section = "#{record[:section]}:#{record[:subsection]}"
- if artefact
- artefact.section = section
- begin
- artefact.save!
- @logger.info("Set '#{record[:title]}' to set section '#{section}'")
- rescue => e
- @logger.warn("Couldn't save '#{record[:title]}' because '#{e}'")
- end
- else
- @logger.warn("Couldn't find '#{record[:title]}' to set section '#{section}'")
- end
- end
- end
-end
View
53 lib/tasks/artefact_sections_to_tags.rake
@@ -0,0 +1,53 @@
+namespace :sections do
+
+ desc "Migrate artefacts to use tags for section information"
+ task :artefact_sections_to_tags => :environment do
+
+ IMPORTING_LEGACY_DATA = true # Allow resaving artefacts with no need ID
+
+ # Artefacts where section doesn't exist: leave them
+ # Artefacts where section is nil or empty string: unset section
+ # Artefacts where section is top-level:
+ # set top-level section tag;
+ # set primary section;
+ # unset section
+ # Artefacts where section is sub-level:
+ # set [sub-level, top-level];
+ # set primary section to sub-level;
+ # unset section
+
+ # The current stable version of Mongo doesn't offer criteria updates
+ Artefact.any_in(:section => [nil, '']).each do |a|
+ a.unset 'section'
+ a.save!
+ end
+
+ Artefact.where(:section.exists => true).each do |a|
+ section = a['section']
+
+ # Skip empty values: only useful in development
+ next if [nil, ''].include? section
+
+ section_parts = section.split(':').map { |s| s.downcase.gsub(' ', '-') }
+
+ case section_parts.length
+ when 1
+ section_tags = section_parts
+ when 2
+ section_tags = [section_parts.join('/'), section_parts[0]]
+ else
+ puts 'Wrong number of sections: aargh!'
+ raise RuntimeError
+ end
+ a.sections = section_tags # Will check the tags exist
+ a.primary_section = section_tags[0]
+ a.save!
+ puts "Sections: #{a.sections}; primary: #{a.primary_section}"
+
+ # Word of warning: this *does* persist the artefact, even without save
+ a.unset 'section'
+ # a.save!
+ end
+
+ end
+end
View
12 lib/tasks/bulk_set_sections.rake
@@ -1,12 +0,0 @@
-namespace :sections do
-
- desc "Set sections in bulk (specify DOCUMENT_SECTIONS_FILE)"
- task :bulk_set => :environment do
- raise "Specify DOCUMENT_SECTIONS_FILE" unless ENV['DOCUMENT_SECTIONS_FILE']
- raise "DOCUMENT_SECTIONS_FILE '#{ENV['DOCUMENT_SECTIONS_FILE']} not found" unless File.exist?(ENV['DOCUMENT_SECTIONS_FILE'])
-
- require 'bulk_section_setter'
- s = BulkSectionSetter.new(ENV['DOCUMENT_SECTIONS_FILE'], Logger.new(STDOUT))
- s.set_all
- end
-end
View
27 lib/tasks/sections.rake
@@ -1,27 +0,0 @@
-namespace :sections do
-
- desc "Migrate section assignments to new sections"
- task :migrate => :environment do
-
- @section_migrations = {
- 'Driving:Owning a car/motorbike' => 'Driving:Owning a car or motorbike',
- 'Education:In schools' => 'Education:In school',
- 'Family:Separation and divorce' => 'Family:Divorce and separation',
- 'Driving:Buying/selling a vehicle'=> 'Driving:Buying and selling a vehicle'
- }
-
- Artefact.all.each do |a|
-
- current_section = a.section
- new_section = @section_migrations[current_section]
-
- if !new_section or new_section.nil?
- puts "Not updating \"#{a.name}\" (\"#{current_section}\")".colorize(:white)
- elsif a.update_attribute(:section, new_section)
- puts "Updated \"#{a.name}\" from \"#{current_section}\" to \"#{new_section}\"".colorize(:green)
- else
- puts "Error: Could not update \"#{a.name}\", existing section \"#{current_section}\"".colorize(:red)
- end
- end
- end
-end
View
7 test/factories/tag_factory.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :tag do
+ sequence(:tag_id) { |n| "crime-and-justice/the-police-#{n}" }
+ sequence(:title) { |n| "The title #{n}" }
+ tag_type "section"
+ end
+end
View
3  test/fixtures/sample_bulk_section_settings.txt
@@ -1,3 +0,0 @@
-Section
- SubSection
- Article Title
View
22 test/functional/artefacts_controller_test.rb
@@ -53,6 +53,16 @@ class ArtefactsControllerTest < ActionController::TestCase
assert_equal artefact.kind, parsed['kind']
assert_equal artefact.owning_app, parsed['owning_app']
end
+
+ should "Include section ID" do
+ TagRepository.put :tag_id => 'crime', :tag_type => 'section', :title => 'Crime'
+ artefact = Artefact.create! :slug => 'whatever', :kind => 'guide', :owning_app => 'publisher', :name => 'Whatever', :need_id => 1, :primary_section => 'crime'
+ get :show, id: artefact.id, format: :json
+ parsed = JSON.parse(response.body)
+
+ assert_equal artefact.section, parsed['section']
+ end
+
end
context "PUT /artefacts/:id" do
@@ -67,6 +77,18 @@ class ArtefactsControllerTest < ActionController::TestCase
assert_equal "Changed", artefact.reload.name
assert_response :success
end
+
+ should "Update our primary section and ensure it persists into sections" do
+ @tags = FactoryGirl.create_list(:tag, 3)
+ artefact = Artefact.create!(:slug => 'whatever', :kind => 'guide',
+ :owning_app => 'publisher', :name => 'Whatever', :need_id => 1,
+ :tag_ids => [@tags[0].tag_id, @tags[1].tag_id])
+ put :update, :id => artefact.id, :primary_section => @tags[2].tag_id
+ artefact.reload
+
+ assert_equal @tags[2].tag_id, artefact.primary_section
+ assert_equal [@tags[2].tag_id, @tags[0].tag_id, @tags[1].tag_id], artefact.sections
+ end
end
end
View
7 test/unit/artefact_section_helper_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ArtefactSectionHelperTest < ActiveSupport::TestCase
+ test "should return sections with primary_section excluded" do
+ # TODO
+ end
+end
View
46 test/unit/bulk_section_setter_test.rb
@@ -1,46 +0,0 @@
-require 'test_helper'
-require 'bulk_section_setter'
-
-class BulkSectionSetterTest < ActiveSupport::TestCase
- def sample_bulk_section_settings_file
- File.expand_path("../fixtures/sample_bulk_section_settings.txt", File.dirname(__FILE__))
- end
-
- test "Reads settings from a file" do
- setter = BulkSectionSetter.new(sample_bulk_section_settings_file)
- assert_equal 1, setter.artefacts.size
- expected_artefact = {title: "Article Title", section: "Section", subsection: "SubSection"}
- assert_equal expected_artefact, setter.artefacts.first
- end
-
- test "Apply section to artefacts which can be found" do
- artefact = stub_everything("Article")
- Artefact.expects(:find_by_name).with('Article Title').returns(artefact)
- s = sequence("setting section")
- artefact.expects(:section=).with("Section:SubSection").in_sequence(s)
- artefact.expects(:save!).in_sequence(s)
-
- setter = BulkSectionSetter.new(sample_bulk_section_settings_file)
- setter.set_all
- end
-
- test "Keep a log of artefacts which could not be found" do
- logger = stub("Logger")
- Artefact.stubs(:find_by_name).returns(nil)
- logger.expects(:warn).with("Couldn't find 'Article Title' to set section 'Section:SubSection'")
-
- setter = BulkSectionSetter.new(sample_bulk_section_settings_file, logger)
- setter.set_all
- end
-
- test "Catch validation errors on save" do
- artefact = stub("Article")
- artefact.stubs(:section=)
- artefact.stubs(:save!).raises("something bad happened")
- Artefact.expects(:find_by_name).returns(artefact)
- logger = stub("Logger")
- logger.expects(:warn).with(regexp_matches(/Couldn't save 'Article Title' because /))
- setter = BulkSectionSetter.new(sample_bulk_section_settings_file, logger)
- setter.set_all
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.