diff --git a/app/views/attachments/upload.js.erb b/app/views/attachments/upload.js.erb
index 970c5b22d..2420b2a6e 100644
--- a/app/views/attachments/upload.js.erb
+++ b/app/views/attachments/upload.js.erb
@@ -11,4 +11,5 @@ fileSpan.find('a.remove-upload')
})
.off('click');
$('', { type: 'hidden', name: 'attachments[<%= j params[:attachment_id] %>][token]' } ).val('<%= j @attachment.token %>').appendTo(fileSpan);
+console.log(fileSpan.html())
<% end %>
diff --git a/app/views/files/_attachement_list.html.erb b/app/views/files/_attachement_list.html.erb
index 50d14b7ee..c2c8d2d10 100644
--- a/app/views/files/_attachement_list.html.erb
+++ b/app/views/files/_attachement_list.html.erb
@@ -21,13 +21,13 @@
<% end %>
-
+<% checkBox = (@course.present? && @course.is_public?) ? 'public' : 'private'%>
<%= file_field_tag 'attachments[dummy][file]',
:id => '_file',
:class => ie8? ? '':'file_selector',
:multiple => true,
- :onchange => 'addInputFiles(this);',
+ :onchange => 'addInputFiles(this,"'+ checkBox.to_s+'");',
:style => ie8? ? '': 'display:none',
:data => {
:max_file_size => Setting.attachment_max_size.to_i.kilobytes,
diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js
index 9c32e41dc..12384f451 100644
--- a/public/javascripts/attachments.js
+++ b/public/javascripts/attachments.js
@@ -88,7 +88,7 @@ function addFile_board(inputEl, file, eagerUpload, id) {
return null;
}
-function addFile(inputEl, file, eagerUpload) {
+function addFile(inputEl, file, eagerUpload,checkBox) {
var attachments_frame = '#attachments_fields';
if ($(attachments_frame).children().length < 30) {
@@ -99,50 +99,72 @@ function addFile(inputEl, file, eagerUpload) {
'id': 'attachments_' + attachmentId,
'class': 'attachment'
});
-
- 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);
+ //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');
+ }).toggle(!eagerUpload),
+ $('
', {
+ 'class': 'div_attachments',
+ 'name': 'div_' + 'attachments_' + attachmentId
+ })
+ ).appendTo('#attachments_fields');
+ }
if (eagerUpload) {
ajaxUpload(file, attachmentId, fileSpan, inputEl);
@@ -198,7 +220,7 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) {
//gcm files count and add delete_all link
- //modify by yutao 2015-5-14 当1个页面存在多个上传控件时此块代码存在bug 故改之 start
+ //modify by yutao 2015-5-14 锟斤拷1锟斤拷页锟斤拷锟斤拷诙锟斤拷锟较达拷锟截硷拷时锟剿匡拷锟斤拷锟斤拷锟斤拷bug 锟绞革拷之 start
var containerid = $(inputEl).data('containerid');
if (containerid == undefined) {
var count = $('#attachments_fields>span').length;
@@ -233,7 +255,7 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) {
}));
}
}
- //modify by yutao 2015-5-14 当1个页面存在多个上传控件时此块代码存在bug 故改之 end
+ //modify by yutao 2015-5-14 锟斤拷1锟斤拷页锟斤拷锟斤拷诙锟斤拷锟较达拷锟截硷拷时锟剿匡拷锟斤拷锟斤拷锟斤拷bug 锟绞革拷之 end
}
//gcm
@@ -260,7 +282,7 @@ function removeFile() {
}
//gcm delete all file
-//modify by yutao 2015-5-14 当1个页面存在多个上传控件时此块代码存在bug 故改之 start
+//modify by yutao 2015-5-14 锟斤拷1锟斤拷页锟斤拷锟斤拷诙锟斤拷锟较达拷锟截硷拷时锟剿匡拷锟斤拷锟斤拷锟斤拷bug 锟绞革拷之 start
function removeAll(containerid) {
if (confirm(deleteallfiles)) {
if (containerid == undefined) {
@@ -276,7 +298,7 @@ function removeAll(containerid) {
}
// return false;
}
- //modify by yutao 2015-5-14 当1个页面存在多个上传控件时此块代码存在bug 故改之 end
+ //modify by yutao 2015-5-14 锟斤拷1锟斤拷页锟斤拷锟斤拷诙锟斤拷锟较达拷锟截硷拷时锟剿匡拷锟斤拷锟斤拷锟斤拷bug 锟绞革拷之 end
//gcm
function uploadBlob(blob, uploadUrl, attachmentId, options) {
@@ -313,10 +335,11 @@ 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);
+ uploadAndAttachFiles(inputEl.files, inputEl,checkBox);
// $(inputEl).remove();
} else {
// browser not supporting the file API, upload on form submission
@@ -363,7 +386,7 @@ function addInputFiles_board(inputEl, id) {
//clearedFileInput.insertAfter('#attachments_fields');
}
-function uploadAndAttachFiles(files, inputEl) {
+function uploadAndAttachFiles(files, inputEl,checkBox) {
var maxFileSize = $(inputEl).data('max-file-size');
var maxFileSizeExceeded = $(inputEl).data('max-file-size-message');
@@ -378,7 +401,7 @@ function uploadAndAttachFiles(files, inputEl) {
window.alert(maxFileSizeExceeded);
} else {
$.each(files, function() {
- addFile(inputEl, this, true);
+ addFile(inputEl, this, true,checkBox);
});
}
}