small bug fix for inserting and delete button.

This commit is contained in:
Harry Bomrah 2013-09-10 14:34:34 +08:00 committed by saurabhbhatia
parent 9e10a3c944
commit 8c98645a69
2 changed files with 103 additions and 103 deletions

View File

@ -0,0 +1,102 @@
!function ($) {
$.fn.checkListLength = function (param){
_defaultSettings = {
onlyOne: null,
};
_set = $.extend(_defaultSettings, param);
$this = this;
$li = this.children('li');
$dropzone = $('#dropzone');
if(($li.length - _set.onlyOne) == 0) {
$('#dropzone').fadeIn(300);
} else {
$('#dropzone').fadeOut(300);
};
$('#file-list').nanoScroller({ scrollTop: 0, iOSNativeScrolling: true });
}
}(window.jQuery);
$(function () {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
maxFileSize: 5000000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|pdf|doc|docx|ppt|pptx|xls|xlsx)$/i,
dropZone: $('#dropzone'),
headers:{
'X-CSRF-Token': $('meta[name="csrf-token"]').attr("content")
}
}).bind('fileuploadstop', function (e, data) {
window.location.reload();
});
});
$(document).ready(function(){
var insertBtn = $("#insert_btn"),
deleteBtn = $("#delete_btn"),
url = null;
$("#asset_sort_list").on(clickEvent,"input[type=checkbox]",function(){
if($("#asset_sort_list input[type=checkbox]:checked").length == 1){
url = window.location.protocol + "//" + window.location.host + $("#url_" + $("input[type=checkbox]:checked").val()).val();
insertBtn.show();
}else{
insertBtn.hide();
url = null;
}
if($("#asset_sort_list input[type=checkbox]:checked").length)
deleteBtn.show();
else
deleteBtn.hide();
})
insertBtn.bind(clickEvent,function(){
var alt_text = $("#"+language+"_desc_"+$("input[type=checkbox]:checked").val()).val();
alt_text = (alt_text ? alt_text : "This is alt text");
if(url){
window.opener.CKEDITOR.tools.callFunction( funcNum, url, function() {
var element,
dialog = this.getDialog();
if ( dialog.getName() == 'image' ) {
element = dialog.getContentElement( 'info', 'txtAlt' );
if ( element )
element.setValue( alt_text );
}
});
window.close();
}
})
deleteBtn.bind( clickEvent,function(){
var items_to_delete = [],
type = getUrlParam("type");
$("input[type=checkbox]:checked").each(function(){
items_to_delete.push($(this).val());
})
$.post("<%= delete_files_admin_assets_path %>",{"files":items_to_delete,"type":type},function(){
deleteBtn.hide();
})
})
var currentEdit = null;
$(document).on("ajax:success","form[data-remote=true]",function(evt, data, xhr){
currentEdit.replaceWith($(data));
$("#editform").modal("hide");
})
$("#asset_sort_list").on(clickEvent,".editform",function(){
currentEdit = $(this).parent().parent();
$.get($(this).attr("href"),function(data){
$("#editform").html(data).modal("show");
})
return false;
})
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 funcNum = getUrlParam( 'CKEditorFuncNum' ),
t = getUrlParam('CKEditor').split("_"),
language = t[t.length-1];
language = (language == "tw" ? "zh_tw" : language);
})

View File

@ -317,111 +317,9 @@
<%= javascript_include_tag "file-upload/jquery.fileupload-fp.js" %> <%= javascript_include_tag "file-upload/jquery.fileupload-fp.js" %>
<%= javascript_include_tag "file-upload/jquery.fileupload-ui.js" %> <%= javascript_include_tag "file-upload/jquery.fileupload-ui.js" %>
<%= javascript_include_tag "file-upload/drop-zone.js" %> <%= javascript_include_tag "file-upload/drop-zone.js" %>
<%= javascript_include_tag "admin/filemanager.js" %>
<% end %> <% end %>
<script type="text/javascript">
!function ($) {
$.fn.checkListLength = function (param){
_defaultSettings = {
onlyOne: null,
};
_set = $.extend(_defaultSettings, param);
$this = this;
$li = this.children('li');
$dropzone = $('#dropzone');
if(($li.length - _set.onlyOne) == 0) {
$('#dropzone').fadeIn(300);
} else {
$('#dropzone').fadeOut(300);
};
$('#file-list').nanoScroller({ scrollTop: 0, iOSNativeScrolling: true });
}
}(window.jQuery);
$(function () {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
maxFileSize: 5000000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|pdf|doc|docx|ppt|pptx|xls|xlsx)$/i,
dropZone: $('#dropzone'),
headers:{
'X-CSRF-Token': $('meta[name="csrf-token"]').attr("content")
}
}).bind('fileuploadstop', function (e, data) {
window.location.reload();
});
});
$(document).ready(function(){
var insertBtn = $("#insert_btn"),
deleteBtn = $("#delete_btn"),
url = null;
$("#asset_sort_list").on(clickEvent,"input[type=checkbox]",function(){
if($("input[type=checkbox]:checked").length == 1){
url = window.location.protocol + "//" + window.location.host + $("#url_" + $("input[type=checkbox]:checked").val()).val();
insertBtn.show();
}else{
insertBtn.hide();
url = null;
}
if($("input[type=checkbox]:checked").length)
deleteBtn.show();
else
deleteBtn.hide();
})
insertBtn.bind(clickEvent,function(){
var alt_text = $("#"+language+"_desc_"+$("input[type=checkbox]:checked").val()).val();
alt_text = (alt_text ? alt_text : "This is alt text");
if(url){
window.opener.CKEDITOR.tools.callFunction( funcNum, url, function() {
var element,
dialog = this.getDialog();
if ( dialog.getName() == 'image' ) {
element = dialog.getContentElement( 'info', 'txtAlt' );
if ( element )
element.setValue( alt_text );
}
});
window.close();
}
})
deleteBtn.bind( clickEvent,function(){
var items_to_delete = [],
type = getUrlParam("type");
$("input[type=checkbox]:checked").each(function(){
items_to_delete.push($(this).val());
})
$.post("<%= delete_files_admin_assets_path %>",{"files":items_to_delete,"type":type},function(){
deleteBtn.hide();
})
})
var currentEdit = null;
$(document).on("ajax:success","form[data-remote=true]",function(evt, data, xhr){
currentEdit.replaceWith($(data));
$("#editform").modal("hide");
})
$("#asset_sort_list").on(clickEvent,".editform",function(){
currentEdit = $(this).parent().parent();
$.get($(this).attr("href"),function(data){
$("#editform").html(data).modal("show");
})
return false;
})
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 funcNum = getUrlParam( 'CKEditorFuncNum' ),
t = getUrlParam('CKEditor').split("_"),
language = t[t.length-1];
language = (language == "tw" ? "zh_tw" : language);
})
</script>
<script id="template-upload" type="text/x-tmpl"> <script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %} {% for (var i=0, file; file=o.files[i]; i++) { %}
<li class="template-upload fade"> <li class="template-upload fade">