lol_multiple_uploads 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/lol_multiple_uploads/jquery.form.js +7 -0
- data/app/assets/javascripts/lol_multiple_uploads/upload.js +10 -23
- data/app/assets/stylesheets/lol_multiple_uploads/base.css +2 -1
- data/app/helpers/image_helper.rb +1 -1
- data/app/models/photo.rb +5 -0
- data/app/views/layouts/lol_multiple_uploads/_photo-caption-localized.html.erb +7 -0
- data/app/views/layouts/lol_multiple_uploads/_photo.html.erb +4 -1
- data/lib/lol_multiple_uploads/version.rb +1 -1
- data/lib/mongoid/lol_multiple_images.rb +4 -20
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f771b9e0a45b3b4f12c0d041d7e06d11b13da2cf
|
4
|
+
data.tar.gz: fe31b3d5d86dc91e339ada160876dede4cd04fac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 854aaa45fa09fd4c6a4dcaf5088846701924ddc5136bcb73be07a79fc65823806b21b7892ccf750f8829e87df8aab41b163fa0bb029f12b7d3a1d919445b9d37
|
7
|
+
data.tar.gz: 4f4e13aaadcb5732bd8e88e6aaeac62f4bac3e4ed76e16c49e4da3f2c40a2ea4b2300e09adb47644e028be0dcf043dae0f44a48c4092d6a429aeee4836658d5c
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery Form Plugin; v20131121
|
3
|
+
* http://jquery.malsup.com/form/
|
4
|
+
* Copyright (c) 2013 M. Alsup; Dual licensed: MIT/GPL
|
5
|
+
* https://github.com/malsup/form#copyright-and-license
|
6
|
+
*/
|
7
|
+
;(function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e("undefined"!=typeof jQuery?jQuery:window.Zepto)})(function(e){"use strict";function t(t){var r=t.data;t.isDefaultPrevented()||(t.preventDefault(),e(t.target).ajaxSubmit(r))}function r(t){var r=t.target,a=e(r);if(!a.is("[type=submit],[type=image]")){var n=a.closest("[type=submit]");if(0===n.length)return;r=n[0]}var i=this;if(i.clk=r,"image"==r.type)if(void 0!==t.offsetX)i.clk_x=t.offsetX,i.clk_y=t.offsetY;else if("function"==typeof e.fn.offset){var o=a.offset();i.clk_x=t.pageX-o.left,i.clk_y=t.pageY-o.top}else i.clk_x=t.pageX-r.offsetLeft,i.clk_y=t.pageY-r.offsetTop;setTimeout(function(){i.clk=i.clk_x=i.clk_y=null},100)}function a(){if(e.fn.ajaxSubmit.debug){var t="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(t):window.opera&&window.opera.postError&&window.opera.postError(t)}}var n={};n.fileapi=void 0!==e("<input type='file'/>").get(0).files,n.formdata=void 0!==window.FormData;var i=!!e.fn.prop;e.fn.attr2=function(){if(!i)return this.attr.apply(this,arguments);var e=this.prop.apply(this,arguments);return e&&e.jquery||"string"==typeof e?e:this.attr.apply(this,arguments)},e.fn.ajaxSubmit=function(t){function r(r){var a,n,i=e.param(r,t.traditional).split("&"),o=i.length,s=[];for(a=0;o>a;a++)i[a]=i[a].replace(/\+/g," "),n=i[a].split("="),s.push([decodeURIComponent(n[0]),decodeURIComponent(n[1])]);return s}function o(a){for(var n=new FormData,i=0;a.length>i;i++)n.append(a[i].name,a[i].value);if(t.extraData){var o=r(t.extraData);for(i=0;o.length>i;i++)o[i]&&n.append(o[i][0],o[i][1])}t.data=null;var s=e.extend(!0,{},e.ajaxSettings,t,{contentType:!1,processData:!1,cache:!1,type:u||"POST"});t.uploadProgress&&(s.xhr=function(){var r=e.ajaxSettings.xhr();return r.upload&&r.upload.addEventListener("progress",function(e){var r=0,a=e.loaded||e.position,n=e.total;e.lengthComputable&&(r=Math.ceil(100*(a/n))),t.uploadProgress(e,a,n,r)},!1),r}),s.data=null;var c=s.beforeSend;return s.beforeSend=function(e,r){r.data=t.formData?t.formData:n,c&&c.call(this,e,r)},e.ajax(s)}function s(r){function n(e){var t=null;try{e.contentWindow&&(t=e.contentWindow.document)}catch(r){a("cannot get iframe.contentWindow document: "+r)}if(t)return t;try{t=e.contentDocument?e.contentDocument:e.document}catch(r){a("cannot get iframe.contentDocument: "+r),t=e.document}return t}function o(){function t(){try{var e=n(g).readyState;a("state = "+e),e&&"uninitialized"==e.toLowerCase()&&setTimeout(t,50)}catch(r){a("Server abort: ",r," (",r.name,")"),s(k),j&&clearTimeout(j),j=void 0}}var r=f.attr2("target"),i=f.attr2("action");w.setAttribute("target",p),(!u||/post/i.test(u))&&w.setAttribute("method","POST"),i!=m.url&&w.setAttribute("action",m.url),m.skipEncodingOverride||u&&!/post/i.test(u)||f.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),m.timeout&&(j=setTimeout(function(){T=!0,s(D)},m.timeout));var o=[];try{if(m.extraData)for(var c in m.extraData)m.extraData.hasOwnProperty(c)&&(e.isPlainObject(m.extraData[c])&&m.extraData[c].hasOwnProperty("name")&&m.extraData[c].hasOwnProperty("value")?o.push(e('<input type="hidden" name="'+m.extraData[c].name+'">').val(m.extraData[c].value).appendTo(w)[0]):o.push(e('<input type="hidden" name="'+c+'">').val(m.extraData[c]).appendTo(w)[0]));m.iframeTarget||v.appendTo("body"),g.attachEvent?g.attachEvent("onload",s):g.addEventListener("load",s,!1),setTimeout(t,15);try{w.submit()}catch(l){var d=document.createElement("form").submit;d.apply(w)}}finally{w.setAttribute("action",i),r?w.setAttribute("target",r):f.removeAttr("target"),e(o).remove()}}function s(t){if(!x.aborted&&!F){if(M=n(g),M||(a("cannot access response document"),t=k),t===D&&x)return x.abort("timeout"),S.reject(x,"timeout"),void 0;if(t==k&&x)return x.abort("server abort"),S.reject(x,"error","server abort"),void 0;if(M&&M.location.href!=m.iframeSrc||T){g.detachEvent?g.detachEvent("onload",s):g.removeEventListener("load",s,!1);var r,i="success";try{if(T)throw"timeout";var o="xml"==m.dataType||M.XMLDocument||e.isXMLDoc(M);if(a("isXml="+o),!o&&window.opera&&(null===M.body||!M.body.innerHTML)&&--O)return a("requeing onLoad callback, DOM not available"),setTimeout(s,250),void 0;var u=M.body?M.body:M.documentElement;x.responseText=u?u.innerHTML:null,x.responseXML=M.XMLDocument?M.XMLDocument:M,o&&(m.dataType="xml"),x.getResponseHeader=function(e){var t={"content-type":m.dataType};return t[e.toLowerCase()]},u&&(x.status=Number(u.getAttribute("status"))||x.status,x.statusText=u.getAttribute("statusText")||x.statusText);var c=(m.dataType||"").toLowerCase(),l=/(json|script|text)/.test(c);if(l||m.textarea){var f=M.getElementsByTagName("textarea")[0];if(f)x.responseText=f.value,x.status=Number(f.getAttribute("status"))||x.status,x.statusText=f.getAttribute("statusText")||x.statusText;else if(l){var p=M.getElementsByTagName("pre")[0],h=M.getElementsByTagName("body")[0];p?x.responseText=p.textContent?p.textContent:p.innerText:h&&(x.responseText=h.textContent?h.textContent:h.innerText)}}else"xml"==c&&!x.responseXML&&x.responseText&&(x.responseXML=X(x.responseText));try{E=_(x,c,m)}catch(b){i="parsererror",x.error=r=b||i}}catch(b){a("error caught: ",b),i="error",x.error=r=b||i}x.aborted&&(a("upload aborted"),i=null),x.status&&(i=x.status>=200&&300>x.status||304===x.status?"success":"error"),"success"===i?(m.success&&m.success.call(m.context,E,"success",x),S.resolve(x.responseText,"success",x),d&&e.event.trigger("ajaxSuccess",[x,m])):i&&(void 0===r&&(r=x.statusText),m.error&&m.error.call(m.context,x,i,r),S.reject(x,"error",r),d&&e.event.trigger("ajaxError",[x,m,r])),d&&e.event.trigger("ajaxComplete",[x,m]),d&&!--e.active&&e.event.trigger("ajaxStop"),m.complete&&m.complete.call(m.context,x,i),F=!0,m.timeout&&clearTimeout(j),setTimeout(function(){m.iframeTarget?v.attr("src",m.iframeSrc):v.remove(),x.responseXML=null},100)}}}var c,l,m,d,p,v,g,x,b,y,T,j,w=f[0],S=e.Deferred();if(S.abort=function(e){x.abort(e)},r)for(l=0;h.length>l;l++)c=e(h[l]),i?c.prop("disabled",!1):c.removeAttr("disabled");if(m=e.extend(!0,{},e.ajaxSettings,t),m.context=m.context||m,p="jqFormIO"+(new Date).getTime(),m.iframeTarget?(v=e(m.iframeTarget),y=v.attr2("name"),y?p=y:v.attr2("name",p)):(v=e('<iframe name="'+p+'" src="'+m.iframeSrc+'" />'),v.css({position:"absolute",top:"-1000px",left:"-1000px"})),g=v[0],x={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(t){var r="timeout"===t?"timeout":"aborted";a("aborting upload... "+r),this.aborted=1;try{g.contentWindow.document.execCommand&&g.contentWindow.document.execCommand("Stop")}catch(n){}v.attr("src",m.iframeSrc),x.error=r,m.error&&m.error.call(m.context,x,r,t),d&&e.event.trigger("ajaxError",[x,m,r]),m.complete&&m.complete.call(m.context,x,r)}},d=m.global,d&&0===e.active++&&e.event.trigger("ajaxStart"),d&&e.event.trigger("ajaxSend",[x,m]),m.beforeSend&&m.beforeSend.call(m.context,x,m)===!1)return m.global&&e.active--,S.reject(),S;if(x.aborted)return S.reject(),S;b=w.clk,b&&(y=b.name,y&&!b.disabled&&(m.extraData=m.extraData||{},m.extraData[y]=b.value,"image"==b.type&&(m.extraData[y+".x"]=w.clk_x,m.extraData[y+".y"]=w.clk_y)));var D=1,k=2,A=e("meta[name=csrf-token]").attr("content"),L=e("meta[name=csrf-param]").attr("content");L&&A&&(m.extraData=m.extraData||{},m.extraData[L]=A),m.forceSync?o():setTimeout(o,10);var E,M,F,O=50,X=e.parseXML||function(e,t){return window.ActiveXObject?(t=new ActiveXObject("Microsoft.XMLDOM"),t.async="false",t.loadXML(e)):t=(new DOMParser).parseFromString(e,"text/xml"),t&&t.documentElement&&"parsererror"!=t.documentElement.nodeName?t:null},C=e.parseJSON||function(e){return window.eval("("+e+")")},_=function(t,r,a){var n=t.getResponseHeader("content-type")||"",i="xml"===r||!r&&n.indexOf("xml")>=0,o=i?t.responseXML:t.responseText;return i&&"parsererror"===o.documentElement.nodeName&&e.error&&e.error("parsererror"),a&&a.dataFilter&&(o=a.dataFilter(o,r)),"string"==typeof o&&("json"===r||!r&&n.indexOf("json")>=0?o=C(o):("script"===r||!r&&n.indexOf("javascript")>=0)&&e.globalEval(o)),o};return S}if(!this.length)return a("ajaxSubmit: skipping submit process - no element selected"),this;var u,c,l,f=this;"function"==typeof t?t={success:t}:void 0===t&&(t={}),u=t.type||this.attr2("method"),c=t.url||this.attr2("action"),l="string"==typeof c?e.trim(c):"",l=l||window.location.href||"",l&&(l=(l.match(/^([^#]+)/)||[])[1]),t=e.extend(!0,{url:l,success:e.ajaxSettings.success,type:u||e.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},t);var m={};if(this.trigger("form-pre-serialize",[this,t,m]),m.veto)return a("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(t.beforeSerialize&&t.beforeSerialize(this,t)===!1)return a("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var d=t.traditional;void 0===d&&(d=e.ajaxSettings.traditional);var p,h=[],v=this.formToArray(t.semantic,h);if(t.data&&(t.extraData=t.data,p=e.param(t.data,d)),t.beforeSubmit&&t.beforeSubmit(v,this,t)===!1)return a("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[v,this,t,m]),m.veto)return a("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var g=e.param(v,d);p&&(g=g?g+"&"+p:p),"GET"==t.type.toUpperCase()?(t.url+=(t.url.indexOf("?")>=0?"&":"?")+g,t.data=null):t.data=g;var x=[];if(t.resetForm&&x.push(function(){f.resetForm()}),t.clearForm&&x.push(function(){f.clearForm(t.includeHidden)}),!t.dataType&&t.target){var b=t.success||function(){};x.push(function(r){var a=t.replaceTarget?"replaceWith":"html";e(t.target)[a](r).each(b,arguments)})}else t.success&&x.push(t.success);if(t.success=function(e,r,a){for(var n=t.context||this,i=0,o=x.length;o>i;i++)x[i].apply(n,[e,r,a||f,f])},t.error){var y=t.error;t.error=function(e,r,a){var n=t.context||this;y.apply(n,[e,r,a,f])}}if(t.complete){var T=t.complete;t.complete=function(e,r){var a=t.context||this;T.apply(a,[e,r,f])}}var j=e("input[type=file]:enabled",this).filter(function(){return""!==e(this).val()}),w=j.length>0,S="multipart/form-data",D=f.attr("enctype")==S||f.attr("encoding")==S,k=n.fileapi&&n.formdata;a("fileAPI :"+k);var A,L=(w||D)&&!k;t.iframe!==!1&&(t.iframe||L)?t.closeKeepAlive?e.get(t.closeKeepAlive,function(){A=s(v)}):A=s(v):A=(w||D)&&k?o(v):e.ajax(t),f.removeData("jqxhr").data("jqxhr",A);for(var E=0;h.length>E;E++)h[E]=null;return this.trigger("form-submit-notify",[this,t]),this},e.fn.ajaxForm=function(n){if(n=n||{},n.delegation=n.delegation&&e.isFunction(e.fn.on),!n.delegation&&0===this.length){var i={s:this.selector,c:this.context};return!e.isReady&&i.s?(a("DOM not ready, queuing ajaxForm"),e(function(){e(i.s,i.c).ajaxForm(n)}),this):(a("terminating; zero elements found by selector"+(e.isReady?"":" (DOM not ready)")),this)}return n.delegation?(e(document).off("submit.form-plugin",this.selector,t).off("click.form-plugin",this.selector,r).on("submit.form-plugin",this.selector,n,t).on("click.form-plugin",this.selector,n,r),this):this.ajaxFormUnbind().bind("submit.form-plugin",n,t).bind("click.form-plugin",n,r)},e.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")},e.fn.formToArray=function(t,r){var a=[];if(0===this.length)return a;var i=this[0],o=t?i.getElementsByTagName("*"):i.elements;if(!o)return a;var s,u,c,l,f,m,d;for(s=0,m=o.length;m>s;s++)if(f=o[s],c=f.name,c&&!f.disabled)if(t&&i.clk&&"image"==f.type)i.clk==f&&(a.push({name:c,value:e(f).val(),type:f.type}),a.push({name:c+".x",value:i.clk_x},{name:c+".y",value:i.clk_y}));else if(l=e.fieldValue(f,!0),l&&l.constructor==Array)for(r&&r.push(f),u=0,d=l.length;d>u;u++)a.push({name:c,value:l[u]});else if(n.fileapi&&"file"==f.type){r&&r.push(f);var p=f.files;if(p.length)for(u=0;p.length>u;u++)a.push({name:c,value:p[u],type:f.type});else a.push({name:c,value:"",type:f.type})}else null!==l&&l!==void 0&&(r&&r.push(f),a.push({name:c,value:l,type:f.type,required:f.required}));if(!t&&i.clk){var h=e(i.clk),v=h[0];c=v.name,c&&!v.disabled&&"image"==v.type&&(a.push({name:c,value:h.val()}),a.push({name:c+".x",value:i.clk_x},{name:c+".y",value:i.clk_y}))}return a},e.fn.formSerialize=function(t){return e.param(this.formToArray(t))},e.fn.fieldSerialize=function(t){var r=[];return this.each(function(){var a=this.name;if(a){var n=e.fieldValue(this,t);if(n&&n.constructor==Array)for(var i=0,o=n.length;o>i;i++)r.push({name:a,value:n[i]});else null!==n&&n!==void 0&&r.push({name:this.name,value:n})}}),e.param(r)},e.fn.fieldValue=function(t){for(var r=[],a=0,n=this.length;n>a;a++){var i=this[a],o=e.fieldValue(i,t);null===o||void 0===o||o.constructor==Array&&!o.length||(o.constructor==Array?e.merge(r,o):r.push(o))}return r},e.fieldValue=function(t,r){var a=t.name,n=t.type,i=t.tagName.toLowerCase();if(void 0===r&&(r=!0),r&&(!a||t.disabled||"reset"==n||"button"==n||("checkbox"==n||"radio"==n)&&!t.checked||("submit"==n||"image"==n)&&t.form&&t.form.clk!=t||"select"==i&&-1==t.selectedIndex))return null;if("select"==i){var o=t.selectedIndex;if(0>o)return null;for(var s=[],u=t.options,c="select-one"==n,l=c?o+1:u.length,f=c?o:0;l>f;f++){var m=u[f];if(m.selected){var d=m.value;if(d||(d=m.attributes&&m.attributes.value&&!m.attributes.value.specified?m.text:m.value),c)return d;s.push(d)}}return s}return e(t).val()},e.fn.clearForm=function(t){return this.each(function(){e("input,select,textarea",this).clearFields(t)})},e.fn.clearFields=e.fn.clearInputs=function(t){var r=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;return this.each(function(){var a=this.type,n=this.tagName.toLowerCase();r.test(a)||"textarea"==n?this.value="":"checkbox"==a||"radio"==a?this.checked=!1:"select"==n?this.selectedIndex=-1:"file"==a?/MSIE/.test(navigator.userAgent)?e(this).replaceWith(e(this).clone(!0)):e(this).val(""):t&&(t===!0&&/hidden/.test(a)||"string"==typeof t&&e(this).is(t))&&(this.value="")})},e.fn.resetForm=function(){return this.each(function(){("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})},e.fn.enable=function(e){return void 0===e&&(e=!0),this.each(function(){this.disabled=!e})},e.fn.selected=function(t){return void 0===t&&(t=!0),this.each(function(){var r=this.type;if("checkbox"==r||"radio"==r)this.checked=t;else if("option"==this.tagName.toLowerCase()){var a=e(this).parent("select");t&&a[0]&&"select-one"==a[0].type&&a.find("option").selected(!1),this.selected=t}})},e.fn.ajaxSubmit.debug=!1});
|
@@ -10,9 +10,10 @@ $(document).ready(function() {
|
|
10
10
|
});
|
11
11
|
|
12
12
|
var imageContainerManager = function(){
|
13
|
-
var _this
|
14
|
-
this.$container
|
15
|
-
this.hasCaption
|
13
|
+
var _this = this;
|
14
|
+
this.$container = $('.lol-multiple-uploads.images-container');
|
15
|
+
this.hasCaption = Boolean(this.$container.data('has-caption'));
|
16
|
+
this.hasCaptionLocalized = Boolean(this.$container.data('has-caption-localized'));
|
16
17
|
|
17
18
|
this.startup = function(){
|
18
19
|
this.$container.on('click', 'figure a.delete', function(event) {
|
@@ -20,7 +21,7 @@ var imageContainerManager = function(){
|
|
20
21
|
return false;
|
21
22
|
});
|
22
23
|
|
23
|
-
if (this.hasCaption){
|
24
|
+
if (this.hasCaption || this.hasCaptionLocalized){
|
24
25
|
new imageCaptionManager(this.$container);
|
25
26
|
};
|
26
27
|
},
|
@@ -57,28 +58,14 @@ var imageCaptionManager = function($container){
|
|
57
58
|
this.startup = function(){
|
58
59
|
this.$container.on('focusout', 'figure textarea', function(event) {
|
59
60
|
event.preventDefault();
|
60
|
-
var field = $(this);
|
61
|
-
|
61
|
+
var $field = $(this);
|
62
|
+
var $form = $field.closest('form');
|
63
|
+
_this.updateImageCaption($form);
|
62
64
|
});
|
63
65
|
},
|
64
66
|
|
65
|
-
this.updateImageCaption = function(
|
66
|
-
|
67
|
-
url: '/update-image/'+image_id,
|
68
|
-
type: 'PUT',
|
69
|
-
dataType: 'json',
|
70
|
-
data: {photo: {caption: text}},
|
71
|
-
})
|
72
|
-
.done(function() {
|
73
|
-
console.log("success");
|
74
|
-
})
|
75
|
-
.fail(function() {
|
76
|
-
console.log("error");
|
77
|
-
})
|
78
|
-
.always(function() {
|
79
|
-
console.log("complete");
|
80
|
-
});
|
81
|
-
|
67
|
+
this.updateImageCaption = function($form){
|
68
|
+
$form.ajaxSubmit();
|
82
69
|
}
|
83
70
|
|
84
71
|
this.startup();
|
@@ -66,7 +66,8 @@
|
|
66
66
|
max-width: 100%;
|
67
67
|
}
|
68
68
|
|
69
|
-
.lol-multiple-uploads.images-container[data-has-caption="true"] figure textarea
|
69
|
+
.lol-multiple-uploads.images-container[data-has-caption="true"] figure textarea,
|
70
|
+
.lol-multiple-uploads.images-container[data-has-caption-localized="true"] figure textarea{
|
70
71
|
border: 1px solid #cacaca;
|
71
72
|
width: 114px;
|
72
73
|
}
|
data/app/helpers/image_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ImageHelper
|
2
2
|
|
3
3
|
def list_photos(resource, photo_version=:gallery_thumb)
|
4
|
-
content_tag(:div, class: 'lol-multiple-uploads images-container is-sortable', 'data-resource' => 'photo', 'data-has-caption' => resource.class.caption_status) do
|
4
|
+
content_tag(:div, class: 'lol-multiple-uploads images-container is-sortable', 'data-resource' => 'photo', 'data-has-caption' => resource.class.caption_status, 'data-has-caption-localized' => resource.class.caption_localized_status) do
|
5
5
|
render partial: '/layouts/lol_multiple_uploads/photo', collection: resource.photos.prioritized, locals: {photo_version: photo_version}
|
6
6
|
end
|
7
7
|
end
|
data/app/models/photo.rb
CHANGED
@@ -10,10 +10,15 @@ class Photo
|
|
10
10
|
validates :photable, presence: true
|
11
11
|
|
12
12
|
field :caption
|
13
|
+
field :caption_localized, localize: true
|
13
14
|
|
14
15
|
validates :caption, presence: true, if: :has_caption?, on: :update
|
15
16
|
|
16
17
|
def has_caption?
|
17
18
|
self.photable.present? && self.photable.caption_status
|
18
19
|
end
|
20
|
+
|
21
|
+
def has_caption_localized?
|
22
|
+
self.photable.present? && self.photable.caption_localized_status
|
23
|
+
end
|
19
24
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<%= form_for photo, url: update_image_path(photo) do |f|%>
|
2
|
+
<% locales.each do |locale| %>
|
3
|
+
<%= f.fields_for "caption_localized_translations", OpenStruct.new(f.object.send('caption_localized_translations')) do |ff| %>
|
4
|
+
<%= ff.text_area locale, placeholder: locale, rows: 3 %>
|
5
|
+
<% end %>
|
6
|
+
<% end %>
|
7
|
+
<% end %>
|
@@ -1,6 +1,9 @@
|
|
1
1
|
<figure data-id="<%= photo.id %>">
|
2
2
|
<%= image_tag(photo.image.send(photo_version).url)%>
|
3
|
+
|
3
4
|
<%= link_to "Remover", remove_image_path(photo, format: 'json'), method: :delete, class: :delete%>
|
4
5
|
<%= link_to image_tag('lol_multiple_uploads/maximize.png'), photo.image.url, class: 'maximize', target: :blank %>
|
5
|
-
|
6
|
+
|
7
|
+
<%= render partial: '/layouts/lol_multiple_uploads/photo-caption' , locals: {photo: photo} if photo.has_caption? %>
|
8
|
+
<%= render partial: '/layouts/lol_multiple_uploads/photo-caption-localized', locals: {photo: photo, locales: photo.photable.available_locales} if photo.has_caption_localized? %>
|
6
9
|
</figure>
|
@@ -1,34 +1,18 @@
|
|
1
|
-
# module Mongoid
|
2
|
-
# module LolMultipleImages
|
3
|
-
# extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
# included do
|
6
|
-
# cattr_accessor :caption_status
|
7
|
-
|
8
|
-
# has_many :photos, as: :photable
|
9
|
-
# end
|
10
|
-
|
11
|
-
# module ClassMethods
|
12
|
-
# def images_caption(option=false)
|
13
|
-
# self.caption_status = option
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
# end
|
18
|
-
|
19
1
|
module Mongoid
|
20
2
|
module LolMultipleImages
|
21
3
|
extend ActiveSupport::Concern
|
22
4
|
|
23
5
|
included do
|
24
|
-
cattr_accessor :caption_status
|
6
|
+
cattr_accessor :caption_status, :caption_localized_status, :available_locales
|
25
7
|
|
26
8
|
has_many :photos, as: :photable
|
27
9
|
end
|
28
10
|
|
29
11
|
module ClassMethods
|
30
12
|
def multiple_uploads(option={})
|
31
|
-
self.caption_status
|
13
|
+
self.caption_status = option[:caption] || false # config
|
14
|
+
self.caption_localized_status = option[:caption_localized] || false
|
15
|
+
self.available_locales = option[:available_locales] || I18n.available_locales
|
32
16
|
end
|
33
17
|
end
|
34
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lol_multiple_uploads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Zaghi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -104,6 +104,7 @@ extra_rdoc_files: []
|
|
104
104
|
files:
|
105
105
|
- app/assets/images/lol_multiple_uploads/loading.gif
|
106
106
|
- app/assets/images/lol_multiple_uploads/maximize.png
|
107
|
+
- app/assets/javascripts/lol_multiple_uploads/jquery.form.js
|
107
108
|
- app/assets/javascripts/lol_multiple_uploads/upload.js
|
108
109
|
- app/assets/stylesheets/lol_multiple_uploads/base.css
|
109
110
|
- app/controllers/photos_controller.rb
|
@@ -111,6 +112,7 @@ files:
|
|
111
112
|
- app/helpers/upload_helper.rb
|
112
113
|
- app/models/photo.rb
|
113
114
|
- app/uploaders/image_uploader.rb
|
115
|
+
- app/views/layouts/lol_multiple_uploads/_photo-caption-localized.html.erb
|
114
116
|
- app/views/layouts/lol_multiple_uploads/_photo-caption.html.erb
|
115
117
|
- app/views/layouts/lol_multiple_uploads/_photo.html.erb
|
116
118
|
- config/initializers/init_lol_multiple_uploads.rb
|