forked from saurabh/orbit4-5
Fix filemanager js
This commit is contained in:
parent
5c4ba2b0d5
commit
0f58f39eb5
|
@ -1,3 +1,5 @@
|
||||||
|
var insertBtn, deleteBtn, language, funcNum, url = null;
|
||||||
|
|
||||||
!function ($) {
|
!function ($) {
|
||||||
$.fn.checkListLength = function (param){
|
$.fn.checkListLength = function (param){
|
||||||
_defaultSettings = {
|
_defaultSettings = {
|
||||||
|
@ -30,41 +32,27 @@ $(function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
var insertBtn = $("#insert_btn"),
|
insertBtn = $("#insert_btn");
|
||||||
deleteBtn = $("#delete_btn"),
|
deleteBtn = $("#delete_btn");
|
||||||
url = null;
|
|
||||||
|
|
||||||
var showPreview = function(elem){
|
initAssets();
|
||||||
var type = $("#ext_" + elem.val()).val(),
|
|
||||||
imgexp = new RegExp(/(\.|\/)(gif|jpe?g|png)$/i),
|
|
||||||
otherexp = new RegExp(/(\.|\/)(pdf|doc|docx|ppt|pptx|xls|xlsx)$/i)
|
|
||||||
img = $("<img />"),
|
|
||||||
preview = $( ".preview-area" );
|
|
||||||
preview.text("Preview is loading...");
|
|
||||||
if( imgexp.test(type) ){
|
|
||||||
var url = $("#url_" + elem.val()).val();
|
|
||||||
img.attr("src",url).load(function(){
|
|
||||||
var ratio = this.width / this.height,
|
|
||||||
targetWidth = targetHeight = 200;
|
|
||||||
if( ratio < 1 ){
|
|
||||||
targetWidth = targetHeight * ratio;
|
|
||||||
}else{
|
|
||||||
targetHeight = targetWidth / ratio;
|
|
||||||
}
|
|
||||||
img.height(targetHeight).width(targetWidth);
|
|
||||||
preview.html(img);
|
|
||||||
})
|
|
||||||
}else if( otherexp.test(type) ) {
|
|
||||||
var t = type.replace(".",""),
|
|
||||||
url = "/assets/ft-icons/" + t + "/" + t + "-128_32.png";
|
|
||||||
img.attr('src', url).load(function(){
|
|
||||||
preview.html(img);
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
preview.html("Preview not available.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
funcNum = getUrlParam( 'CKEditorFuncNum' ),
|
||||||
|
t = getUrlParam('CKEditor').split("_"),
|
||||||
|
language = t[t.length-1];
|
||||||
|
|
||||||
|
language = (language == "tw" ? "zh_tw" : language);
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
function getUrlParam( paramName ) {
|
||||||
|
var reParam = new RegExp( '(?:[\?&]|&)' + paramName + '=([^&]+)', 'i' );
|
||||||
|
var match = window.location.search.match(reParam);
|
||||||
|
|
||||||
|
return ( match && match.length > 1 ) ? match[ 1 ] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var initAssets = function(){
|
||||||
$("#asset_sort_list").on(clickEvent,"input[type=checkbox]",function(){
|
$("#asset_sort_list").on(clickEvent,"input[type=checkbox]",function(){
|
||||||
if($("#asset_sort_list input[type=checkbox]:checked").length == 1){
|
if($("#asset_sort_list input[type=checkbox]:checked").length == 1){
|
||||||
url = window.location.protocol + "//" + window.location.host + $("#url_" + $("input[type=checkbox]:checked").val()).val();
|
url = window.location.protocol + "//" + window.location.host + $("#url_" + $("input[type=checkbox]:checked").val()).val();
|
||||||
|
@ -86,7 +74,7 @@ $(document).ready(function(){
|
||||||
if(url){
|
if(url){
|
||||||
window.opener.CKEDITOR.tools.callFunction( funcNum, url, function() {
|
window.opener.CKEDITOR.tools.callFunction( funcNum, url, function() {
|
||||||
var element,
|
var element,
|
||||||
dialog = this.getDialog();
|
dialog = this.getDialog();
|
||||||
if ( dialog.getName() == 'image' ) {
|
if ( dialog.getName() == 'image' ) {
|
||||||
element = dialog.getContentElement( 'info', 'txtAlt' );
|
element = dialog.getContentElement( 'info', 'txtAlt' );
|
||||||
if ( element )
|
if ( element )
|
||||||
|
@ -98,7 +86,10 @@ $(document).ready(function(){
|
||||||
})
|
})
|
||||||
deleteBtn.bind( clickEvent,function(){
|
deleteBtn.bind( clickEvent,function(){
|
||||||
var items_to_delete = [],
|
var items_to_delete = [],
|
||||||
type = getUrlParam("type");
|
type = getUrlParam("type");
|
||||||
|
|
||||||
|
$( ".preview-area" ).empty();
|
||||||
|
|
||||||
$("input[type=checkbox]:checked").each(function(){
|
$("input[type=checkbox]:checked").each(function(){
|
||||||
items_to_delete.push($(this).val());
|
items_to_delete.push($(this).val());
|
||||||
})
|
})
|
||||||
|
@ -109,7 +100,8 @@ $(document).ready(function(){
|
||||||
var currentEdit = null;
|
var currentEdit = null;
|
||||||
$(document).on("ajax:success","form[data-remote=true]",function(evt, data, xhr){
|
$(document).on("ajax:success","form[data-remote=true]",function(evt, data, xhr){
|
||||||
if(currentEdit){
|
if(currentEdit){
|
||||||
currentEdit.replaceWith($(data));
|
$('#assets_content').html($(data));
|
||||||
|
initAssets();
|
||||||
$("#editform").modal("hide");
|
$("#editform").modal("hide");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -125,17 +117,35 @@ $(document).ready(function(){
|
||||||
$("#editform").on("hidden",function(){
|
$("#editform").on("hidden",function(){
|
||||||
currentEdit = null;
|
currentEdit = null;
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function getUrlParam( paramName ) {
|
var showPreview = function(elem){
|
||||||
var reParam = new RegExp( '(?:[\?&]|&)' + paramName + '=([^&]+)', 'i' ) ;
|
var type = $("#ext_" + elem.val()).val(),
|
||||||
var match = window.location.search.match(reParam) ;
|
imgexp = new RegExp(/(\.|\/)(gif|jpe?g|png)$/i),
|
||||||
|
otherexp = new RegExp(/(\.|\/)(pdf|doc|docx|ppt|pptx|xls|xlsx)$/i)
|
||||||
return ( match && match.length > 1 ) ? match[ 1 ] : null ;
|
img = $("<img />"),
|
||||||
|
preview = $( ".preview-area" );
|
||||||
|
preview.text("Preview is loading...");
|
||||||
|
if( imgexp.test(type) ){
|
||||||
|
var url = $("#url_" + elem.val()).val();
|
||||||
|
img.attr("src",url).load(function(){
|
||||||
|
var ratio = this.width / this.height,
|
||||||
|
targetWidth = targetHeight = 200;
|
||||||
|
if( ratio < 1 ){
|
||||||
|
targetWidth = targetHeight * ratio;
|
||||||
|
}else{
|
||||||
|
targetHeight = targetWidth / ratio;
|
||||||
|
}
|
||||||
|
img.height(targetHeight).width(targetWidth);
|
||||||
|
preview.html(img);
|
||||||
|
})
|
||||||
|
}else if( otherexp.test(type) ) {
|
||||||
|
var t = type.replace(".",""),
|
||||||
|
url = "/assets/ft-icons/" + t + "/" + t + "-128_32.png";
|
||||||
|
img.attr('src', url).load(function(){
|
||||||
|
preview.html(img);
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
preview.html("Preview not available.");
|
||||||
}
|
}
|
||||||
var funcNum = getUrlParam( 'CKEditorFuncNum' ),
|
}
|
||||||
t = getUrlParam('CKEditor').split("_"),
|
|
||||||
language = t[t.length-1];
|
|
||||||
|
|
||||||
language = (language == "tw" ? "zh_tw" : language);
|
|
||||||
|
|
||||||
})
|
|
|
@ -2,7 +2,7 @@ class Admin::AssetsController < OrbitAdminController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@assets = current_user.assets
|
@assets = current_user.assets
|
||||||
@assets = @assets.page(params[:page]).per(10)
|
@assets = @assets.order_by(:created_at=>'desc').page(params[:page]).per(10)
|
||||||
render :layout => "assets"
|
render :layout => "assets"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,6 +22,10 @@ class Admin::AssetsController < OrbitAdminController
|
||||||
def update
|
def update
|
||||||
@asset = Asset.find(params[:id])
|
@asset = Asset.find(params[:id])
|
||||||
@asset.update_attributes(asset_params)
|
@asset.update_attributes(asset_params)
|
||||||
|
|
||||||
|
@assets = current_user.assets
|
||||||
|
@assets = @assets.order_by(:created_at=>'desc').page(params[:page]).per(10)
|
||||||
|
|
||||||
if asset_params['data'].blank?
|
if asset_params['data'].blank?
|
||||||
render layout: false
|
render layout: false
|
||||||
else
|
else
|
||||||
|
@ -39,7 +43,8 @@ class Admin::AssetsController < OrbitAdminController
|
||||||
|
|
||||||
def delete_files
|
def delete_files
|
||||||
Asset.where(:id.in=>params[:files]).destroy
|
Asset.where(:id.in=>params[:files]).destroy
|
||||||
@assets = current_user.assets.page(params[:page]).per(10)
|
@assets = current_user.assets
|
||||||
|
@assets = @assets.order_by(:created_at=>'desc').page(params[:page]).per(10)
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_upload
|
def file_upload
|
||||||
|
|
|
@ -1,17 +1,35 @@
|
||||||
<tr id="asset_<%= asset.id %>" class="with_action">
|
<table id="asset_sort_list" class="table main-list">
|
||||||
<td>
|
<thead>
|
||||||
<%= check_box_tag 'files[]', asset.id, false, :class => "checkbox_in_list" %>
|
<tr>
|
||||||
<input type="hidden" value="<%= asset.data.url %>" id="url_<%= asset.id %>" />
|
<th></th>
|
||||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
<th><%= t(:filename) %></th>
|
||||||
<input type="hidden" value="<%= asset.description_translations[locale] rescue nil %>" id="<%= locale %>_desc_<%= asset.id %>" />
|
<th><%= t(:size) %></th>
|
||||||
<input type="hidden" value="<%= asset.title_translations[locale] rescue nil %>" id="<%= locale %>_title_<%= asset.id %>" />
|
<th><%= t(:description) %></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="tbody_assets" class="sort-holder">
|
||||||
|
<% @assets.each do |asset| %>
|
||||||
|
<tr id="asset_<%= asset.id %>" class="with_action">
|
||||||
|
<td>
|
||||||
|
<%= check_box_tag 'files[]', asset.id, false, :class => "checkbox_in_list" %>
|
||||||
|
<input type="hidden" value="<%= asset.data.url %>" id="url_<%= asset.id %>" />
|
||||||
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||||
|
<input type="hidden" value="<%= asset.description_translations[locale] rescue nil %>" id="<%= locale %>_desc_<%= asset.id %>" />
|
||||||
|
<input type="hidden" value="<%= asset.title_translations[locale] rescue nil %>" id="<%= locale %>_title_<%= asset.id %>" />
|
||||||
|
<% end %>
|
||||||
|
<input type="hidden" value="<%= File.extname(asset.data.url) %>" id="ext_<%= asset.id %>" />
|
||||||
|
</td>
|
||||||
|
<td><%= asset.title_translations[I18n.locale.to_s] rescue nil %></td>
|
||||||
|
<td><%= number_to_human_size(asset.data.file.size) rescue nil %></td>
|
||||||
|
<td><%= asset.description rescue nil %></td>
|
||||||
|
<td>
|
||||||
|
<a href="<%= edit_admin_asset_path(asset) %>" class="editform"><%= t(:edit) %></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
<input type="hidden" value="<%= File.extname(asset.data.url) %>" id="ext_<%= asset.id %>" />
|
</tbody>
|
||||||
</td>
|
</table>
|
||||||
<td><%= asset.title_translations[I18n.locale.to_s] rescue nil %></td>
|
<div class="pagination pagination-centered">
|
||||||
<td><%= number_to_human_size(asset.data.file.size) rescue nil %></td>
|
<%= paginate @assets, :params => {:controller => 'assets', :action => 'index', :direction => params[:direction], :sort => params[:sort], :type => params[:type]}, :remote => true %>
|
||||||
<td><%= asset.description rescue nil %></td>
|
</div>
|
||||||
<td>
|
|
||||||
<a href="<%= edit_admin_asset_path(asset) %>" class="editform"><%= t(:edit) %></a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
|
@ -1,2 +1,2 @@
|
||||||
$("#tbody_assets").html("<%= j render :partial => 'asset', :collection => @assets %>");
|
$("#assets_content").html("<%= j render :partial => 'asset' %>");
|
||||||
$("#asset_pagination").html("<%= j paginate @assets, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>");
|
initAssets();
|
|
@ -231,22 +231,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<table id="asset_sort_list" class="table main-list">
|
<div id="assets_content">
|
||||||
<thead>
|
<%= render :partial => 'asset' %>
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<th><%= t(:filename) %></th>
|
|
||||||
<th><%= t(:size) %></th>
|
|
||||||
<th><%= t(:description) %></th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="tbody_assets" class="sort-holder">
|
|
||||||
<%= render :partial => 'asset', :collection => @assets %>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div class="pagination pagination-centered">
|
|
||||||
<%= paginate @assets, :params => {:direction => params[:direction], :sort => params[:sort], :type => params[:type]}, :remote => true %>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="panel_r" class="pull-left">
|
<div id="panel_r" class="pull-left">
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
$('#assets_content').html("<%= j render partial: 'asset' %>");
|
||||||
|
initAssets();
|
|
@ -1 +1 @@
|
||||||
<%= render :partial => 'asset', :object => @asset %>
|
<%= render partial: 'asset' %>
|
Loading…
Reference in New Issue