Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
This commit is contained in:
commit
0ee2d557cf
|
@ -27,7 +27,7 @@
|
||||||
:id => '_file',
|
:id => '_file',
|
||||||
:class => ie8? ? '':'file_selector',
|
:class => ie8? ? '':'file_selector',
|
||||||
:multiple => true,
|
:multiple => true,
|
||||||
:onchange => 'addInputFiles(this,"'+ checkBox.to_s+'");',
|
:onchange => 'addInputFilesCourseSource(this,"'+ checkBox.to_s+'");',
|
||||||
:style => ie8? ? '': 'display:none',
|
:style => ie8? ? '': 'display:none',
|
||||||
:data => {
|
:data => {
|
||||||
:max_file_size => Setting.attachment_max_size.to_i.kilobytes,
|
:max_file_size => Setting.attachment_max_size.to_i.kilobytes,
|
||||||
|
|
|
@ -88,7 +88,7 @@ function addFile_board(inputEl, file, eagerUpload, id) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFile(inputEl, file, eagerUpload,checkBox) {
|
function addFile(inputEl, file, eagerUpload) {
|
||||||
|
|
||||||
var attachments_frame = '#attachments_fields';
|
var attachments_frame = '#attachments_fields';
|
||||||
if ($(attachments_frame).children().length < 30) {
|
if ($(attachments_frame).children().length < 30) {
|
||||||
|
@ -99,72 +99,50 @@ function addFile(inputEl, file, eagerUpload,checkBox) {
|
||||||
'id': 'attachments_' + attachmentId,
|
'id': 'attachments_' + attachmentId,
|
||||||
'class': 'attachment'
|
'class': 'attachment'
|
||||||
});
|
});
|
||||||
//alert(checkBox);
|
|
||||||
if(checkBox){
|
|
||||||
fileSpan.append(
|
|
||||||
$('<input>', {
|
|
||||||
'type': 'text',
|
|
||||||
'class': 'filename readonly',
|
|
||||||
'name': 'attachments[' + attachmentId + '][filename]',
|
|
||||||
'readonly': 'readonly'
|
|
||||||
}).val(file.name),
|
|
||||||
$('<input>', {
|
|
||||||
'type': 'text',
|
|
||||||
'class': 'description',
|
|
||||||
'name': 'attachments[' + attachmentId + '][description]',
|
|
||||||
'maxlength': 254,
|
|
||||||
'placeholder': $(inputEl).data('descriptionPlaceholder')
|
|
||||||
}).toggle(!eagerUpload),
|
|
||||||
$('<div>', {
|
|
||||||
'class': 'div_attachments',
|
|
||||||
'name': 'div_' + 'attachments_' + attachmentId
|
|
||||||
})
|
|
||||||
).appendTo('#attachments_fields');
|
|
||||||
}else {
|
|
||||||
fileSpan.append(
|
|
||||||
$('<input>', {
|
|
||||||
'type': 'text',
|
|
||||||
'class': 'filename readonly',
|
|
||||||
'name': 'attachments[' + attachmentId + '][filename]',
|
|
||||||
'readonly': 'readonly'
|
|
||||||
}).val(file.name),
|
|
||||||
$('<input>', {
|
|
||||||
'type': 'text',
|
|
||||||
'class': 'description',
|
|
||||||
'name': 'attachments[' + attachmentId + '][description]',
|
|
||||||
'maxlength': 254,
|
|
||||||
'placeholder': $(inputEl).data('descriptionPlaceholder')
|
|
||||||
}).toggle(!eagerUpload),
|
|
||||||
$('<span >' + $(inputEl).data('fieldIsPublic') + ':</span>').attr({
|
|
||||||
'class': 'ispublic-label'
|
|
||||||
}),
|
|
||||||
$('<input>', {
|
|
||||||
'type': 'checkbox',
|
|
||||||
'class': 'is_public_checkbox',
|
|
||||||
'value': 1,
|
|
||||||
'name': 'attachments[' + attachmentId + '][is_public_checkbox]',
|
|
||||||
checked: 'checked'
|
|
||||||
}).toggle(!eagerUpload),
|
|
||||||
$('<a> </a>').attr({
|
|
||||||
'href': "#",
|
|
||||||
'class': 'remove-upload'
|
|
||||||
}).click(function () {
|
|
||||||
if (confirm($(inputEl).data('areYouSure'))) {
|
|
||||||
removeFile();
|
|
||||||
if (!eagerUpload) {
|
|
||||||
(function (e) {
|
|
||||||
reload(e);
|
|
||||||
})(fileSpan);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}).toggle(!eagerUpload),
|
fileSpan.append(
|
||||||
$('<div>', {
|
$('<input>', {
|
||||||
'class': 'div_attachments',
|
'type': 'text',
|
||||||
'name': 'div_' + 'attachments_' + attachmentId
|
'class': 'filename readonly',
|
||||||
})
|
'name': 'attachments[' + attachmentId + '][filename]',
|
||||||
).appendTo('#attachments_fields');
|
'readonly': 'readonly'
|
||||||
}
|
}).val(file.name),
|
||||||
|
$('<input>', {
|
||||||
|
'type': 'text',
|
||||||
|
'class': 'description',
|
||||||
|
'name': 'attachments[' + attachmentId + '][description]',
|
||||||
|
'maxlength': 254,
|
||||||
|
'placeholder': $(inputEl).data('descriptionPlaceholder')
|
||||||
|
}).toggle(!eagerUpload),
|
||||||
|
$('<span >' + $(inputEl).data('fieldIsPublic') + ':</span>').attr({
|
||||||
|
'class': 'ispublic-label'
|
||||||
|
}),
|
||||||
|
$('<input>', {
|
||||||
|
'type': 'checkbox',
|
||||||
|
'class': 'is_public_checkbox',
|
||||||
|
'value': 1,
|
||||||
|
'name': 'attachments[' + attachmentId + '][is_public_checkbox]',
|
||||||
|
checked: 'checked'
|
||||||
|
}).toggle(!eagerUpload),
|
||||||
|
$('<a> </a>').attr({
|
||||||
|
'href': "#",
|
||||||
|
'class': 'remove-upload'
|
||||||
|
}).click(function() {
|
||||||
|
if (confirm($(inputEl).data('areYouSure'))) {
|
||||||
|
removeFile();
|
||||||
|
if (!eagerUpload) {
|
||||||
|
(function(e) {
|
||||||
|
reload(e);
|
||||||
|
})(fileSpan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}).toggle(!eagerUpload),
|
||||||
|
$('<div>', {
|
||||||
|
'class': 'div_attachments',
|
||||||
|
'name': 'div_' + 'attachments_' + attachmentId
|
||||||
|
})
|
||||||
|
).appendTo('#attachments_fields');
|
||||||
|
|
||||||
if (eagerUpload) {
|
if (eagerUpload) {
|
||||||
ajaxUpload(file, attachmentId, fileSpan, inputEl);
|
ajaxUpload(file, attachmentId, fileSpan, inputEl);
|
||||||
|
@ -195,9 +173,9 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) {
|
||||||
ajaxUpload.uploading++;
|
ajaxUpload.uploading++;
|
||||||
|
|
||||||
uploadBlob(file, $(inputEl).data('upload-path'), attachmentId, {
|
uploadBlob(file, $(inputEl).data('upload-path'), attachmentId, {
|
||||||
loadstartEventHandler: onLoadstart.bind(progressSpan),
|
loadstartEventHandler: onLoadstart.bind(progressSpan),
|
||||||
progressEventHandler: onProgress.bind(progressSpan)
|
progressEventHandler: onProgress.bind(progressSpan)
|
||||||
})
|
})
|
||||||
.done(function(result) {
|
.done(function(result) {
|
||||||
progressSpan.progressbar('value', 100).remove();
|
progressSpan.progressbar('value', 100).remove();
|
||||||
fileSpan.find('input.description, a').css('display', 'inline-block');
|
fileSpan.find('input.description, a').css('display', 'inline-block');
|
||||||
|
@ -284,22 +262,22 @@ function removeFile() {
|
||||||
//gcm delete all file
|
//gcm delete all file
|
||||||
//modify by yutao 2015-5-14 <20><>1<EFBFBD><31>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>ϴ<EFBFBD><CFB4>ؼ<EFBFBD>ʱ<EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bug <20>ʸ<EFBFBD>֮ start
|
//modify by yutao 2015-5-14 <20><>1<EFBFBD><31>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>ϴ<EFBFBD><CFB4>ؼ<EFBFBD>ʱ<EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bug <20>ʸ<EFBFBD>֮ start
|
||||||
function removeAll(containerid) {
|
function removeAll(containerid) {
|
||||||
if (confirm(deleteallfiles)) {
|
if (confirm(deleteallfiles)) {
|
||||||
if (containerid == undefined) {
|
if (containerid == undefined) {
|
||||||
$(".remove-upload").removeAttr("data-confirm");
|
$(".remove-upload").removeAttr("data-confirm");
|
||||||
$(".remove-upload").click();
|
$(".remove-upload").click();
|
||||||
} else {
|
} else {
|
||||||
var arr = $(".remove-upload").filter(function() {
|
var arr = $(".remove-upload").filter(function() {
|
||||||
return $(this).data('containerid') == containerid;
|
return $(this).data('containerid') == containerid;
|
||||||
});
|
});
|
||||||
arr.removeAttr("data-confirm");
|
arr.removeAttr("data-confirm");
|
||||||
arr.click();
|
arr.click();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// return false;
|
|
||||||
}
|
}
|
||||||
//modify by yutao 2015-5-14 <20><>1<EFBFBD><31>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>ϴ<EFBFBD><CFB4>ؼ<EFBFBD>ʱ<EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bug <20>ʸ<EFBFBD>֮ end
|
// return false;
|
||||||
//gcm
|
}
|
||||||
|
//modify by yutao 2015-5-14 <20><>1<EFBFBD><31>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>ϴ<EFBFBD><CFB4>ؼ<EFBFBD>ʱ<EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bug <20>ʸ<EFBFBD>֮ end
|
||||||
|
//gcm
|
||||||
|
|
||||||
function uploadBlob(blob, uploadUrl, attachmentId, options) {
|
function uploadBlob(blob, uploadUrl, attachmentId, options) {
|
||||||
|
|
||||||
|
@ -335,11 +313,10 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addInputFiles(inputEl) {
|
function addInputFiles(inputEl) {
|
||||||
checkBox = arguments[1] == 'public' ? false : true;
|
|
||||||
// var clearedFileInput = $(inputEl).clone().val('');
|
// var clearedFileInput = $(inputEl).clone().val('');
|
||||||
if (inputEl.files) {
|
if (inputEl.files) {
|
||||||
// upload files using ajax
|
// upload files using ajax
|
||||||
uploadAndAttachFiles(inputEl.files, inputEl,checkBox);
|
uploadAndAttachFiles(inputEl.files, inputEl);
|
||||||
// $(inputEl).remove();
|
// $(inputEl).remove();
|
||||||
} else {
|
} else {
|
||||||
// browser not supporting the file API, upload on form submission
|
// browser not supporting the file API, upload on form submission
|
||||||
|
@ -386,7 +363,7 @@ function addInputFiles_board(inputEl, id) {
|
||||||
//clearedFileInput.insertAfter('#attachments_fields');
|
//clearedFileInput.insertAfter('#attachments_fields');
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadAndAttachFiles(files, inputEl,checkBox) {
|
function uploadAndAttachFiles(files, inputEl) {
|
||||||
|
|
||||||
var maxFileSize = $(inputEl).data('max-file-size');
|
var maxFileSize = $(inputEl).data('max-file-size');
|
||||||
var maxFileSizeExceeded = $(inputEl).data('max-file-size-message');
|
var maxFileSizeExceeded = $(inputEl).data('max-file-size-message');
|
||||||
|
@ -401,7 +378,7 @@ function uploadAndAttachFiles(files, inputEl,checkBox) {
|
||||||
window.alert(maxFileSizeExceeded);
|
window.alert(maxFileSizeExceeded);
|
||||||
} else {
|
} else {
|
||||||
$.each(files, function() {
|
$.each(files, function() {
|
||||||
addFile(inputEl, this, true,checkBox);
|
addFile(inputEl, this, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -490,3 +467,139 @@ $(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//课程课件
|
||||||
|
function addInputFilesCourseSource(inputEl) {
|
||||||
|
checkBox = arguments[1] == 'public' ? false : true;
|
||||||
|
// var clearedFileInput = $(inputEl).clone().val('');
|
||||||
|
if (inputEl.files) {
|
||||||
|
// upload files using ajax
|
||||||
|
uploadAndAttachFilesCourseSource(inputEl.files, inputEl,checkBox);
|
||||||
|
// $(inputEl).remove();
|
||||||
|
} else {
|
||||||
|
// browser not supporting the file API, upload on form submission
|
||||||
|
var attachmentId;
|
||||||
|
var aFilename = inputEl.value.split(/\/|\\/);
|
||||||
|
var count = $('#attachments_fields>span').length;
|
||||||
|
attachmentId = addFile(inputEl, {
|
||||||
|
name: aFilename[aFilename.length - 1]
|
||||||
|
}, false);
|
||||||
|
if (attachmentId) {
|
||||||
|
$(inputEl).attr({
|
||||||
|
name: 'attachments[' + attachmentId + '][file]'
|
||||||
|
}).hide();
|
||||||
|
if (count <= 0) count = 1;
|
||||||
|
$('#upload_file_count').html("<span id=\"count\">" + count + "</span>" + $(inputEl).data('fileCount'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//clearedFileInput.insertAfter('#attachments_fields');
|
||||||
|
}
|
||||||
|
|
||||||
|
function uploadAndAttachFilesCourseSource(files, inputEl,checkBox) {
|
||||||
|
|
||||||
|
var maxFileSize = $(inputEl).data('max-file-size');
|
||||||
|
var maxFileSizeExceeded = $(inputEl).data('max-file-size-message');
|
||||||
|
|
||||||
|
var sizeExceeded = false;
|
||||||
|
$.each(files, function() {
|
||||||
|
if (this.size && maxFileSize != null && this.size > parseInt(maxFileSize)) {
|
||||||
|
sizeExceeded = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (sizeExceeded) {
|
||||||
|
window.alert(maxFileSizeExceeded);
|
||||||
|
} else {
|
||||||
|
$.each(files, function() {
|
||||||
|
addFileCourseSource(inputEl, this, true,checkBox);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addFileCourseSource(inputEl, file, eagerUpload,checkBox) {
|
||||||
|
|
||||||
|
var attachments_frame = '#attachments_fields';
|
||||||
|
if ($(attachments_frame).children().length < 30) {
|
||||||
|
deleteallfiles = $(inputEl).data('deleteAllFiles');
|
||||||
|
var attachmentId = addFile.nextAttachmentId++;
|
||||||
|
|
||||||
|
var fileSpan = $('<span>', {
|
||||||
|
'id': 'attachments_' + attachmentId,
|
||||||
|
'class': 'attachment'
|
||||||
|
});
|
||||||
|
//alert(checkBox);
|
||||||
|
if(checkBox){
|
||||||
|
fileSpan.append(
|
||||||
|
$('<input>', {
|
||||||
|
'type': 'text',
|
||||||
|
'class': 'filename readonly',
|
||||||
|
'name': 'attachments[' + attachmentId + '][filename]',
|
||||||
|
'readonly': 'readonly'
|
||||||
|
}).val(file.name),
|
||||||
|
$('<input>', {
|
||||||
|
'type': 'text',
|
||||||
|
'class': 'description',
|
||||||
|
'name': 'attachments[' + attachmentId + '][description]',
|
||||||
|
'maxlength': 254,
|
||||||
|
'placeholder': $(inputEl).data('descriptionPlaceholder')
|
||||||
|
}).toggle(!eagerUpload),
|
||||||
|
$('<div>', {
|
||||||
|
'class': 'div_attachments',
|
||||||
|
'name': 'div_' + 'attachments_' + attachmentId
|
||||||
|
})
|
||||||
|
).appendTo('#attachments_fields');
|
||||||
|
}else {
|
||||||
|
fileSpan.append(
|
||||||
|
$('<input>', {
|
||||||
|
'type': 'text',
|
||||||
|
'class': 'filename readonly',
|
||||||
|
'name': 'attachments[' + attachmentId + '][filename]',
|
||||||
|
'readonly': 'readonly'
|
||||||
|
}).val(file.name),
|
||||||
|
$('<input>', {
|
||||||
|
'type': 'text',
|
||||||
|
'class': 'description',
|
||||||
|
'name': 'attachments[' + attachmentId + '][description]',
|
||||||
|
'maxlength': 254,
|
||||||
|
'placeholder': $(inputEl).data('descriptionPlaceholder')
|
||||||
|
}).toggle(!eagerUpload),
|
||||||
|
$('<span >' + $(inputEl).data('fieldIsPublic') + ':</span>').attr({
|
||||||
|
'class': 'ispublic-label'
|
||||||
|
}),
|
||||||
|
$('<input>', {
|
||||||
|
'type': 'checkbox',
|
||||||
|
'class': 'is_public_checkbox',
|
||||||
|
'value': 1,
|
||||||
|
'name': 'attachments[' + attachmentId + '][is_public_checkbox]',
|
||||||
|
checked: 'checked'
|
||||||
|
}).toggle(!eagerUpload),
|
||||||
|
$('<a> </a>').attr({
|
||||||
|
'href': "#",
|
||||||
|
'class': 'remove-upload'
|
||||||
|
}).click(function () {
|
||||||
|
if (confirm($(inputEl).data('areYouSure'))) {
|
||||||
|
removeFile();
|
||||||
|
if (!eagerUpload) {
|
||||||
|
(function (e) {
|
||||||
|
reload(e);
|
||||||
|
})(fileSpan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}).toggle(!eagerUpload),
|
||||||
|
$('<div>', {
|
||||||
|
'class': 'div_attachments',
|
||||||
|
'name': 'div_' + 'attachments_' + attachmentId
|
||||||
|
})
|
||||||
|
).appendTo('#attachments_fields');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eagerUpload) {
|
||||||
|
ajaxUpload(file, attachmentId, fileSpan, inputEl);
|
||||||
|
|
||||||
|
}
|
||||||
|
return attachmentId;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
addFileCourseSource.nextAttachmentId = 1;
|
Loading…
Reference in New Issue