', {
- 'class': 'div_attachments',
- 'name': 'div_' + 'attachments_' + attachmentId
- })
- ).appendTo('#attachments_fields');
- }else {
- fileSpan.append(
- $('
', {
- 'type': 'text',
- 'class': 'filename readonly',
- 'name': 'attachments[' + attachmentId + '][filename]',
- 'readonly': 'readonly'
- }).val(file.name),
- $('
', {
- 'type': 'text',
- 'class': 'description',
- 'name': 'attachments[' + attachmentId + '][description]',
- 'maxlength': 254,
- 'placeholder': $(inputEl).data('descriptionPlaceholder')
- }).toggle(!eagerUpload),
- $('
').attr({
- 'class': 'ispublic-label'
- }),
- $('
', {
- 'type': 'checkbox',
- 'class': 'is_public_checkbox',
- 'value': 1,
- 'name': 'attachments[' + attachmentId + '][is_public_checkbox]',
- checked: 'checked'
- }).toggle(!eagerUpload),
- $('
').attr({
- 'href': "#",
- 'class': 'remove-upload'
- }).click(function () {
- if (confirm($(inputEl).data('areYouSure'))) {
- removeFile();
- if (!eagerUpload) {
- (function (e) {
- reload(e);
- })(fileSpan);
- }
- }
- }).toggle(!eagerUpload),
- $('
', {
- 'class': 'div_attachments',
- 'name': 'div_' + 'attachments_' + attachmentId
- })
- ).appendTo('#attachments_fields');
- }
+ fileSpan.append(
+ $('
', {
+ 'type': 'text',
+ 'class': 'filename readonly',
+ 'name': 'attachments[' + attachmentId + '][filename]',
+ 'readonly': 'readonly'
+ }).val(file.name),
+ $('
', {
+ 'type': 'text',
+ 'class': 'description',
+ 'name': 'attachments[' + attachmentId + '][description]',
+ 'maxlength': 254,
+ 'placeholder': $(inputEl).data('descriptionPlaceholder')
+ }).toggle(!eagerUpload),
+ $('
' + $(inputEl).data('fieldIsPublic') + ':').attr({
+ 'class': 'ispublic-label'
+ }),
+ $('
', {
+ 'type': 'checkbox',
+ 'class': 'is_public_checkbox',
+ 'value': 1,
+ 'name': 'attachments[' + attachmentId + '][is_public_checkbox]',
+ checked: 'checked'
+ }).toggle(!eagerUpload),
+ $('
 ').attr({
+ 'href': "#",
+ 'class': 'remove-upload'
+ }).click(function() {
+ if (confirm($(inputEl).data('areYouSure'))) {
+ removeFile();
+ if (!eagerUpload) {
+ (function(e) {
+ reload(e);
+ })(fileSpan);
+ }
+ }
+
+ }).toggle(!eagerUpload),
+ $('
', {
+ 'class': 'div_attachments',
+ 'name': 'div_' + 'attachments_' + attachmentId
+ })
+ ).appendTo('#attachments_fields');
if (eagerUpload) {
ajaxUpload(file, attachmentId, fileSpan, inputEl);
@@ -195,9 +173,9 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) {
ajaxUpload.uploading++;
uploadBlob(file, $(inputEl).data('upload-path'), attachmentId, {
- loadstartEventHandler: onLoadstart.bind(progressSpan),
- progressEventHandler: onProgress.bind(progressSpan)
- })
+ loadstartEventHandler: onLoadstart.bind(progressSpan),
+ progressEventHandler: onProgress.bind(progressSpan)
+ })
.done(function(result) {
progressSpan.progressbar('value', 100).remove();
fileSpan.find('input.description, a').css('display', 'inline-block');
@@ -284,22 +262,22 @@ function removeFile() {
//gcm delete all file
//modify by yutao 2015-5-14 ��1��ҳ����ڶ���ϴ��ؼ�ʱ�˿�������bug �ʸ�֮ start
function removeAll(containerid) {
- if (confirm(deleteallfiles)) {
- if (containerid == undefined) {
- $(".remove-upload").removeAttr("data-confirm");
- $(".remove-upload").click();
- } else {
- var arr = $(".remove-upload").filter(function() {
- return $(this).data('containerid') == containerid;
- });
- arr.removeAttr("data-confirm");
- arr.click();
- }
+ if (confirm(deleteallfiles)) {
+ if (containerid == undefined) {
+ $(".remove-upload").removeAttr("data-confirm");
+ $(".remove-upload").click();
+ } else {
+ var arr = $(".remove-upload").filter(function() {
+ return $(this).data('containerid') == containerid;
+ });
+ arr.removeAttr("data-confirm");
+ arr.click();
}
- // return false;
}
- //modify by yutao 2015-5-14 ��1��ҳ����ڶ���ϴ��ؼ�ʱ�˿�������bug �ʸ�֮ end
- //gcm
+ // return false;
+}
+//modify by yutao 2015-5-14 ��1��ҳ����ڶ���ϴ��ؼ�ʱ�˿�������bug �ʸ�֮ end
+//gcm
function uploadBlob(blob, uploadUrl, attachmentId, options) {
@@ -335,11 +313,10 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) {
}
function addInputFiles(inputEl) {
- checkBox = arguments[1] == 'public' ? false : true;
// var clearedFileInput = $(inputEl).clone().val('');
if (inputEl.files) {
// upload files using ajax
- uploadAndAttachFiles(inputEl.files, inputEl,checkBox);
+ uploadAndAttachFiles(inputEl.files, inputEl);
// $(inputEl).remove();
} else {
// browser not supporting the file API, upload on form submission
@@ -386,7 +363,7 @@ function addInputFiles_board(inputEl, id) {
//clearedFileInput.insertAfter('#attachments_fields');
}
-function uploadAndAttachFiles(files, inputEl,checkBox) {
+function uploadAndAttachFiles(files, inputEl) {
var maxFileSize = $(inputEl).data('max-file-size');
var maxFileSizeExceeded = $(inputEl).data('max-file-size-message');
@@ -401,7 +378,7 @@ function uploadAndAttachFiles(files, inputEl,checkBox) {
window.alert(maxFileSizeExceeded);
} else {
$.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("
" + count + "" + $(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 = $('
', {
+ 'id': 'attachments_' + attachmentId,
+ 'class': 'attachment'
+ });
+ //alert(checkBox);
+ if(checkBox){
+ fileSpan.append(
+ $('', {
+ 'type': 'text',
+ 'class': 'filename readonly',
+ 'name': 'attachments[' + attachmentId + '][filename]',
+ 'readonly': 'readonly'
+ }).val(file.name),
+ $('', {
+ 'type': 'text',
+ 'class': 'description',
+ 'name': 'attachments[' + attachmentId + '][description]',
+ 'maxlength': 254,
+ 'placeholder': $(inputEl).data('descriptionPlaceholder')
+ }).toggle(!eagerUpload),
+ $('', {
+ 'class': 'div_attachments',
+ 'name': 'div_' + 'attachments_' + attachmentId
+ })
+ ).appendTo('#attachments_fields');
+ }else {
+ fileSpan.append(
+ $('
', {
+ 'type': 'text',
+ 'class': 'filename readonly',
+ 'name': 'attachments[' + attachmentId + '][filename]',
+ 'readonly': 'readonly'
+ }).val(file.name),
+ $('
', {
+ 'type': 'text',
+ 'class': 'description',
+ 'name': 'attachments[' + attachmentId + '][description]',
+ 'maxlength': 254,
+ 'placeholder': $(inputEl).data('descriptionPlaceholder')
+ }).toggle(!eagerUpload),
+ $('
' + $(inputEl).data('fieldIsPublic') + ':').attr({
+ 'class': 'ispublic-label'
+ }),
+ $('
', {
+ 'type': 'checkbox',
+ 'class': 'is_public_checkbox',
+ 'value': 1,
+ 'name': 'attachments[' + attachmentId + '][is_public_checkbox]',
+ checked: 'checked'
+ }).toggle(!eagerUpload),
+ $('
 ').attr({
+ 'href': "#",
+ 'class': 'remove-upload'
+ }).click(function () {
+ if (confirm($(inputEl).data('areYouSure'))) {
+ removeFile();
+ if (!eagerUpload) {
+ (function (e) {
+ reload(e);
+ })(fileSpan);
+ }
+ }
+
+ }).toggle(!eagerUpload),
+ $('
', {
+ 'class': 'div_attachments',
+ 'name': 'div_' + 'attachments_' + attachmentId
+ })
+ ).appendTo('#attachments_fields');
+ }
+
+ if (eagerUpload) {
+ ajaxUpload(file, attachmentId, fileSpan, inputEl);
+
+ }
+ return attachmentId;
+ }
+ return null;
+}
+addFileCourseSource.nextAttachmentId = 1;
\ No newline at end of file