forked from saurabh/orbit4-5
64 lines
1.8 KiB
Plaintext
64 lines
1.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 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(){
|
|
$(".dropzone a.dz-remove").remove();
|
|
doUpload();
|
|
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 doUpload = function(){
|
|
groupImageDropzone.processQueue();
|
|
groupImageDropzone.on("complete", function(file) {
|
|
var filesCount = groupImageDropzone.getQueuedFiles().length;
|
|
if(filesCount > 0){
|
|
doUpload();
|
|
}
|
|
});
|
|
}
|
|
|
|
$("form#new_group_post").submit(function(){
|
|
if(groupImageDropzone.getQueuedFiles().length > 0){
|
|
alert("Please upload all the files or remove them before submitting a post.");
|
|
return false;
|
|
}else{
|
|
return true;
|
|
}
|
|
})
|
|
|
|
</script> |