|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776 |
- /* Redmine - project management software
- Copyright (C) 2006-2013 Jean-Philippe Lang */
-
- function postUpMsg(attachmentId) {
- $.ajax({
- url: '/attachments/renderTag',
- type: "GET",
- data: {
- attachmentId: attachmentId
- }
-
- })
- }
-
- function reload(fileSpan) {
- fileSpan.remove();
- $('#upload_file_count').html("<%= l(:label_no_file_uploaded)%>");
- $old_file = $("#_file");
- $new_file = $old_file.clone(true);
- $old_file.replaceWith($new_file);
- $new_file.show();
-
- }
-
- function addFile_board(inputEl, file, eagerUpload, id,btnId) {
-
- var attachments_frame = '#attachments_fields' + id;
- if ($(attachments_frame).children().length < 30) {
- deleteallfiles = $(inputEl).data('deleteAllFiles');
- var attachmentId = addFile.nextAttachmentId++;
-
- var fileSpan = $('<span>', {
- 'id': 'attachments_' + attachmentId,
- 'class': 'attachment'
- });
-
- fileSpan.append(
- $('<input>', {
- 'type': 'text',
- 'class': 'upload_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',
- 'data-containerid': id
- }).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_frame);
-
- if (eagerUpload) {
- ajaxUpload(file, attachmentId, fileSpan, inputEl,btnId);
-
- }
- return attachmentId;
- }
- return null;
- }
-
- function addFile(inputEl, file, eagerUpload,btnId) {
-
- var attachments_frame = '#attachments_fields';
- // $("#issue_confirm").attr('href', '#');
- $('#issue_confirm').attr("disabled",true);
- $('#issue_confirm').css('background-color','#c1c1c1');
- $('#issue_confirm').css('cursor','default');
- if (true) {
- deleteallfiles = $(inputEl).data('deleteAllFiles');
- var attachmentId = addFile.nextAttachmentId++;
-
- var fileSpan = $('<span>', {
- 'id': 'attachments_' + attachmentId,
- 'class': 'attachment'
- });
-
- fileSpan.append(
- $('<input>', {
- 'type': 'text',
- 'class': 'upload_filename readonly hidden',
- 'name': 'attachments[' + attachmentId + '][filename]',
- 'readonly': 'readonly',
- 'style': 'border:none; max-width:270px;'
- }).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',
- 'style': 'vertical-align:top;'
- }).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,btnId);
-
- }
- return attachmentId;
- }
- return null;
- }
- addFile.nextAttachmentId = 1;
-
- function addReviseFile(inputEl, file, eagerUpload,btnId) {
-
- 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'
- });
-
- fileSpan.append(
- $('<input>', {
- 'type': 'text',
- 'class': 'upload_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'))) {
- removeReviseFile();
- if (!eagerUpload) {
- (function(e) {
- reload(e);
- })(fileSpan);
- }
- }
-
- }).toggle(!eagerUpload),
- $('<div>', {
- 'class': 'div_attachments',
- 'name': 'div_' + 'attachments_' + attachmentId
- })
- ).appendTo('#attachments_fields');
-
- $("#uploadReviseBox").addClass('disable_link');
- $("#choose_revise_attach").attr("onclick","return false;");
-
- if (eagerUpload) {
- ajaxUpload(file, attachmentId, fileSpan, inputEl,btnId);
- }
- return attachmentId;
- }
- return null;
- }
-
- function ajaxUpload(file, attachmentId, fileSpan, inputEl,btnId) {
- //上传开始调用函数
- function onLoadstart(e) {
- fileSpan.removeClass('ajax-waiting');
- fileSpan.addClass('ajax-loading');
- $('input:submit', $(this).parents('form')).attr('disabled', 'disabled');
- }
- //更改progressbar的值
- function onProgress(e) {
- if (e.lengthComputable) {
- this.progressbar('value', e.loaded * 100 / e.total);
- }
- }
-
- function actualUpload(file, attachmentId, fileSpan, inputEl,btnId) {
-
- ajaxUpload.uploading++;
-
- uploadBlob(file, $(inputEl).data('upload-path'), attachmentId, {
- 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');
- fileSpan.find('input.is_public_checkbox, a').css('display', 'inline-block');
- })
- .fail(function(result) {
- progressSpan.text("网络错误");
- if ($("#network_issue")) { //在上传处都要给出一个network_issue的div用来显示错误
- $("#network_issue").show();
- }
- }).always(function() {
- ajaxUpload.uploading--;
- fileSpan.removeClass('ajax-loading');
- var containerid = $(inputEl).data('containerid');//多个上传控件需要的容器id
- if(containerid == undefined ){
- var count = 1;//同步上传参数为1,所以不需要去获取正在上传的文件就知道是1
- $('#upload_file_count').html("<span id=\"count\">" + count + "</span>" + $(inputEl).data('lebelFileUploding'));
- }
- else{
- var count = 1;
- $('#upload_file_count' + containerid).html("<span id=\"count\">" + count + "</span>" + $(inputEl).data('lebelFileUploding'));
- }
- var form = fileSpan.parents('form');
- if (form.queue('upload').length == 0 && ajaxUpload.uploading == 0) { //所有文件上传完毕,更改状态
- $('input:submit', form).removeAttr('disabled');
- $('#' + btnId).removeAttr("disabled");
- $('#' + btnId).val('确定')
- $('#' + btnId).css('background-color', '#269ac9')
- if(containerid == undefined ){
- var count = $('#attachments_fields>span').length;
- $('#upload_file_count').html("<span id=\"count\">" + count + "</span>" + $(inputEl).data('fileCount'));
- }else{
- var count = $('#attachments_fields' + containerid + '>span').length;
- $('#upload_file_count'+containerid).html("<span id=\"count\">" + count + "</span>" + $(inputEl).data('fileCount'));
- }
-
- }
- form.dequeue('upload');//上传完成一个就退出一个
- });
-
- //gcm files count and add delete_all link
-
- //modify by yutao 2015-5-14 ��1��ҳ����ڶ���ϴ��ؼ�ʱ�˿�������bug �ʸ�֮ start
- var containerid = $(inputEl).data('containerid');
- if (containerid == undefined) {
- var count = $('#attachments_fields>span').length;
- $('#'+btnId).attr("disabled",true);
- $('#'+btnId).val('提交中');
- $('#'+btnId).css('background-color','#c1c1c1')
- $('#upload_file_count').html("<span id=\"count\">1</span>" + $(inputEl).data('lebelFileUploding'));//目前肯定是穿一个文件
- if (count >= 1) {
- var add_attachs = $('.add_attachment');
- var delete_all = $('.remove_all');
- if (delete_all.length < 1) {
- add_attachs.append($("<a> </a>").attr({
- "href": "javascript:void(0)",
- 'class': 'remove_all',
- "onclick": "removeAll()"
- }));
- }
- }
- } else {
- var count = $('#attachments_fields' + containerid + '>span').length;
- $('#'+btnId).attr("disabled",true);
- $('#'+btnId).val('提交中');
- $('#'+btnId).css('background-color','#c1c1c1')
- $('#upload_file_count' + containerid).html("<span id=\"count\">1</span>" + $(inputEl).data('lebelFileUploding'));//目前肯定是穿一个文件
- if (count >= 1) {
- var add_attachs = $('.add_attachment').filter(function(index) {
- return $(this).data('containerid') == containerid;
- });
- var delete_all = $('.remove_all').filter(function(index) {
- return $(this).data('containerid') == containerid;
- });
- if (delete_all.length < 1) {
- add_attachs.append($("<a> </a>").attr({
- "href": "javascript:void(0)",
- 'class': 'remove_all',
- 'data-containerid': containerid,
- "onclick": "removeAll('" + containerid + "')"
- }));
- }
- }
- //modify by yutao 2015-5-14 ��1��ҳ����ڶ���ϴ��ؼ�ʱ�˿�������bug �ʸ�֮ end
- }
-
- //gcm
-
- }
- //在插入文件名的后边插入div
- var progressSpan = $('<div>').insertAfter(fileSpan.find('input.upload_filename'));
- progressSpan.progressbar(); //将div处理成progress bar
- fileSpan.addClass('ajax-waiting'); //添加文件正在上传的状态
- var containerid = $(inputEl).data('containerid');//多个上传控件需要的容器id
- if(containerid == undefined ){ //选择了多少个文件也要显示,因为有时候文件过大,一时半会传不完,但还是显示文件没有选择
- var count = $('#attachments_fields>span').length;
- $('#upload_file_count').html("<span id=\"count\">" + count + "</span>" + '个文件被选择');
- }else{
- var count = $('#attachments_fields' + containerid + '>span').length;
- $('#upload_file_count'+containerid).html("<span id=\"count\">" + count + "</span>" + '个文件被选择');
- }
- //最大的同步上传参数
- var maxSyncUpload = 1 //$(inputEl).data('max-concurrent-uploads');
- //如果没有指定同步上传参数 或者参数不对,或者需要上传的文件已经小于同步上传的个数,那么直接上传
- if (maxSyncUpload == null || maxSyncUpload <= 0 || ajaxUpload.uploading < maxSyncUpload)
- actualUpload(file, attachmentId, fileSpan, inputEl,btnId);
- else //否则就进行队列上传
- $(inputEl).parents('form').queue('upload', actualUpload.bind(this, file, attachmentId, fileSpan, inputEl,btnId));
- }
-
- ajaxUpload.uploading = 0;
-
- function removeFile() {
- $(this).parent('span').remove();
- return false;
- }
-
- function removeReviseFile() {
- $(this).parent('span').remove();
- $("#uploadReviseBox").removeClass('disable_link');
- $("#choose_revise_attach").attr("onclick","_file.click();");
- return false;
- }
-
- //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();
- }
- }
- // return false;
- }
- //modify by yutao 2015-5-14 ��1��ҳ����ڶ���ϴ��ؼ�ʱ�˿�������bug �ʸ�֮ end
- //gcm
-
- function uploadBlob(blob, uploadUrl, attachmentId, options) {
-
- var actualOptions = $.extend({
- loadstartEventHandler: $.noop,
- progressEventHandler: $.noop
- }, options);
- if (uploadUrl.indexOf('?') > 0) {
- uploadUrl = uploadUrl + '&attachment_id=' + attachmentId;
- } else {
- uploadUrl = uploadUrl + '?attachment_id=' + attachmentId;
- }
- if (blob instanceof window.File) {
- uploadUrl += '&filename=' + encodeURIComponent(blob.name);
- }
-
- return $.ajax(uploadUrl, {
- type: 'POST',
- contentType: 'application/octet-stream',
- beforeSend: function(jqXhr) {
- jqXhr.setRequestHeader('Accept', 'application/js');
- },
- xhr: function() {
- var xhr = $.ajaxSettings.xhr();
- xhr.upload.onloadstart = actualOptions.loadstartEventHandler;
- xhr.upload.onprogress = actualOptions.progressEventHandler;
- return xhr;
- },
- data: blob,
- cache: false,
- processData: false
- });
- }
-
- function addReviseInputFiles(inputEl,btnId) {
- // var clearedFileInput = $(inputEl).clone().val('');
- if (inputEl.files) {
- uploadAndAttachReviseFiles(inputEl.files, inputEl,btnId);
- // $(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 = addReviseFile(inputEl, {
- name: aFilename[aFilename.length - 1]
- }, false);
- if (attachmentId) {
- $(inputEl).attr({
- name: 'attachments[' + attachmentId + '][file]'
- }).hide();
- if (count <= 0) count = 1;
- }
- }
-
- //clearedFileInput.insertAfter('#attachments_fields');
- }
-
- function addInputFiles(inputEl,btnId) {
- // var clearedFileInput = $(inputEl).clone().val('');
- if (inputEl.files) {
- // if(inputEl.files.length >= 5){
- // alert('一次选择的文件不能超过5个')
- // return;
- // }
- // upload files using ajax
- uploadAndAttachFiles(inputEl.files, inputEl,btnId);
- // $(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 addInputFiles_board(inputEl, id,btnId) {
- // var clearedFileInput = $(inputEl).clone().val('');
-
- if (inputEl.files) {
- // if(inputEl.files.length >= 5){
- // alert('一次选择的文件不能超过5个')
- // return;
- // }
- // upload files using ajax
- uploadAndAttachFiles_board(inputEl.files, inputEl, id,btnId);
- // $(inputEl).remove();
- } else {
- // browser not supporting the file API, upload on form submission
- var attachmentId;
- var aFilename = inputEl.value.split(/\/|\\/);
- attachmentId = addFile_board(inputEl, {
- name: aFilename[aFilename.length - 1]
- }, false, id);
- if (attachmentId) {
- $(inputEl).attr({
- name: 'attachments[' + attachmentId + '][file]'
- }).hide();
- $('#upload_file_count').html("<span id=\"count\">" + count + "</span>" + $(inputEl).data('fileCount'));
- }
- }
-
- //clearedFileInput.insertAfter('#attachments_fields');
- }
-
- function uploadAndAttachReviseFiles(files, inputEl,btnId) {
-
- 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() {
- addReviseFile(inputEl, this, true,btnId);
- });
- }
- }
-
- function uploadAndAttachFiles(files, inputEl,btnId) {
-
- 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() {
- addFile(inputEl, this, true,btnId);
- });
- }
- }
-
- function uploadAndAttachFiles_board(files, inputEl, id,btnId) {
-
- 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() {
- addFile_board(inputEl, this, true, id,btnId);
- });
- }
- }
-
- function handleFileDropEvent(e) {
-
- $(this).removeClass('fileover');
- blockEventPropagation(e);
-
- if ($.inArray('Files', e.dataTransfer.types) > -1) {
- uploadAndAttachFiles(e.dataTransfer.files, $('input:file.file_selector'));
- }
- }
-
- function dragOverHandler(e) {
- $(this).addClass('fileover');
- blockEventPropagation(e);
- }
-
- function dragOutHandler(e) {
- $(this).removeClass('fileover');
- blockEventPropagation(e);
- }
-
- function setupFileDrop() {
- if (window.File && window.FileList && window.ProgressEvent && window.FormData) {
-
- $.event.fixHooks.drop = {
- props: ['dataTransfer']
- };
-
- $('form div.box').has('input:file').each(function() {
- $(this).on({
- dragover: dragOverHandler,
- dragleave: dragOutHandler,
- drop: handleFileDropEvent
- });
- });
- }
- }
-
- $(document).ready(setupFileDrop);
- $(function() {
- $(".file_selector").each(function() {
- deleteallfiles = $(this).data('deleteAllFiles');
- var containerid = $(this).data('containerid');
- if (containerid == undefined) containerid = '';
- var count = $('#attachments_fields' + containerid + '>span').length;
- if (count >= 1) {
- $('#upload_file_count' + containerid).html("<span id=\"count\">" + count + "</span>" + $(this).data('fileCount'));
- var add_attachs = $('.add_attachment').filter(function(index) {
- return $(this).data('containerid') == containerid;
- });
- var delete_all = $('.remove_all').filter(function(index) {
- return $(this).data('containerid') == containerid;
- });
- if (delete_all.length < 1) {
- add_attachs.append($("<a> </a>").attr({
- "href": "javascript:void(0)",
- 'class': 'remove_all',
- 'data-containerid': containerid,
- "onclick": "removeAll('" + containerid + "')"
- }));
- }
-
- }
- });
- });
-
- //课程课件
- function addInputFilesCourseSource(inputEl) {
- checkBox = arguments[1] == 'public' ? false : true;
- btnId = arguments[2];
- // var clearedFileInput = $(inputEl).clone().val('');
- if (inputEl.files) {
- // if(inputEl.files.length >= 5){
- // alert('一次选择的文件不能超过5个')
- // return;
- // }
- // upload files using ajax
- uploadAndAttachFilesCourseSource(inputEl.files, inputEl,checkBox,btnId);
- // $(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,btnId) {
-
- 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,btnId);
- });
- }
- }
-
- function addFileCourseSource(inputEl, file, eagerUpload,checkBox,btnId) {
-
- 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': 'upload_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': 'upload_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,btnId);
-
- }
- return attachmentId;
- }
- return null;
- }
- addFileCourseSource.nextAttachmentId = 1;
|