Commit 45340488df548adf6024f6e7fe357eb07f37f780
Committed by
Tallys Martins
1 parent
1a927cde
Exists in
master
and in
55 other branches
Added masks for use report fields
- Added mask for benefited people in the format 000.000.000 - Added mask for saved value in the format 999.999.999,00 - Added hidden fields to get better effects with javascript - Added cucumber tests to use report Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com> Signed-off-by: Joenio Costa <joenio@colivre.coop.br> Signed-off-by: Gustavo Coelho <gust.rod.coelho@gmail.com> Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
6 changed files
with
97 additions
and
13 deletions
Show diff stats
src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb
... | ... | @@ -151,7 +151,7 @@ Given /^the user "([^"]*)" has "([^"]*)" as secondary e\-mail$/ do |login, email |
151 | 151 | end |
152 | 152 | |
153 | 153 | Given /^I click on anything with selector "([^"]*)"$/ do |selector| |
154 | - evaluate_script "jQuery('#{selector}').trigger('click') && true" | |
154 | + page.evaluate_script("jQuery('##{selector}').click();") | |
155 | 155 | end |
156 | 156 | |
157 | 157 | Given /^I should see "([^"]*)" of this selector "([^"]*)"$/ do |quantity, selector| | ... | ... |
src/noosfero-spb/software_communities/features/use_report.feature
0 → 100644
... | ... | @@ -0,0 +1,56 @@ |
1 | +Feature: Use report | |
2 | + As a user | |
3 | + I want to make a use report of a software | |
4 | + to give my feedback about a software. | |
5 | + | |
6 | + Background: | |
7 | + Given "SoftwareCommunitiesPlugin" plugin is enabled | |
8 | + Given "OrganizationRatings" plugin is enabled | |
9 | + And I am logged in as mpog_admin | |
10 | + And I go to /admin/plugins | |
11 | + And I check "SoftwareCommunitiesPlugin" | |
12 | + And I press "Save changes" | |
13 | + And the following softwares | |
14 | + | name | public_software | finality | | |
15 | + | Noosfero | true | some finality | | |
16 | + | |
17 | + Scenario: Add Organization Ratings Block | |
18 | + Given I go to Noosfero's control panel | |
19 | + And I follow "Edit sideboxes" | |
20 | + When I follow "Add a block" | |
21 | + And I choose "Organization Ratings" | |
22 | + And I press "Add" | |
23 | + Then I should see "Report your experiences" | |
24 | + | |
25 | + Scenario: Add Average Rating Block | |
26 | + Given I go to Noosfero's control panel | |
27 | + And I follow "Edit sideboxes" | |
28 | + When I follow "Add a block" | |
29 | + And I choose "Organization Average Rating" | |
30 | + And I press "Add" | |
31 | + Then I should see "Be the first to rate!" | |
32 | + | |
33 | + @selenium | |
34 | + Scenario: Test Additional Fields JavaScript | |
35 | + Given I go to /profile/noosfero/plugin/organization_ratings/new_rating | |
36 | + Then I should not see "Number of Beneficiaries" | |
37 | + And I should not see "Saved Resources" | |
38 | + When I click on anything with selector "comments-additional-information" | |
39 | + Then I should see "Number of Beneficiaries" | |
40 | + And I should see "Saved Resources" | |
41 | + | |
42 | + @selenium | |
43 | + Scenario: Validate Use Report fields format | |
44 | + Given I go to Noosfero's control panel | |
45 | + Given I follow "Edit sideboxes" | |
46 | + When I follow "Add a block" | |
47 | + And I choose "Organization Ratings" | |
48 | + And I press "Add" | |
49 | + And I am on Noosfero's homepage | |
50 | + And I follow "Rate Community" | |
51 | + When I click on anything with selector "comments-additional-information" | |
52 | + And I fill in "organization_rating_people_benefited" with "123123" | |
53 | + And I fill in "organization_rating_saved_value" with "7654321" | |
54 | + And I press "Save" | |
55 | + Then I should see "Benefited People: 123.123" | |
56 | + And I should see "Saved Resources: $ 76,543.21" | ... | ... |
src/noosfero-spb/software_communities/public/vendor/jquery.maskedinput.min.js
1 | -/* | |
2 | - Masked Input plugin for jQuery | |
3 | - Copyright (c) 2007-2013 Josh Bush (digitalbush.com) | |
4 | - Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) | |
5 | - Version: 1.3.1 | |
6 | -*/ | |
7 | -(function(e){function t(){var e=document.createElement("input"),t="onpaste";return e.setAttribute(t,""),"function"==typeof e[t]?"paste":"input"}var n,a=t()+".mask",r=navigator.userAgent,i=/iphone/i.test(r),o=/android/i.test(r);e.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},dataName:"rawMaskFn",placeholder:"_"},e.fn.extend({caret:function(e,t){var n;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof e?(t="number"==typeof t?t:e,this.each(function(){this.setSelectionRange?this.setSelectionRange(e,t):this.createTextRange&&(n=this.createTextRange(),n.collapse(!0),n.moveEnd("character",t),n.moveStart("character",e),n.select())})):(this[0].setSelectionRange?(e=this[0].selectionStart,t=this[0].selectionEnd):document.selection&&document.selection.createRange&&(n=document.selection.createRange(),e=0-n.duplicate().moveStart("character",-1e5),t=e+n.text.length),{begin:e,end:t})},unmask:function(){return this.trigger("unmask")},mask:function(t,r){var c,l,s,u,f,h;return!t&&this.length>0?(c=e(this[0]),c.data(e.mask.dataName)()):(r=e.extend({placeholder:e.mask.placeholder,completed:null},r),l=e.mask.definitions,s=[],u=h=t.length,f=null,e.each(t.split(""),function(e,t){"?"==t?(h--,u=e):l[t]?(s.push(RegExp(l[t])),null===f&&(f=s.length-1)):s.push(null)}),this.trigger("unmask").each(function(){function c(e){for(;h>++e&&!s[e];);return e}function d(e){for(;--e>=0&&!s[e];);return e}function m(e,t){var n,a;if(!(0>e)){for(n=e,a=c(t);h>n;n++)if(s[n]){if(!(h>a&&s[n].test(R[a])))break;R[n]=R[a],R[a]=r.placeholder,a=c(a)}b(),x.caret(Math.max(f,e))}}function p(e){var t,n,a,i;for(t=e,n=r.placeholder;h>t;t++)if(s[t]){if(a=c(t),i=R[t],R[t]=n,!(h>a&&s[a].test(i)))break;n=i}}function g(e){var t,n,a,r=e.which;8===r||46===r||i&&127===r?(t=x.caret(),n=t.begin,a=t.end,0===a-n&&(n=46!==r?d(n):a=c(n-1),a=46===r?c(a):a),k(n,a),m(n,a-1),e.preventDefault()):27==r&&(x.val(S),x.caret(0,y()),e.preventDefault())}function v(t){var n,a,i,l=t.which,u=x.caret();t.ctrlKey||t.altKey||t.metaKey||32>l||l&&(0!==u.end-u.begin&&(k(u.begin,u.end),m(u.begin,u.end-1)),n=c(u.begin-1),h>n&&(a=String.fromCharCode(l),s[n].test(a)&&(p(n),R[n]=a,b(),i=c(n),o?setTimeout(e.proxy(e.fn.caret,x,i),0):x.caret(i),r.completed&&i>=h&&r.completed.call(x))),t.preventDefault())}function k(e,t){var n;for(n=e;t>n&&h>n;n++)s[n]&&(R[n]=r.placeholder)}function b(){x.val(R.join(""))}function y(e){var t,n,a=x.val(),i=-1;for(t=0,pos=0;h>t;t++)if(s[t]){for(R[t]=r.placeholder;pos++<a.length;)if(n=a.charAt(pos-1),s[t].test(n)){R[t]=n,i=t;break}if(pos>a.length)break}else R[t]===a.charAt(pos)&&t!==u&&(pos++,i=t);return e?b():u>i+1?(x.val(""),k(0,h)):(b(),x.val(x.val().substring(0,i+1))),u?t:f}var x=e(this),R=e.map(t.split(""),function(e){return"?"!=e?l[e]?r.placeholder:e:void 0}),S=x.val();x.data(e.mask.dataName,function(){return e.map(R,function(e,t){return s[t]&&e!=r.placeholder?e:null}).join("")}),x.attr("readonly")||x.one("unmask",function(){x.unbind(".mask").removeData(e.mask.dataName)}).bind("focus.mask",function(){clearTimeout(n);var e;S=x.val(),e=y(),n=setTimeout(function(){b(),e==t.length?x.caret(0,e):x.caret(e)},10)}).bind("blur.mask",function(){y(),x.val()!=S&&x.change()}).bind("keydown.mask",g).bind("keypress.mask",v).bind(a,function(){setTimeout(function(){var e=y(!0);x.caret(e),r.completed&&e==x.val().length&&r.completed.call(x)},0)}),y()}))}})})(jQuery); | |
8 | 1 | \ No newline at end of file |
2 | +// jQuery Mask Plugin v1.13.4 | |
3 | +// github.com/igorescobar/jQuery-Mask-Plugin | |
4 | +(function(b){"function"===typeof define&&define.amd?define(["jquery"],b):"object"===typeof exports?module.exports=b(require("jquery")):b(jQuery||Zepto)})(function(b){var y=function(a,c,d){a=b(a);var g=this,k=a.val(),l;c="function"===typeof c?c(a.val(),void 0,a,d):c;var e={invalid:[],getCaret:function(){try{var q,b=0,e=a.get(0),f=document.selection,c=e.selectionStart;if(f&&-1===navigator.appVersion.indexOf("MSIE 10"))q=f.createRange(),q.moveStart("character",a.is("input")?-a.val().length:-a.text().length), | |
5 | +b=q.text.length;else if(c||"0"===c)b=c;return b}catch(d){}},setCaret:function(q){try{if(a.is(":focus")){var b,c=a.get(0);c.setSelectionRange?c.setSelectionRange(q,q):c.createTextRange&&(b=c.createTextRange(),b.collapse(!0),b.moveEnd("character",q),b.moveStart("character",q),b.select())}}catch(f){}},events:function(){a.on("input.mask keyup.mask",e.behaviour).on("paste.mask drop.mask",function(){setTimeout(function(){a.keydown().keyup()},100)}).on("change.mask",function(){a.data("changed",!0)}).on("blur.mask", | |
6 | +function(){k===a.val()||a.data("changed")||a.triggerHandler("change");a.data("changed",!1)}).on("blur.mask",function(){k=a.val()}).on("focus.mask",function(a){!0===d.selectOnFocus&&b(a.target).select()}).on("focusout.mask",function(){d.clearIfNotMatch&&!l.test(e.val())&&e.val("")})},getRegexMask:function(){for(var a=[],b,e,f,d,h=0;h<c.length;h++)(b=g.translation[c.charAt(h)])?(e=b.pattern.toString().replace(/.{1}$|^.{1}/g,""),f=b.optional,(b=b.recursive)?(a.push(c.charAt(h)),d={digit:c.charAt(h), | |
7 | +pattern:e}):a.push(f||b?e+"?":e)):a.push(c.charAt(h).replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"));a=a.join("");d&&(a=a.replace(new RegExp("("+d.digit+"(.*"+d.digit+")?)"),"($1)?").replace(new RegExp(d.digit,"g"),d.pattern));return new RegExp(a)},destroyEvents:function(){a.off("input keydown keyup paste drop blur focusout ".split(" ").join(".mask "))},val:function(b){var c=a.is("input")?"val":"text";if(0<arguments.length){if(a[c]()!==b)a[c](b);c=a}else c=a[c]();return c},getMCharsBeforeCount:function(a, | |
8 | +b){for(var e=0,f=0,d=c.length;f<d&&f<a;f++)g.translation[c.charAt(f)]||(a=b?a+1:a,e++);return e},caretPos:function(a,b,d,f){return g.translation[c.charAt(Math.min(a-1,c.length-1))]?Math.min(a+d-b-f,d):e.caretPos(a+1,b,d,f)},behaviour:function(a){a=a||window.event;e.invalid=[];var c=a.keyCode||a.which;if(-1===b.inArray(c,g.byPassKeys)){var d=e.getCaret(),f=e.val().length,n=d<f,h=e.getMasked(),k=h.length,m=e.getMCharsBeforeCount(k-1)-e.getMCharsBeforeCount(f-1);e.val(h);!n||65===c&&a.ctrlKey||(8!== | |
9 | +c&&46!==c&&(d=e.caretPos(d,f,k,m)),e.setCaret(d));return e.callbacks(a)}},getMasked:function(a){var b=[],k=e.val(),f=0,n=c.length,h=0,l=k.length,m=1,p="push",u=-1,t,w;d.reverse?(p="unshift",m=-1,t=0,f=n-1,h=l-1,w=function(){return-1<f&&-1<h}):(t=n-1,w=function(){return f<n&&h<l});for(;w();){var x=c.charAt(f),v=k.charAt(h),r=g.translation[x];if(r)v.match(r.pattern)?(b[p](v),r.recursive&&(-1===u?u=f:f===t&&(f=u-m),t===u&&(f-=m)),f+=m):r.optional?(f+=m,h-=m):r.fallback?(b[p](r.fallback),f+=m,h-=m):e.invalid.push({p:h, | |
10 | +v:v,e:r.pattern}),h+=m;else{if(!a)b[p](x);v===x&&(h+=m);f+=m}}a=c.charAt(t);n!==l+1||g.translation[a]||b.push(a);return b.join("")},callbacks:function(b){var g=e.val(),l=g!==k,f=[g,b,a,d],n=function(a,b,c){"function"===typeof d[a]&&b&&d[a].apply(this,c)};n("onChange",!0===l,f);n("onKeyPress",!0===l,f);n("onComplete",g.length===c.length,f);n("onInvalid",0<e.invalid.length,[g,b,a,e.invalid,d])}};g.mask=c;g.options=d;g.remove=function(){var b=e.getCaret();e.destroyEvents();e.val(g.getCleanVal());e.setCaret(b- | |
11 | +e.getMCharsBeforeCount(b));return a};g.getCleanVal=function(){return e.getMasked(!0)};g.init=function(c){c=c||!1;d=d||{};g.byPassKeys=b.jMaskGlobals.byPassKeys;g.translation=b.jMaskGlobals.translation;g.translation=b.extend({},g.translation,d.translation);g=b.extend(!0,{},g,d);l=e.getRegexMask();!1===c?(d.placeholder&&a.attr("placeholder",d.placeholder),b("input").length&&!1==="oninput"in b("input")[0]&&"on"===a.attr("autocomplete")&&a.attr("autocomplete","off"),e.destroyEvents(),e.events(),c=e.getCaret(), | |
12 | +e.val(e.getMasked()),e.setCaret(c+e.getMCharsBeforeCount(c,!0))):(e.events(),e.val(e.getMasked()))};g.init(!a.is("input"))};b.maskWatchers={};var A=function(){var a=b(this),c={},d=a.attr("data-mask");a.attr("data-mask-reverse")&&(c.reverse=!0);a.attr("data-mask-clearifnotmatch")&&(c.clearIfNotMatch=!0);"true"===a.attr("data-mask-selectonfocus")&&(c.selectOnFocus=!0);if(z(a,d,c))return a.data("mask",new y(this,d,c))},z=function(a,c,d){d=d||{};var g=b(a).data("mask"),k=JSON.stringify;a=b(a).val()|| | |
13 | +b(a).text();try{return"function"===typeof c&&(c=c(a)),"object"!==typeof g||k(g.options)!==k(d)||g.mask!==c}catch(l){}};b.fn.mask=function(a,c){c=c||{};var d=this.selector,g=b.jMaskGlobals,k=b.jMaskGlobals.watchInterval,l=function(){if(z(this,a,c))return b(this).data("mask",new y(this,a,c))};b(this).each(l);d&&""!==d&&g.watchInputs&&(clearInterval(b.maskWatchers[d]),b.maskWatchers[d]=setInterval(function(){b(document).find(d).each(l)},k));return this};b.fn.unmask=function(){clearInterval(b.maskWatchers[this.selector]); | |
14 | +delete b.maskWatchers[this.selector];return this.each(function(){var a=b(this).data("mask");a&&a.remove().removeData("mask")})};b.fn.cleanVal=function(){return this.data("mask").getCleanVal()};b.applyDataMask=function(a){a=a||b.jMaskGlobals.maskElements;(a instanceof b?a:b(a)).filter(b.jMaskGlobals.dataMaskAttr).each(A)};var p={maskElements:"input,td,span,div",dataMaskAttr:"*[data-mask]",dataMask:!0,watchInterval:300,watchInputs:!0,watchDataMask:!1,byPassKeys:[9,16,17,18,36,37,38,39,40,91],translation:{0:{pattern:/\d/}, | |
15 | +9:{pattern:/\d/,optional:!0},"#":{pattern:/\d/,recursive:!0},A:{pattern:/[a-zA-Z0-9]/},S:{pattern:/[a-zA-Z]/}}};b.jMaskGlobals=b.jMaskGlobals||{};p=b.jMaskGlobals=b.extend(!0,{},p,b.jMaskGlobals);p.dataMask&&b.applyDataMask();setInterval(function(){b.jMaskGlobals.watchDataMask&&b.applyDataMask()},p.watchInterval)}); | |
16 | + | ... | ... |
src/noosfero-spb/software_communities/public/views/comments-software-extra-fields.js
... | ... | @@ -15,6 +15,24 @@ modulejs.define('CommentsSoftwareExtraFields', ['jquery'], function($) { |
15 | 15 | $(".comments-software-extra-fields div").hide(); |
16 | 16 | } |
17 | 17 | }); |
18 | + var organization_rating_saved_value = $("#organization_rating_saved_value"); | |
19 | + var organization_rating_people_benefited = $("#organization_rating_people_benefited"); | |
20 | + var people_benefited_tmp = $("#people_benefited_tmp"); | |
21 | + var saved_value_tmp = $("#saved_value_tmp"); | |
22 | + | |
23 | + saved_value_tmp.mask("#.##0,00", {reverse: true}); | |
24 | + people_benefited_tmp.mask("000.000.000", {reverse: true}); | |
25 | + | |
26 | + organization_rating_saved_value.closest("form").submit(function( event ) { | |
27 | + var unformated_saved_value = saved_value_tmp.val(); | |
28 | + unformated_saved_value = unformated_saved_value.split(".").join(""); | |
29 | + unformated_saved_value = unformated_saved_value.replace(",","."); | |
30 | + organization_rating_saved_value.val(unformated_saved_value); | |
31 | + | |
32 | + var unformated_people_benefited = people_benefited_tmp.val(); | |
33 | + unformated_people_benefited = unformated_people_benefited.split(".").join(""); | |
34 | + organization_rating_people_benefited.val(unformated_people_benefited); | |
35 | + }); | |
18 | 36 | } |
19 | 37 | |
20 | 38 | return { | ... | ... |
src/noosfero-spb/software_communities/views/comments_extra_fields.html.erb
... | ... | @@ -10,12 +10,14 @@ |
10 | 10 | <div class="comments-software-people-benefited"> |
11 | 11 | <%= label_tag "comments_people_benefited", _("Number of Beneficiaries")%> |
12 | 12 | <span class="star-tooltip" title="Quantidade de pessoas beneficiadas com a utilização do software"></span> |
13 | - <%= text_field_tag "organization_rating[people_benefited]", "" %> | |
13 | + <%= text_field_tag "people_benefited_tmp", "" %> | |
14 | + <%= hidden_field_tag "organization_rating[people_benefited]", "" %> | |
14 | 15 | </div> |
15 | 16 | |
16 | 17 | <div class="comments-software-saved-values"> |
17 | - <%= label_tag "comments_saved_value", _("Saved resources")%> | |
18 | + <%= label_tag "comments_saved_value", _("Saved Resources")%> | |
18 | 19 | <span class="star-tooltip" title="Valores em “Real” economizados com a utilização do software"></span> |
19 | - <%= text_field_tag "organization_rating[saved_value]", "", :placeholder=>"R$"%> | |
20 | + <%= text_field_tag "saved_value_tmp", "", :placeholder=>"R$" %> | |
21 | + <%= hidden_field_tag "organization_rating[saved_value]","" %> | |
20 | 22 | </div> |
21 | 23 | </div> | ... | ... |
src/noosfero-spb/software_communities/views/organization_ratings_extra_fields_show_data.html.erb
1 | 1 | <div class="aditional-informations"> |
2 | 2 | <div class="comments-people-benefited"> |
3 | - <span><%=_("Benefited People")%> :</span> <%= user_rating.people_benefited unless user_rating.nil? %> | |
3 | + <span><%=_("Benefited People")%>:</span> <%= number_with_delimiter(user_rating.people_benefited, :separator => environment.currency_separator, :delimiter => environment.currency_delimiter) unless user_rating.nil? %> | |
4 | 4 | </div> |
5 | 5 | |
6 | 6 | <div class="comments-saved-value"> |
7 | - <span><%=_("Saved Resources")%> :</span> <%= user_rating.saved_value unless user_rating.nil? %> | |
7 | + <span><%=_("Saved Resources")%>:</span> <%= float_to_currency(user_rating.saved_value) unless user_rating.nil? %> | |
8 | 8 | </div> |
9 | 9 | </div> |
10 | 10 | ... | ... |