effective_assets 0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +1 -1
- data/README.md +341 -72
- data/app/assets/javascripts/effective/snippets/effective_asset.js.coffee +53 -0
- data/app/assets/javascripts/effective_assets.js +4 -0
- data/app/assets/javascripts/effective_assets/asset_box.js.coffee +36 -0
- data/app/assets/javascripts/effective_assets/asset_box_dialog.js.coffee +49 -0
- data/app/assets/javascripts/effective_assets/asset_box_drag_and_drop.js.coffee +2 -0
- data/app/assets/javascripts/effective_assets/asset_box_filtering.js.coffee +16 -0
- data/app/assets/javascripts/effective_assets/asset_box_sorting.js.coffee +8 -0
- data/app/assets/javascripts/effective_assets/jquery_ui_sortable.js +813 -585
- data/app/assets/javascripts/effective_assets/s3_uploader.js.coffee +268 -0
- data/app/assets/javascripts/effective_assets_iframe.js.coffee +28 -0
- data/app/assets/stylesheets/active_admin/effective_assets.css.scss +57 -0
- data/app/assets/stylesheets/effective_assets/_asset_box_input.scss +54 -175
- data/app/assets/stylesheets/effective_assets/_iframe_bootstrap.scss +1714 -0
- data/app/assets/stylesheets/effective_assets/_input_bootstrap.scss +508 -0
- data/app/assets/stylesheets/effective_assets_iframe.css.scss +23 -0
- data/app/controllers/effective/assets_controller.rb +41 -0
- data/app/controllers/effective/s3_uploads_controller.rb +58 -74
- data/app/helpers/effective_assets_helper.rb +30 -14
- data/app/helpers/effective_assets_s3_helper.rb +69 -0
- data/app/models/concerns/acts_as_asset_box.rb +75 -11
- data/app/models/effective/access_denied.rb +17 -0
- data/app/models/effective/asset.rb +130 -93
- data/app/models/effective/attachment.rb +2 -7
- data/app/models/effective/delayed_job.rb +33 -78
- data/app/models/effective/snippets/effective_asset.rb +19 -0
- data/app/models/effective/user_uploads.rb +19 -0
- data/app/models/inputs/asset_box.rb +154 -0
- data/app/models/inputs/asset_box_form_input.rb +7 -0
- data/app/models/inputs/asset_box_formtastic_input.rb +9 -0
- data/app/models/inputs/asset_box_input.rb +13 -82
- data/app/models/inputs/asset_box_simple_form_input.rb +7 -0
- data/app/uploaders/effective_assets_uploader.rb +14 -2
- data/app/uploaders/{asset_uploader.rb → test_asset_uploader.rb} +1 -1
- data/app/views/active_admin/effective_assets/_edit.html.haml +3 -3
- data/app/views/active_admin/effective_assets/_new.html.haml +2 -1
- data/app/views/asset_box_input/_attachment_as_list.html.haml +17 -0
- data/app/views/asset_box_input/_attachment_as_table.html.haml +32 -0
- data/app/views/asset_box_input/_attachment_as_thumbnail.html.haml +20 -0
- data/app/views/asset_box_input/_dialog.html.haml +18 -0
- data/app/views/asset_box_input/_progress_bar_template.html.haml +8 -0
- data/app/views/asset_box_input/_uploader.html.haml +21 -115
- data/app/views/effective/assets/iframe.html.haml +17 -0
- data/app/views/effective/snippets/_effective_asset.html.haml +8 -0
- data/config/routes.rb +8 -2
- data/db/migrate/01_create_effective_assets.rb.erb +3 -0
- data/lib/effective_assets.rb +34 -3
- data/lib/effective_assets/engine.rb +11 -8
- data/lib/effective_assets/version.rb +1 -1
- data/lib/generators/templates/asset_uploader.rb +35 -0
- data/lib/generators/templates/effective_assets.rb +31 -4
- data/lib/tasks/effective_assets_tasks.rake +115 -4
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/initializers/effective_assets.rb +18 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +52 -0
- data/spec/internal/log/test.log +793 -0
- data/spec/{dummy → internal}/public/favicon.ico +0 -0
- data/spec/internal/public/sprites.png +0 -0
- data/spec/models/asset_spec.rb +119 -35
- data/spec/spec_helper.rb +9 -3
- metadata +95 -234
- data/app/assets/images/effective_assets/s3_down_button.gif +0 -0
- data/app/assets/images/effective_assets/s3_over_button.gif +0 -0
- data/app/assets/images/effective_assets/s3_up_button.gif +0 -0
- data/app/assets/images/effective_assets/s3_upload.swf +0 -0
- data/app/assets/javascripts/effective_assets/asset_box_input.js.coffee +0 -71
- data/app/assets/javascripts/effective_assets/asset_box_uploader.js +0 -122
- data/app/assets/javascripts/effective_assets/asset_box_uploader_customization.js +0 -166
- data/app/controllers/effective/attachments_controller.rb +0 -14
- data/app/views/asset_box_input/_attachment_fields.html.haml +0 -14
- data/spec/dummy/README.rdoc +0 -261
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -65
- data/spec/dummy/config/boot.rb +0 -10
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -67
- data/spec/dummy/config/environments/test.rb +0 -37
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -58
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +0 -16
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -71
- data/spec/dummy/log/test.log +0 -33
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/spec_link +0 -3
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
$ ->
|
|
2
|
-
$(document).on 'click', 'a.asset-box-remove', (event) ->
|
|
3
|
-
event.preventDefault()
|
|
4
|
-
attachment_div = $(event.target).closest('div.asset-box-attachment')
|
|
5
|
-
attachment_div.find('input.asset-box-remove').first().val(1)
|
|
6
|
-
attachment_div.hide()
|
|
7
|
-
|
|
8
|
-
# Show the first 'limit' attachments, hide the rest
|
|
9
|
-
asset_box_input = attachment_div.closest('div.asset_box_input')
|
|
10
|
-
limit = asset_box_input.data('limit')
|
|
11
|
-
|
|
12
|
-
asset_box_input.find("input.asset-box-remove[value!='1']:gt(#{limit})").each -> $(this).closest('div.asset-box-attachment').hide()
|
|
13
|
-
asset_box_input.find("input.asset-box-remove[value!='1']:lt(#{limit})").each -> $(this).closest('div.asset-box-attachment').show()
|
|
14
|
-
|
|
15
|
-
$(document).on 'click', 'a.asset-box-upload', (event) ->
|
|
16
|
-
event.preventDefault()
|
|
17
|
-
uploader = $(event.target).closest('div.asset_box_input').find('div.asset_box_uploader').first()
|
|
18
|
-
|
|
19
|
-
if uploader.is(':visible')
|
|
20
|
-
uploader.slideUp('slow', -> $(this).hide())
|
|
21
|
-
else
|
|
22
|
-
uploader.slideDown('slow', -> $(this).show())
|
|
23
|
-
|
|
24
|
-
# This is the 'admin' insert assets screen
|
|
25
|
-
$(document).on 'click', 'a.asset-box-dialog', (event) ->
|
|
26
|
-
event.preventDefault()
|
|
27
|
-
dialog_frame = $(
|
|
28
|
-
"<div title='Insert Asset'>" +
|
|
29
|
-
"<iframe id='wym_insert_asset_iframe' src='/admin/assets' width='100%' height='100%' marginWidth='0' marginHeight='0' frameBorder='0' scrolling='auto' title='Insert Asset'></iframe>" +
|
|
30
|
-
"</div>"
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
dialog_frame.dialog({
|
|
34
|
-
modal: true,
|
|
35
|
-
height: $(window).height() * 0.85,
|
|
36
|
-
width: "85%",
|
|
37
|
-
close: (event, ui) -> $(this).remove()
|
|
38
|
-
buttons: { Close: -> $(this).dialog("close") }
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
asset_box = $(event.target).closest('div.asset_box_input')
|
|
42
|
-
|
|
43
|
-
single_mode = (asset_box.data('limit') == 1)
|
|
44
|
-
attachable_id = asset_box.data('attachable-id')
|
|
45
|
-
attachable_type = asset_box.data('attachable-type')
|
|
46
|
-
attachable_swf = asset_box.data('swf')
|
|
47
|
-
attachable_box = asset_box.data('box')
|
|
48
|
-
authenticity_token = asset_box.closest('form').find("input[name='authenticity_token']").first().val()
|
|
49
|
-
|
|
50
|
-
$('#wym_insert_asset_iframe', dialog_frame).on 'load', ->
|
|
51
|
-
$(this).contents().find('a.asset-insertable').on 'click', (event) ->
|
|
52
|
-
event.preventDefault()
|
|
53
|
-
|
|
54
|
-
# Initialize a new Attachment and get the HTML for it.
|
|
55
|
-
$.ajax({
|
|
56
|
-
url: '/s3_uploads',
|
|
57
|
-
beforeSend: (jqXHR, settings) -> s3_showAttachmentLoading(attachable_swf, '...'),
|
|
58
|
-
complete: (jqXHR, textStatus) -> s3_loadAttachmentHtml(attachable_swf, jqXHR.responseText),
|
|
59
|
-
global: false,
|
|
60
|
-
type: 'POST',
|
|
61
|
-
dataType: 'script',
|
|
62
|
-
data: {
|
|
63
|
-
'authenticity_token' : authenticity_token,
|
|
64
|
-
'box' : attachable_box,
|
|
65
|
-
'attachable_type' : attachable_type,
|
|
66
|
-
'attachable_id' : attachable_id,
|
|
67
|
-
'asset_id' : $(this).data('asset-id')
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
if single_mode then dialog_frame.dialog("close")
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/* SWFObject v2.2 <http://code.google.com/p/swfobject/>
|
|
2
|
-
is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
|
3
|
-
*/
|
|
4
|
-
var s3_upload_swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();
|
|
5
|
-
|
|
6
|
-
/* S3_Upload V0.1
|
|
7
|
-
Copyright (c) 2008 Elctech,
|
|
8
|
-
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
|
9
|
-
*/
|
|
10
|
-
/* S3_Upload V0.2
|
|
11
|
-
Copyright (c) 2010 Nathan Colgate,
|
|
12
|
-
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
|
13
|
-
*/
|
|
14
|
-
var s3_swf;
|
|
15
|
-
function s3_swf_init(id, options)
|
|
16
|
-
{
|
|
17
|
-
var buttonWidth = (options.buttonWidth != undefined) ? options.buttonWidth : 50;
|
|
18
|
-
var buttonHeight = (options.buttonHeight != undefined) ? options.buttonHeight : 50;
|
|
19
|
-
var flashVersion = (options.flashVersion != undefined) ? options.flashVersion : '9.0.0';
|
|
20
|
-
var queueSizeLimit = (options.queueSizeLimit != undefined) ? options.queueSizeLimit : 10;
|
|
21
|
-
var fileSizeLimit = (options.fileSizeLimit != undefined) ? options.fileSizeLimit : 524288000;
|
|
22
|
-
var fileTypes = (options.fileTypes != undefined) ? options.fileTypes : "*.*";
|
|
23
|
-
var fileTypeDescs = (options.fileTypeDescs != undefined) ? options.fileTypeDescs : "All Files";
|
|
24
|
-
var selectMultipleFiles = (options.selectMultipleFiles != undefined) ? options.selectMultipleFiles : true;
|
|
25
|
-
var keyPrefix = (options.keyPrefix != undefined) ? options.keyPrefix : "";
|
|
26
|
-
var signaturePath = (options.signaturePath != undefined) ? options.signaturePath : "s3_uploads.xml";
|
|
27
|
-
var swfFilePath = (options.swfFilePath != undefined) ? options.swfFilePath : "/flash/s3_upload.swf";
|
|
28
|
-
var buttonUpPath = (options.buttonUpPath != undefined) ? options.buttonUpPath : "";
|
|
29
|
-
var buttonOverPath = (options.buttonOverPath != undefined) ? options.buttonOverPath : "";
|
|
30
|
-
var buttonDownPath = (options.buttonDownPath != undefined) ? options.buttonDownPath : "";
|
|
31
|
-
|
|
32
|
-
var onFileAdd = (options.onFileAdd != undefined) ? options.onFileAdd : function(file){};
|
|
33
|
-
var onFileRemove = (options.onFileRemove != undefined) ? options.onFileRemove : function(file){};
|
|
34
|
-
var onFileSizeLimitReached = (options.onFileSizeLimitReached != undefined) ? options.onFileSizeLimitReached : function(file){};
|
|
35
|
-
var onFileNotInQueue = (options.onFileNotInQueue != undefined) ? options.onFileNotInQueue : function(file){};
|
|
36
|
-
|
|
37
|
-
var onQueueChange = (options.onQueueChange != undefined) ? options.onQueueChange : function(queue){};
|
|
38
|
-
var onQueueClear = (options.onQueueClear != undefined) ? options.onQueueClear : function(queue){};
|
|
39
|
-
var onQueueSizeLimitReached = (options.onQueueSizeLimitReached != undefined) ? options.onQueueSizeLimitReached : function(queue){};
|
|
40
|
-
var onQueueEmpty = (options.onQueueEmpty != undefined) ? options.onQueueEmpty : function(queue){};
|
|
41
|
-
|
|
42
|
-
var onUploadingStop = (options.onUploadingStop != undefined) ? options.onUploadingStop : function(){};
|
|
43
|
-
var onUploadingStart = (options.onUploadingStart != undefined) ? options.onUploadingStart : function(){};
|
|
44
|
-
var onUploadingFinish = (options.onUploadingFinish != undefined) ? options.onUploadingFinish : function(){};
|
|
45
|
-
|
|
46
|
-
var onSignatureOpen = (options.onSignatureOpen != undefined) ? options.onSignatureOpen : function(file,event){};
|
|
47
|
-
var onSignatureProgress = (options.onSignatureProgress != undefined) ? options.onSignatureProgress : function(file,progress_event){};
|
|
48
|
-
var onSignatureHttpStatus = (options.onSignatureHttpStatus != undefined) ? options.onSignatureHttpStatus : function(file,http_status_event){};
|
|
49
|
-
var onSignatureComplete = (options.onSignatureComplete != undefined) ? options.onSignatureComplete : function(file,event){};
|
|
50
|
-
var onSignatureSecurityError = (options.onSignatureSecurityError != undefined) ? options.onSignatureSecurityError : function(file,security_error_event){};
|
|
51
|
-
var onSignatureIOError = (options.onSignatureIOError != undefined) ? options.onSignatureIOError : function(file,io_error_event){};
|
|
52
|
-
var onSignatureXMLError = (options.onSignatureXMLError != undefined) ? options.onSignatureXMLError : function(file,error_message){};
|
|
53
|
-
|
|
54
|
-
var onUploadOpen = (options.onUploadOpen != undefined) ? options.onUploadOpen : function(upload_options,event){};
|
|
55
|
-
var onUploadProgress = (options.onUploadProgress != undefined) ? options.onUploadProgress : function(upload_options,progress_event){};
|
|
56
|
-
var onUploadHttpStatus = (options.onUploadHttpStatus != undefined) ? options.onUploadHttpStatus : function(upload_options,http_status_event){};
|
|
57
|
-
var onUploadComplete = (options.onUploadComplete != undefined) ? options.onUploadComplete : function(upload_options,event){};
|
|
58
|
-
var onUploadIOError = (options.onUploadIOError != undefined) ? options.onUploadIOError : function(upload_options,io_error_event){};
|
|
59
|
-
var onUploadSecurityError = (options.onUploadSecurityError != undefined) ? options.onUploadSecurityError : function(upload_options,security_error_event){};
|
|
60
|
-
var onUploadError = (options.onUploadError != undefined) ? options.onUploadError : function(upload_options,error){};
|
|
61
|
-
|
|
62
|
-
var flashvars = {"s3_swf_obj": (options.swfVarObj != undefined ? options.swfVarObj : 's3_swf')}; //fallback to the global var incase script is used outside of view helper
|
|
63
|
-
var params = {};
|
|
64
|
-
var attributes = {};
|
|
65
|
-
params.wmode = "transparent";
|
|
66
|
-
params.menu = "false";
|
|
67
|
-
params.quality = "low";
|
|
68
|
-
|
|
69
|
-
s3_upload_swfobject.embedSWF(swfFilePath+"?t=" + new Date().getTime(), id, buttonWidth, buttonHeight, flashVersion, false, flashvars, params, attributes);
|
|
70
|
-
|
|
71
|
-
var signatureUrl = window.location.protocol + '//' + window.location.host + signaturePath;
|
|
72
|
-
var buttonUpUrl = window.location.protocol + '//' + window.location.host + buttonUpPath;
|
|
73
|
-
var buttonDownUrl = window.location.protocol + '//' + window.location.host + buttonDownPath;
|
|
74
|
-
var buttonOverUrl = window.location.protocol + '//' + window.location.host + buttonOverPath;
|
|
75
|
-
|
|
76
|
-
s3_swf = {
|
|
77
|
-
obj: function() { return document[id]; },
|
|
78
|
-
|
|
79
|
-
init: function() { this.obj().init(signatureUrl, keyPrefix, fileSizeLimit, queueSizeLimit, fileTypes, fileTypeDescs, selectMultipleFiles,buttonWidth,buttonHeight,buttonUpUrl,buttonDownUrl,buttonOverUrl); },
|
|
80
|
-
clearQueue: function() { this.obj().clearQueue();},
|
|
81
|
-
startUploading: function() { this.obj().startUploading();},
|
|
82
|
-
stopUploading: function() { this.obj().stopUploading(); s3_queueClearHandler("");},
|
|
83
|
-
removeFileFromQueue: function(file_name) {
|
|
84
|
-
console.log("remove file from queue");
|
|
85
|
-
var one_file = $("#file_todo_list li[data-name='" + file_name + "']");
|
|
86
|
-
this.obj().removeFileFromQueue(one_file.index());
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
onFileAdd: onFileAdd,
|
|
90
|
-
onFileRemove: onFileRemove,
|
|
91
|
-
onFileSizeLimitReached: onFileSizeLimitReached,
|
|
92
|
-
onFileNotInQueue: onFileNotInQueue,
|
|
93
|
-
|
|
94
|
-
onQueueChange: onQueueChange,
|
|
95
|
-
onQueueClear: onQueueClear,
|
|
96
|
-
onQueueSizeLimitReached: onQueueSizeLimitReached,
|
|
97
|
-
onQueueEmpty: onQueueEmpty,
|
|
98
|
-
|
|
99
|
-
onUploadingStop: onUploadingStop,
|
|
100
|
-
onUploadingStart: onUploadingStart,
|
|
101
|
-
onUploadingFinish: onUploadingFinish,
|
|
102
|
-
|
|
103
|
-
onSignatureOpen: onSignatureOpen,
|
|
104
|
-
onSignatureProgress: onSignatureProgress,
|
|
105
|
-
onSignatureHttpStatus: onSignatureHttpStatus,
|
|
106
|
-
onSignatureComplete: onSignatureComplete,
|
|
107
|
-
onSignatureSecurityError: onSignatureSecurityError,
|
|
108
|
-
onSignatureIOError: onSignatureIOError,
|
|
109
|
-
onSignatureXMLError: onSignatureXMLError,
|
|
110
|
-
|
|
111
|
-
onUploadOpen: onUploadOpen,
|
|
112
|
-
onUploadProgress: onUploadProgress,
|
|
113
|
-
onUploadHttpStatus: onUploadHttpStatus,
|
|
114
|
-
onUploadComplete: onUploadComplete,
|
|
115
|
-
onUploadIOError: onUploadIOError,
|
|
116
|
-
onUploadSecurityError: onUploadSecurityError,
|
|
117
|
-
onUploadError: onUploadError
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return(s3_swf);
|
|
122
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
var s3_queueChangeHandler = function(s3_swf, queue) {
|
|
2
|
-
var obj = $("div.asset_box_input[data-swf='" + s3_swf + "']").find('div.asset_box_uploader').first();
|
|
3
|
-
var list = obj.find('.file_todo_list');
|
|
4
|
-
|
|
5
|
-
var queueBytesTotal = 0;
|
|
6
|
-
var queueFiles = obj.data('queueFiles') || 0;
|
|
7
|
-
|
|
8
|
-
// Go through the queue, find anything that doesn't exist in the list, and add it to list
|
|
9
|
-
// Also add up the queueBytesTotal
|
|
10
|
-
for(x = 0; x < queue.files.length; x++) {
|
|
11
|
-
queueBytesTotal = queueBytesTotal + queue.files[x].size;
|
|
12
|
-
var one_file = list.find("li[data-name='" + queue.files[x].name + "']");
|
|
13
|
-
if(one_file.length == 0) {
|
|
14
|
-
s3_addFileToTodoList(s3_swf, queue.files[x].name, queue.files[x].size, x);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//Go through the list, find anything that doesn't exist in the queue, and remove it
|
|
19
|
-
$('li.file_to_upload', list).each(function(i, el) {
|
|
20
|
-
var name_to_find = $(el).data('name');
|
|
21
|
-
var found_it = false;
|
|
22
|
-
|
|
23
|
-
for(x = 0; x < queue.files.length; x++) {
|
|
24
|
-
if(queue.files[x].name == name_to_find) {
|
|
25
|
-
found_it = true;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if(found_it == false) $(el).remove();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
obj.find('.file_done_list').find('li').show();
|
|
34
|
-
|
|
35
|
-
if(queue.files.length > queueFiles) obj.data('queueBytesTotal', queueBytesTotal);
|
|
36
|
-
obj.data('queueFiles', queue.files.length);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
var s3_uploadingStartHandler = function(s3_swf) {
|
|
40
|
-
var obj = $("div.asset_box_input[data-swf='" + s3_swf + "']").find('div.asset_box_uploader').first();
|
|
41
|
-
|
|
42
|
-
obj.data('queueBytesFinished', 0);
|
|
43
|
-
var queueBytesTotal = obj.data('queueBytesTotal');
|
|
44
|
-
|
|
45
|
-
obj.find('.queue_size').find('.numerator').text("0 bytes / ");
|
|
46
|
-
obj.find('.queue_size').find('.denominator').text(s3_readableBytes(queueBytesTotal));
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
var s3_uploadingFinishHandler = function(s3_swf) {
|
|
50
|
-
var obj = $("div.asset_box_input[data-swf='" + s3_swf + "']").find('div.asset_box_uploader').first();
|
|
51
|
-
|
|
52
|
-
obj.find('.overall').find('.progress').css('width', '100%');
|
|
53
|
-
obj.find('.overall').find('.amount').text('100%');
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
var s3_progressHandler = function(s3_swf, progress_event) {
|
|
57
|
-
var obj = $("div.asset_box_input[data-swf='" + s3_swf + "']").find('div.asset_box_uploader').first();
|
|
58
|
-
var current_percentage = Math.floor((parseInt(progress_event.bytesLoaded)/parseInt(progress_event.bytesTotal))*100)+'%';
|
|
59
|
-
|
|
60
|
-
var first_file = obj.find('.file_todo_list').find('li.file_to_upload').first();
|
|
61
|
-
first_file.find('.delete').hide();
|
|
62
|
-
first_file.find('.progress').css('display','block').css('width', current_percentage);
|
|
63
|
-
first_file.find('.progress').find('.amount').text(current_percentage);
|
|
64
|
-
|
|
65
|
-
var queueBytesFinished = parseInt(obj.data('queueBytesFinished'));
|
|
66
|
-
var queueBytesTotal = parseInt(obj.data('queueBytesTotal'));
|
|
67
|
-
|
|
68
|
-
var overall_percentage = Math.floor(((queueBytesFinished+parseInt(progress_event.bytesLoaded))/queueBytesTotal)*100)+'%';
|
|
69
|
-
|
|
70
|
-
// Overall
|
|
71
|
-
obj.find('.overall').find('.progress').css('width', overall_percentage).show();
|
|
72
|
-
obj.find('.overall').find('.amount').text(overall_percentage);
|
|
73
|
-
obj.find('.queue_size').find('.numerator').text(s3_readableBytes(queueBytesFinished+parseInt(progress_event.bytesLoaded)) + " / ");
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
var s3_queueClearHandler = function(s3_swf, queue) {
|
|
77
|
-
var obj = $("div.asset_box_input[data-swf='" + s3_swf + "']").find('div.asset_box_uploader').first();
|
|
78
|
-
|
|
79
|
-
var overall = obj.find('div.overall');
|
|
80
|
-
|
|
81
|
-
overall.find('span.progress').css('width', '0%').hide();
|
|
82
|
-
overall.find('span.amount').html('0%');
|
|
83
|
-
|
|
84
|
-
obj.find('.file_done_list').children().remove();
|
|
85
|
-
obj.find('.file_todo_list').children().remove();
|
|
86
|
-
|
|
87
|
-
obj.find('.queue_size').find('.numerator').text('');
|
|
88
|
-
obj.find('.queue_size').find('.denominator').text('');
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
var s3_addFileToDoneList = function(s3_swf, file_name, file_size) {
|
|
92
|
-
var obj = $("div.asset_box_input[data-swf='" + s3_swf + "']").find('div.asset_box_uploader').first();
|
|
93
|
-
|
|
94
|
-
var queueBytesFinished = parseInt(obj.data('queueBytesFinished'));
|
|
95
|
-
queueBytesFinished = queueBytesFinished + parseInt(file_size);
|
|
96
|
-
obj.data('queueBytesFinished', queueBytesFinished);
|
|
97
|
-
|
|
98
|
-
var one_file = $(
|
|
99
|
-
'<li class="file_to_upload" data-name="' + file_name + '" style="display: none;">' +
|
|
100
|
-
'<span class="progress">' +
|
|
101
|
-
'<span class="amount">100%</span>' +
|
|
102
|
-
'</span>' +
|
|
103
|
-
'<span class="file_name">' + file_name + '</span>' +
|
|
104
|
-
'<span class="file_size">' + s3_readableBytes(file_size) + '</span>' +
|
|
105
|
-
'</li>'
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
obj.find('.file_done_list').first().append(one_file);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
var s3_addFileToTodoList = function(s3_swf, file_name, file_size, index) {
|
|
112
|
-
var obj = $("div.asset_box_input[data-swf='" + s3_swf + "']").find('div.asset_box_uploader').first();
|
|
113
|
-
|
|
114
|
-
var one_file = $(
|
|
115
|
-
'<li class="file_to_upload" data-name="' + file_name + '">' +
|
|
116
|
-
'<span class="progress">' +
|
|
117
|
-
'<span class="amount">0%</span>' +
|
|
118
|
-
'</span>' +
|
|
119
|
-
'<span class="file_name">' + file_name + '</span>' +
|
|
120
|
-
'<span class="file_size">' + s3_readableBytes(file_size) + '</span>' +
|
|
121
|
-
'<a href="#" class="delete" onclick="javascript:' + s3_swf + '_object.removeFileFromQueue(\''+file_name+'\'); return false;">Delete</span></a>' +
|
|
122
|
-
'<span class="properties">' +
|
|
123
|
-
'<label>Title</label>' +
|
|
124
|
-
'<input type="text" class="title" value="' + file_name + '"/>' +
|
|
125
|
-
'<label>Description</label>' +
|
|
126
|
-
'<input type="text" class="description" />' +
|
|
127
|
-
'<label>Tags</label>' +
|
|
128
|
-
'<input type="text" class="tags"/>' +
|
|
129
|
-
'</span>' +
|
|
130
|
-
'</li>'
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
obj.find('.file_todo_list').first().append(one_file);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
var s3_loadAttachmentHtml = function(s3_swf, html) {
|
|
137
|
-
var asset_box_input = $("div.asset_box_input[data-swf='" + s3_swf + "']");
|
|
138
|
-
|
|
139
|
-
asset_box_input.find('.attachments > div.asset-box-loading').first().remove()
|
|
140
|
-
asset_box_input.find('.attachments').prepend($(html));
|
|
141
|
-
|
|
142
|
-
var limit = asset_box_input.data('limit') - 1;
|
|
143
|
-
asset_box_input.find("input.asset-box-remove[value!='1']:gt(" + limit + ")").each(function(i) { $(this).closest('div.asset-box-attachment').hide(); });
|
|
144
|
-
asset_box_input.find("input.asset-box-remove[value!='1']:lt(" + limit + ")").each(function(i) { $(this).closest('div.asset-box-attachment').show(); });
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
var s3_showAttachmentLoading = function(s3_swf, title) {
|
|
148
|
-
var asset_box_input = $("div.asset_box_input[data-swf='" + s3_swf + "']");
|
|
149
|
-
|
|
150
|
-
var loading_html = $(
|
|
151
|
-
'<div class="asset-box-attachment asset-box-loading">' +
|
|
152
|
-
'<span class="thumbnail">' +
|
|
153
|
-
'<i class="asset-box-spinner"></i>' +
|
|
154
|
-
'</span>' +
|
|
155
|
-
'<p class="title">' + title + '</p>' +
|
|
156
|
-
'</div>'
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
asset_box_input.find('.attachments').prepend($(loading_html));
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
var s3_readableBytes = function(bytes) {
|
|
163
|
-
var s = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
|
|
164
|
-
var e = Math.floor(Math.log(bytes)/Math.log(1024));
|
|
165
|
-
return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
|
|
166
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
module Effective
|
|
2
|
-
class AttachmentsController < ApplicationController
|
|
3
|
-
skip_authorize_resource if defined?(CanCan)
|
|
4
|
-
respond_to :json
|
|
5
|
-
|
|
6
|
-
def show
|
|
7
|
-
@asset = Asset.find(params[:id]) # This should actually search Assets
|
|
8
|
-
|
|
9
|
-
EffectiveAssets.authorized?(self, :read, @asset)
|
|
10
|
-
|
|
11
|
-
respond_with @asset
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
- attachable_type ||= attachment.attachable_type.titleize.gsub(" ", "_").gsub('/', '_').downcase
|
|
2
|
-
- uid = (attachment.persisted? ? attachment.id : Time.now.to_i)
|
|
3
|
-
- hidden ||= false
|
|
4
|
-
|
|
5
|
-
.asset-box-attachment{:style => "#{(attachment.marked_for_destruction? || hidden) ? 'display: none;' : ''}"}
|
|
6
|
-
- if attachment.persisted?
|
|
7
|
-
= hidden_field_tag("#{attachable_type}[attachments_attributes][#{uid}][id]", attachment.id)
|
|
8
|
-
= hidden_field_tag("#{attachable_type}[attachments_attributes][#{uid}][asset_id]", attachment.asset_id)
|
|
9
|
-
= hidden_field_tag("#{attachable_type}[attachments_attributes][#{uid}][box]", attachment.box)
|
|
10
|
-
= hidden_field_tag("#{attachable_type}[attachments_attributes][#{uid}][_destroy]", attachment.marked_for_destruction? ? 1 : nil, :class => 'asset-box-remove')
|
|
11
|
-
|
|
12
|
-
%span.thumbnail= effective_asset_image_tag(attachment.asset, :thumb)
|
|
13
|
-
%p.title= attachment.asset.title
|
|
14
|
-
%a.asset-box-remove{:href => '#'} Delete
|
data/spec/dummy/README.rdoc
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
== Welcome to Rails
|
|
2
|
-
|
|
3
|
-
Rails is a web-application framework that includes everything needed to create
|
|
4
|
-
database-backed web applications according to the Model-View-Control pattern.
|
|
5
|
-
|
|
6
|
-
This pattern splits the view (also called the presentation) into "dumb"
|
|
7
|
-
templates that are primarily responsible for inserting pre-built data in between
|
|
8
|
-
HTML tags. The model contains the "smart" domain objects (such as Account,
|
|
9
|
-
Product, Person, Post) that holds all the business logic and knows how to
|
|
10
|
-
persist themselves to a database. The controller handles the incoming requests
|
|
11
|
-
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
|
12
|
-
and directing data to the view.
|
|
13
|
-
|
|
14
|
-
In Rails, the model is handled by what's called an object-relational mapping
|
|
15
|
-
layer entitled Active Record. This layer allows you to present the data from
|
|
16
|
-
database rows as objects and embellish these data objects with business logic
|
|
17
|
-
methods. You can read more about Active Record in
|
|
18
|
-
link:files/vendor/rails/activerecord/README.html.
|
|
19
|
-
|
|
20
|
-
The controller and view are handled by the Action Pack, which handles both
|
|
21
|
-
layers by its two parts: Action View and Action Controller. These two layers
|
|
22
|
-
are bundled in a single package due to their heavy interdependence. This is
|
|
23
|
-
unlike the relationship between the Active Record and Action Pack that is much
|
|
24
|
-
more separate. Each of these packages can be used independently outside of
|
|
25
|
-
Rails. You can read more about Action Pack in
|
|
26
|
-
link:files/vendor/rails/actionpack/README.html.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
== Getting Started
|
|
30
|
-
|
|
31
|
-
1. At the command prompt, create a new Rails application:
|
|
32
|
-
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
|
33
|
-
|
|
34
|
-
2. Change directory to <tt>myapp</tt> and start the web server:
|
|
35
|
-
<tt>cd myapp; rails server</tt> (run with --help for options)
|
|
36
|
-
|
|
37
|
-
3. Go to http://localhost:3000/ and you'll see:
|
|
38
|
-
"Welcome aboard: You're riding Ruby on Rails!"
|
|
39
|
-
|
|
40
|
-
4. Follow the guidelines to start developing your application. You can find
|
|
41
|
-
the following resources handy:
|
|
42
|
-
|
|
43
|
-
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
|
44
|
-
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
== Debugging Rails
|
|
48
|
-
|
|
49
|
-
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
|
50
|
-
will help you debug it and get it back on the rails.
|
|
51
|
-
|
|
52
|
-
First area to check is the application log files. Have "tail -f" commands
|
|
53
|
-
running on the server.log and development.log. Rails will automatically display
|
|
54
|
-
debugging and runtime information to these files. Debugging info will also be
|
|
55
|
-
shown in the browser on requests from 127.0.0.1.
|
|
56
|
-
|
|
57
|
-
You can also log your own messages directly into the log file from your code
|
|
58
|
-
using the Ruby logger class from inside your controllers. Example:
|
|
59
|
-
|
|
60
|
-
class WeblogController < ActionController::Base
|
|
61
|
-
def destroy
|
|
62
|
-
@weblog = Weblog.find(params[:id])
|
|
63
|
-
@weblog.destroy
|
|
64
|
-
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
The result will be a message in your log file along the lines of:
|
|
69
|
-
|
|
70
|
-
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
|
71
|
-
|
|
72
|
-
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
|
73
|
-
|
|
74
|
-
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
|
75
|
-
several books available online as well:
|
|
76
|
-
|
|
77
|
-
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
|
78
|
-
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
|
79
|
-
|
|
80
|
-
These two books will bring you up to speed on the Ruby language and also on
|
|
81
|
-
programming in general.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
== Debugger
|
|
85
|
-
|
|
86
|
-
Debugger support is available through the debugger command when you start your
|
|
87
|
-
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
|
88
|
-
execution at any point in the code, investigate and change the model, and then,
|
|
89
|
-
resume execution! You need to install ruby-debug to run the server in debugging
|
|
90
|
-
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
|
91
|
-
|
|
92
|
-
class WeblogController < ActionController::Base
|
|
93
|
-
def index
|
|
94
|
-
@posts = Post.all
|
|
95
|
-
debugger
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
So the controller will accept the action, run the first line, then present you
|
|
100
|
-
with a IRB prompt in the server window. Here you can do things like:
|
|
101
|
-
|
|
102
|
-
>> @posts.inspect
|
|
103
|
-
=> "[#<Post:0x14a6be8
|
|
104
|
-
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
|
105
|
-
#<Post:0x14a6620
|
|
106
|
-
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
|
107
|
-
>> @posts.first.title = "hello from a debugger"
|
|
108
|
-
=> "hello from a debugger"
|
|
109
|
-
|
|
110
|
-
...and even better, you can examine how your runtime objects actually work:
|
|
111
|
-
|
|
112
|
-
>> f = @posts.first
|
|
113
|
-
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
|
114
|
-
>> f.
|
|
115
|
-
Display all 152 possibilities? (y or n)
|
|
116
|
-
|
|
117
|
-
Finally, when you're ready to resume execution, you can enter "cont".
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
== Console
|
|
121
|
-
|
|
122
|
-
The console is a Ruby shell, which allows you to interact with your
|
|
123
|
-
application's domain model. Here you'll have all parts of the application
|
|
124
|
-
configured, just like it is when the application is running. You can inspect
|
|
125
|
-
domain models, change values, and save to the database. Starting the script
|
|
126
|
-
without arguments will launch it in the development environment.
|
|
127
|
-
|
|
128
|
-
To start the console, run <tt>rails console</tt> from the application
|
|
129
|
-
directory.
|
|
130
|
-
|
|
131
|
-
Options:
|
|
132
|
-
|
|
133
|
-
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
|
134
|
-
made to the database.
|
|
135
|
-
* Passing an environment name as an argument will load the corresponding
|
|
136
|
-
environment. Example: <tt>rails console production</tt>.
|
|
137
|
-
|
|
138
|
-
To reload your controllers and models after launching the console run
|
|
139
|
-
<tt>reload!</tt>
|
|
140
|
-
|
|
141
|
-
More information about irb can be found at:
|
|
142
|
-
link:http://www.rubycentral.org/pickaxe/irb.html
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
== dbconsole
|
|
146
|
-
|
|
147
|
-
You can go to the command line of your database directly through <tt>rails
|
|
148
|
-
dbconsole</tt>. You would be connected to the database with the credentials
|
|
149
|
-
defined in database.yml. Starting the script without arguments will connect you
|
|
150
|
-
to the development database. Passing an argument will connect you to a different
|
|
151
|
-
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
|
152
|
-
PostgreSQL and SQLite 3.
|
|
153
|
-
|
|
154
|
-
== Description of Contents
|
|
155
|
-
|
|
156
|
-
The default directory structure of a generated Ruby on Rails application:
|
|
157
|
-
|
|
158
|
-
|-- app
|
|
159
|
-
| |-- assets
|
|
160
|
-
| | |-- images
|
|
161
|
-
| | |-- javascripts
|
|
162
|
-
| | `-- stylesheets
|
|
163
|
-
| |-- controllers
|
|
164
|
-
| |-- helpers
|
|
165
|
-
| |-- mailers
|
|
166
|
-
| |-- models
|
|
167
|
-
| `-- views
|
|
168
|
-
| `-- layouts
|
|
169
|
-
|-- config
|
|
170
|
-
| |-- environments
|
|
171
|
-
| |-- initializers
|
|
172
|
-
| `-- locales
|
|
173
|
-
|-- db
|
|
174
|
-
|-- doc
|
|
175
|
-
|-- lib
|
|
176
|
-
| |-- assets
|
|
177
|
-
| `-- tasks
|
|
178
|
-
|-- log
|
|
179
|
-
|-- public
|
|
180
|
-
|-- script
|
|
181
|
-
|-- test
|
|
182
|
-
| |-- fixtures
|
|
183
|
-
| |-- functional
|
|
184
|
-
| |-- integration
|
|
185
|
-
| |-- performance
|
|
186
|
-
| `-- unit
|
|
187
|
-
|-- tmp
|
|
188
|
-
| `-- cache
|
|
189
|
-
| `-- assets
|
|
190
|
-
`-- vendor
|
|
191
|
-
|-- assets
|
|
192
|
-
| |-- javascripts
|
|
193
|
-
| `-- stylesheets
|
|
194
|
-
`-- plugins
|
|
195
|
-
|
|
196
|
-
app
|
|
197
|
-
Holds all the code that's specific to this particular application.
|
|
198
|
-
|
|
199
|
-
app/assets
|
|
200
|
-
Contains subdirectories for images, stylesheets, and JavaScript files.
|
|
201
|
-
|
|
202
|
-
app/controllers
|
|
203
|
-
Holds controllers that should be named like weblogs_controller.rb for
|
|
204
|
-
automated URL mapping. All controllers should descend from
|
|
205
|
-
ApplicationController which itself descends from ActionController::Base.
|
|
206
|
-
|
|
207
|
-
app/models
|
|
208
|
-
Holds models that should be named like post.rb. Models descend from
|
|
209
|
-
ActiveRecord::Base by default.
|
|
210
|
-
|
|
211
|
-
app/views
|
|
212
|
-
Holds the template files for the view that should be named like
|
|
213
|
-
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
|
214
|
-
eRuby syntax by default.
|
|
215
|
-
|
|
216
|
-
app/views/layouts
|
|
217
|
-
Holds the template files for layouts to be used with views. This models the
|
|
218
|
-
common header/footer method of wrapping views. In your views, define a layout
|
|
219
|
-
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
|
220
|
-
Inside default.html.erb, call <% yield %> to render the view using this
|
|
221
|
-
layout.
|
|
222
|
-
|
|
223
|
-
app/helpers
|
|
224
|
-
Holds view helpers that should be named like weblogs_helper.rb. These are
|
|
225
|
-
generated for you automatically when using generators for controllers.
|
|
226
|
-
Helpers can be used to wrap functionality for your views into methods.
|
|
227
|
-
|
|
228
|
-
config
|
|
229
|
-
Configuration files for the Rails environment, the routing map, the database,
|
|
230
|
-
and other dependencies.
|
|
231
|
-
|
|
232
|
-
db
|
|
233
|
-
Contains the database schema in schema.rb. db/migrate contains all the
|
|
234
|
-
sequence of Migrations for your schema.
|
|
235
|
-
|
|
236
|
-
doc
|
|
237
|
-
This directory is where your application documentation will be stored when
|
|
238
|
-
generated using <tt>rake doc:app</tt>
|
|
239
|
-
|
|
240
|
-
lib
|
|
241
|
-
Application specific libraries. Basically, any kind of custom code that
|
|
242
|
-
doesn't belong under controllers, models, or helpers. This directory is in
|
|
243
|
-
the load path.
|
|
244
|
-
|
|
245
|
-
public
|
|
246
|
-
The directory available for the web server. Also contains the dispatchers and the
|
|
247
|
-
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
|
248
|
-
server.
|
|
249
|
-
|
|
250
|
-
script
|
|
251
|
-
Helper scripts for automation and generation.
|
|
252
|
-
|
|
253
|
-
test
|
|
254
|
-
Unit and functional tests along with fixtures. When using the rails generate
|
|
255
|
-
command, template test files will be generated for you and placed in this
|
|
256
|
-
directory.
|
|
257
|
-
|
|
258
|
-
vendor
|
|
259
|
-
External libraries that the application depends on. Also includes the plugins
|
|
260
|
-
subdirectory. If the app has frozen rails, those gems also go here, under
|
|
261
|
-
vendor/rails/. This directory is in the load path.
|