orbit4-5/app/views/admin/groups/newpost.html.erb

138 lines
3.8 KiB
Plaintext

<%= form_for @grouppost, :url => admin_group_createpost_path(@group), :html => { :multipart => true , :class=>"form-horizontal main-forms"} do |f| %>
<fieldset>
<%= render :partial => "post_form", locals: {f: f} %>
</fieldset>
<% end %>
<script type="text/javascript">
Dropzone.autoDiscover = false;
var image_id_panel = $("#image_ids");
var file_id_panel = $("#file_ids");
var groupImageDropzone = new Dropzone("div#group-post-images", {
url : "/admin/posts/image",
previewsContainer : "#group-post-images-container",
paramName : "group_post_image[image]",
clickable : true,
autoProcessQueue : false,
addRemoveLinks : true,
uploadMultiple : false,
accept: function(file, done) {
var regex = new RegExp(/(\.|\/)(gif|jpe?g|png)$/i)
if(regex.test(file.name)){
done();
}else{
this.removeFile(file);
}
}
})
$(".upload_image_btn").on("click",function(){
$("#group-post-images a.dz-remove").remove();
doImagesUpload();
return false;
})
$(".remove_image_btn").on("click",function(){
groupImageDropzone.removeAllFiles();
return false;
})
groupImageDropzone.on("success",function(file,data){
image_id_panel.append("<input type='hidden' name='group_post[group_post_images][]' value='" + data.id + "' />");
})
groupImageDropzone.on("sending",function(file,xhr,obj){
obj.append("authenticity_token",$("form#new_group_post input[name=authenticity_token]").val());
})
var doImagesUpload = function(){
groupImageDropzone.processQueue();
groupImageDropzone.on("complete", function(file) {
var filesCount = groupImageDropzone.getQueuedFiles().length;
if(filesCount > 0){
doImagesUpload();
}else{
if(groupFilesDropzone.getQueuedFiles().length > 0){
doFilesUpload();
}else{
submitForm();
}
}
});
}
var groupFilesDropzone = new Dropzone("div#group-post-files", {
url : "/admin/posts/file",
previewsContainer : "#group-post-files-container",
paramName : "group_post_file[file]",
clickable : true,
autoProcessQueue : false,
addRemoveLinks : true,
uploadMultiple : false,
accept: function(file, done) {
var regex = new RegExp(/(\.|\/)(pdf|doc?x|xls?x|rtf|txt|ppt?x|mp3|mov|avi|gif|jpe?g|png|zip|rar)$/i)
if(regex.test(file.name)){
done();
}else{
this.removeFile(file);
}
}
})
$(".upload_file_btn").on("click",function(){
$("#group-post-files a.dz-remove").remove();
doFilesUpload();
return false;
})
$(".remove_file_btn").on("click",function(){
groupFilesDropzone.removeAllFiles();
return false;
})
groupFilesDropzone.on("success",function(file,data){
file_id_panel.append("<input type='hidden' name='group_post[group_post_files][]' value='" + data.id + "' />");
})
groupFilesDropzone.on("sending",function(file,xhr,obj){
obj.append("authenticity_token",$("form#new_group_post input[name=authenticity_token]").val());
})
var doFilesUpload = function(){
groupFilesDropzone.processQueue();
groupFilesDropzone.on("complete", function(file) {
var filesCount = groupFilesDropzone.getQueuedFiles().length;
if(filesCount > 0){
doFilesUpload();
}else{
submitForm();
}
});
}
$("#create-post-form-btn").on("click",function(){
if(groupImageDropzone.getQueuedFiles().length > 0){
doImagesUpload();
}else if(groupFilesDropzone.getQueuedFiles().length > 0){
doFilesUpload();
}else{
submitForm();
}
// uploading all the files
$(".upload-status-notice")
.removeClass("hide")
.addClass("animated slideInRight");
return false;
})
var submitForm = function(){
if(groupImageDropzone.getQueuedFiles().length > 0 || groupFilesDropzone.getQueuedFiles().length > 0){
return false;
}else{
$(".upload-status-notice span.upload-text").text("Submitting");
$("form#new_group_post").submit();
return true;
}
}
</script>