You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
921 lines
49 KiB
921 lines
49 KiB
/*
|
|
For event attachments for pictures and .mp3 audio and video
|
|
*/
|
|
var event_file_attachment_dropdown = $("#event-file-attachment");
|
|
var event_attachment = (function ($, window, jQuery) {
|
|
return {
|
|
"getForm" : function(){
|
|
var form = $("form#eventForm");
|
|
return { obj : form, data : form.data("event_attachment")};
|
|
},
|
|
"model" : {
|
|
|
|
"indexs" : function(){
|
|
return {
|
|
"display": "",
|
|
"attachment_id" : null,
|
|
"attachment_type" :"",
|
|
"file_preview" : null,
|
|
"description" : "",
|
|
"file_setup" : {
|
|
"setup_id" : null,
|
|
"mime_type" : "",
|
|
"file_name" : ""
|
|
// ,"autoplay_vaudio" : 0, //autoplay audio or video in HP
|
|
// "preview_default_image" : 1 //use default image in HP or use custom image
|
|
}
|
|
};
|
|
},
|
|
|
|
"init" : function(){
|
|
var eventForm = event_attachment.getForm();
|
|
(eventForm.obj).data("event_attachment", {
|
|
"grid" : [],
|
|
"uploadedFiles" : []
|
|
});
|
|
//initialize grid
|
|
event_attachment.grid.init("addEvent");
|
|
},
|
|
|
|
"action" : {
|
|
"client" : { //means local storage
|
|
"reset" : function() {
|
|
(event_attachment.getForm().obj).removeData("event_attachment");
|
|
events.set_vars({"event_file_attachment_list": []});
|
|
},
|
|
|
|
"generate_tmp_id" : function(){
|
|
var eventForm = event_attachment.getForm(),
|
|
len = (eventForm.data.grid).length,
|
|
min = ((len-2) <=0)?0:(len-2),
|
|
max = len+1;
|
|
return Math.random() * (max - min) + min;
|
|
},
|
|
|
|
fill_up_indexs : function(action, uploadedFiles, indexs, display){
|
|
//create temporary id for edit and delete purposes, happens when sorting is activated
|
|
if(action == "client"){
|
|
indexs["display"] = display
|
|
indexs["attachment_id"] = event_attachment.model.action.client.generate_tmp_id();
|
|
indexs["file_preview"] = uploadedFiles;
|
|
indexs["description"] = 'File name : '+uploadedFiles.name+' <br/>File size : '
|
|
+(uploadedFiles.size / (1024*1024)).toFixed(2)+'MB';
|
|
} else {
|
|
delete indexs["attachment_id"];
|
|
delete indexs["display"];
|
|
delete indexs["description"];
|
|
}
|
|
indexs["attachment_type"] = uploadedFiles.atype;
|
|
var opt = {
|
|
"mime_type" : uploadedFiles.type,
|
|
"file_name" : uploadedFiles.name
|
|
};
|
|
|
|
if(uploadedFiles.type.indexOf("audio") != -1){
|
|
opt["autoplay_vaudio"] = 0; //disable autoplay
|
|
opt["preview_default_image"] = 1;
|
|
} else if(uploadedFiles.type.indexOf("video") != -1){
|
|
opt["autoplay_vaudio"] = 0; //disable autoplay
|
|
}
|
|
indexs["file_setup"] = opt;
|
|
return indexs;
|
|
},
|
|
|
|
"add" : function(uploadedFiles) {
|
|
var eventForm = event_attachment.getForm();
|
|
//get all data
|
|
$.map(uploadedFiles, function(value, key){
|
|
var indexs = event_attachment.model.indexs();
|
|
let display = 'home'
|
|
if(eventForm.data.grid.length > 0) {
|
|
if(eventForm.data.grid[0].display == 'home')
|
|
display = 'details'
|
|
}
|
|
//push new data from temp. datastore
|
|
indexs = event_attachment.model.action.client.fill_up_indexs("client", uploadedFiles[key], indexs, display);
|
|
//now, update datastore
|
|
(eventForm.data.grid).push(indexs);
|
|
(eventForm.data.uploadedFiles).push(uploadedFiles[key]);
|
|
(eventForm.obj).data("event_attachment", eventForm.data);
|
|
//automatically add new entry to datatable.
|
|
//we do not reload the entire datable when adding or editing, just the row being edited
|
|
(events.get_vars().event_file_attachment_list)[0].row.add(indexs).draw();
|
|
});
|
|
},
|
|
|
|
"delete" : function(td, row){
|
|
var eventForm = event_attachment.getForm();
|
|
var tobe_deleted_row = (events.get_vars().event_file_attachment_list)[0].row(row).data();
|
|
// delete a row or an element from the datastore
|
|
$.map(eventForm.data.grid, function(value, key){
|
|
if(typeof value!= "undefined"){
|
|
// console.log(value);
|
|
if(tobe_deleted_row.attachment_id == value.attachment_id){
|
|
eventForm.data.grid.splice(key, 1);
|
|
eventForm.data.uploadedFiles.splice(key, 1);
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
//now, update datastore
|
|
(eventForm.obj).data("event_attachment", eventForm.data);
|
|
//then, reload grid
|
|
event_attachment.grid.reload("addEvent");
|
|
},
|
|
|
|
"update" : function(uploadedFiles, row){
|
|
var eventForm = event_attachment.getForm();
|
|
var edited_row = (events.get_vars().event_file_attachment_list)[0].row(row).data();
|
|
var indexs = event_attachment.model.indexs();
|
|
//update specific event speaker from the datastore
|
|
$.map(eventForm.data.grid, function(value, key){
|
|
if(typeof value!= "undefined"){
|
|
if(edited_row.attachment_id == value.attachment_id){
|
|
indexs = event_attachment.model.action.client.fill_up_indexs("client", uploadedFiles[0], indexs);
|
|
eventForm.data.grid[key] = indexs;
|
|
eventForm.data.uploadedFiles[key] = uploadedFiles[0];
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
//now, update datastore
|
|
(eventForm.obj).data("event_attachment", eventForm.data);
|
|
//then, reload grid
|
|
event_attachment.grid.reload("addEvent");
|
|
},
|
|
|
|
/*clean up event data before saving*/
|
|
"clean_event_attachment_data" : function(formData){
|
|
var eventForm = event_attachment.getForm();
|
|
//clean datastore before submitting to server
|
|
if(eventForm.data.grid.length > 0){
|
|
$.map(eventForm.data.grid, function(value, key){
|
|
if(typeof value!= "undefined"){
|
|
//delete eventForm.data.grid[key]["display"];
|
|
delete eventForm.data.grid[key]["attachment_id"];
|
|
delete eventForm.data.grid[key]["file_preview"];
|
|
delete eventForm.data.grid[key]["description"];
|
|
formData.append("event_attachment[]", JSON.stringify(eventForm.data.grid[key]));
|
|
formData.append("event_attachment_files[]", eventForm.data.uploadedFiles[key]);
|
|
}
|
|
});
|
|
} else {
|
|
formData.append("event_attachment", []);
|
|
formData.append("event_attachment_files", []);
|
|
}
|
|
|
|
return formData;
|
|
}
|
|
},
|
|
|
|
"server" : {
|
|
|
|
"add" : function(uploadedFiles){
|
|
var url_param = events.get_vars().event_id;
|
|
var indexs = event_attachment.model.indexs();
|
|
var form_data ={"grid" : [], "uploadedFiles": []};
|
|
var http_data = new FormData();
|
|
//push new data to server
|
|
$.map(uploadedFiles, function(value, key){
|
|
if(typeof value!= "undefined"){
|
|
var fields = indexs;
|
|
fields = event_attachment.model.action.client.fill_up_indexs("server", uploadedFiles[key], fields);
|
|
delete fields["display"];
|
|
delete fields["file_preview"];
|
|
delete fields["attachment_id"];
|
|
delete fields["description"];
|
|
http_data.append("info[]", JSON.stringify(fields));
|
|
http_data.append("uploadedFiles[]", uploadedFiles[key]);
|
|
}
|
|
});
|
|
|
|
var http_result = events.server.request("add", "add_event_attachment", http_data, url_param);
|
|
http_result.success(function(result){
|
|
if(app.isalive(result)) {
|
|
events.server.reset("add", result);
|
|
//then, reload grid
|
|
event_attachment.grid.reload("editEvent");
|
|
}
|
|
}).error(function(xhr){
|
|
console.log(xhr);
|
|
});
|
|
},
|
|
|
|
"update" : function(uploadedFiles, row){
|
|
var edited_row = (events.get_vars().event_file_attachment_list)[0].row(row).data();
|
|
var http_data = new FormData();
|
|
var indexs = event_attachment.model.indexs();
|
|
indexs = event_attachment.model.action.client.fill_up_indexs("server", uploadedFiles[0], indexs);
|
|
//get the original file for unlinking process on server side
|
|
indexs["file_preview"] = edited_row.file_preview;
|
|
http_data.append("info", JSON.stringify(indexs));
|
|
http_data.append("uploadedFiles", uploadedFiles[0]);
|
|
var url_param = events.get_vars().event_id+"_"+edited_row.attachment_id+"_"+edited_row.status;//edited_row.attachment_id;
|
|
|
|
var http_result = events.server.request("edit", "update_event_attachment", http_data, url_param);
|
|
http_result.success(function(result){
|
|
if(app.isalive(result)) {
|
|
events.server.reset("edit", result);
|
|
//then, reload grid
|
|
event_attachment.grid.reload("editEvent");
|
|
}
|
|
}).error(function(xhr){
|
|
console.log(xhr);
|
|
});
|
|
},
|
|
|
|
"delete" : function(row){
|
|
var edited_row = (events.get_vars().event_file_attachment_list)[0].row(row).data();
|
|
var mime_type = edited_row.mime.replace("/", ".");
|
|
var url_param = events.get_vars().event_id+"_"+edited_row.attachment_type+"_"+edited_row.attachment_id+"_"+mime_type;//edited_row.attachment_id;
|
|
var http_data = new FormData();
|
|
http_data.append("file_name", edited_row.file_preview);
|
|
|
|
var http_result = events.server.request("delete", "delete_event_attachment", http_data, url_param);
|
|
http_result.success(function(result){
|
|
if(app.isalive(result)) {
|
|
events.server.reset("delete", result);
|
|
//then, reload grid
|
|
event_attachment.grid.reload("editEvent");
|
|
}
|
|
}).error(function(xhr){
|
|
console.log(xhr);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
"grid" : {
|
|
|
|
init : function(action){
|
|
try{
|
|
//check datatable is initialzed
|
|
var table;
|
|
if (action == "addEvent") {
|
|
table = $("#event_file_attachment_list").DataTable($.extend(event_attachment.grid.opt(action), event_attachment.grid.extra(action))).clear();
|
|
} else{
|
|
var result = localStorage.getItem("event_attachment");
|
|
if(result != null){
|
|
table = $("#event_file_attachment_list").DataTable().ajax.url(app.get_vars().baseurl + "list_event_attachment/" + ((events.get_vars().event_id !=null && typeof events.get_vars().event_id != "undefined" )?events.get_vars().event_id:0)).load();
|
|
}else{
|
|
localStorage.setItem("event_attachment", "initialzed");
|
|
table = $("#event_file_attachment_list").DataTable($.extend(event_attachment.grid.opt(action), event_attachment.grid.extra(action)));
|
|
}
|
|
}
|
|
event_attachment.grid.init_vars(table, action);
|
|
}catch(e){
|
|
console.log(e);
|
|
}
|
|
},
|
|
"init_vars" : function(table, action){
|
|
//set table instance in the global variable along with the action [addEvent/editEvent]
|
|
events.set_vars({"event_file_attachment_list": [(typeof table!="undefined")?table:null, action]});
|
|
},
|
|
reload : function(action){
|
|
var table = $("#event_file_attachment_list").DataTable();
|
|
|
|
if(action == "addEvent"){
|
|
var eventForm = event_attachment.getForm();
|
|
if((eventForm.data.grid).length != 0) {
|
|
table.clear().draw();
|
|
$.map(eventForm.data.grid, function (value) {
|
|
table.row.add(value).columns.adjust().draw();
|
|
});
|
|
} else {
|
|
table.clear().columns.adjust().draw();
|
|
}
|
|
} else {
|
|
table.ajax.reload(null, false);
|
|
}
|
|
//displayHack : recalculate the dimensions of event_file_attachment_list table/grid
|
|
// events.get_vars().event_file_attachment_list[0].columns.adjust().draw();
|
|
},
|
|
|
|
"opt" : function(action){
|
|
return {
|
|
"autoWidth": false,
|
|
"sDom": '<"toolbar">',
|
|
"destroy": true,
|
|
"responsive": true,
|
|
"searching": false,
|
|
"processing": true, //Feature control the processing indicator
|
|
"order" : [1, "asc"],
|
|
"oLanguage": fr_onload_lang.oLanguage,
|
|
"columns": [
|
|
{"data": "attachment_id", defaultContent: null, "orderable": false, "visible" : false,
|
|
"render" : function(data, type, full, meta){
|
|
return data;
|
|
}
|
|
},
|
|
{"data": "display", defaultContent: "", "orderable": false,
|
|
"render" : function(data, type, full, meta){
|
|
return data;
|
|
}
|
|
},
|
|
{"data": "attachment_type", defaultContent: "", "orderable": false,
|
|
"render" : function(data, type, full, meta){
|
|
if(data == 1) return "Joindre photo Event";
|
|
else return "Joindre photo Event detail";
|
|
}
|
|
},
|
|
{"data" : "file_preview", "defaultContent": null, "orderable" : false,
|
|
"render" : event_attachment.upload.render
|
|
},
|
|
{data: 'description', "orderable": false,
|
|
"render": event_attachment.modal.show_file_setup
|
|
},
|
|
{"data": "file_setup", defaultContent: null, "orderable": false,
|
|
"render": event_attachment.grid.action
|
|
}
|
|
],
|
|
"columnDefs": [
|
|
{ "targets" : [1], "width" : "25%"},
|
|
{"targets": [2], "width": "18%"},
|
|
{"targets": [3], "width": "40%"},
|
|
{"targets": [4], "width": "10%"}
|
|
],
|
|
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
|
|
// if(typeof aData.file_preview == "object"){
|
|
// $(nRow).addClass("row_selected");
|
|
// }
|
|
},
|
|
"drawCallback": function( settings ) {
|
|
var attachment_type = 1//parseInt(event_file_attachment_dropdown.val());
|
|
if(attachment_type ==1){
|
|
event_attachment.upload.validate.disable_browse_file(attachment_type);
|
|
} else {
|
|
event_attachment.upload.validate.disable_browse_file(attachment_type);
|
|
}
|
|
},
|
|
initComplete: function(){
|
|
//set table instance in the global variable along with the action [addEvent/editEvent]
|
|
event_attachment.grid.init_vars($("#event_file_attachment_list").DataTable(), action);
|
|
|
|
$("#event_file_attachment_list_wrapper div.toolbar")
|
|
.html('<label id="browse_file_attachment" class="btn btn-block btn-primary btn-sm" style="width: 160px;">'+
|
|
'Parcourir les fichiers… <input accept="image/*" onchange="event_attachment.upload.init(\'eventfiles\', \'add\', -1);" id="eventfiles" type="file" name="eventfiles[]" class="ignore filechooser" style="display: none;">'+
|
|
'</label>');
|
|
//disable upload button on init
|
|
event_attachment.upload.validate.disable_browse_file(1);
|
|
}
|
|
};
|
|
},
|
|
|
|
"extra" : function(action){
|
|
if(action == "editEvent"){
|
|
return {
|
|
"serverSide": true, //Feature control DataTables' server-side processing mode.
|
|
"ajax": { // Load data for the table's content from an Ajax source
|
|
"url": app.get_vars().baseurl + "list_event_attachment/" + events.get_vars().event_id,
|
|
"type": "post"
|
|
}
|
|
};
|
|
} else {
|
|
return {data : event_attachment.getForm().data};
|
|
}
|
|
},
|
|
|
|
"action" : function(data, type, full, meta){
|
|
var table = (events.get_vars().event_file_attachment_list),
|
|
actions = {}, action_btns = "";
|
|
|
|
switch(table[1]){
|
|
case "addEvent" :
|
|
actions.edit = "event_attachment.upload.replace_file(event, \'edit\', "+meta.row+")";
|
|
actions.delete = "event_attachment.model.action.client.delete(this, "+meta.row+")";
|
|
break;
|
|
case "editEvent" :
|
|
actions.edit = "event_attachment.upload.replace_file(event, \'edit\', "+meta.row+")";
|
|
actions.delete = "event_attachment.modal.delete_confirm(\'server\', "+meta.row+")";
|
|
break;
|
|
default : ""
|
|
break;
|
|
};
|
|
/*
|
|
lets identify the mime_type and set the exact accepted files for the input file.
|
|
This will lessen the validation
|
|
*/
|
|
if (full.attachment_type == 1) {
|
|
var mime_type = "image/*";
|
|
} else {
|
|
console.log(data);
|
|
console.log(full.file_setup.mime_type);
|
|
if (full.mime) {
|
|
if ((full.mime).indexOf('image') >=0) {
|
|
var mime_type = "image/*";
|
|
} else if ((full.mime).indexOf('audio') >=0) {
|
|
var mime_type = "audio/*";
|
|
} else if ((full.mime).indexOf('video') >=0) {
|
|
var mime_type = "video/*";
|
|
}
|
|
} else {
|
|
if ((full.file_setup.mime_type).indexOf('image') >=0) {
|
|
var mime_type = "image/*";
|
|
} else if ((full.file_setup.mime_type).indexOf('audio') >=0) {
|
|
var mime_type = "audio/*";
|
|
} else if ((full.file_setup.mime_type).indexOf('video') >=0) {
|
|
var mime_type = "video/*";
|
|
}
|
|
}
|
|
}
|
|
action_btns+='<p class="custom-popover-tooltip col-sm-1 col-xs-1" data-placement="top" data-toggle="tooltip" data-title="Modifier" title="Modifier">'
|
|
+'<input accept="'+mime_type+'" data-attachment_type="'+full.attachment_type+'" data-row="'+meta.row+'" onchange="event_attachment.upload.init(\'editfiles_'+meta.row+'\', \'edit\', '+meta.row+');" value="" id="editfiles_'+meta.row+'" type="file" name="editfiles_'+meta.row+'" class="ignore filechooser" style="display: none;">'
|
|
+'<span onclick="'+actions.edit+'" class="btn btn-success btn-xs">'
|
|
+'<span class="glyphicon glyphicon-pencil"></span></span></p>';
|
|
|
|
// action_btns += (full.attachment_type == 1 && table[1] == "editEvent") ? "" : app.grid.create_action_btn(app.get_vars()._app.action._delete, "trash", "danger", actions.delete);
|
|
action_btns += app.grid.create_action_btn(app.get_vars()._app.action._delete, "trash", "danger", actions.delete);
|
|
return action_btns;
|
|
}
|
|
},
|
|
|
|
"modal" : {
|
|
|
|
"show_file_setup" : function(data, type, full, meta){
|
|
// if(((full.file_setup.mime_type).match(/video/g)||[]).length > 0 || ((full.file_setup.mime_type).match(/audio/g)||[]).length > 0){
|
|
// return full.description+'<br/><br/><label><input type="checkbox" name="autoplay_vaudio_'+meta.row+'" value="1"/> Autoplay on HP </label>';
|
|
// }
|
|
return full.description;
|
|
},
|
|
|
|
"delete_confirm" : function(action, row){
|
|
app.modal.confirm_box({
|
|
"message" : app.get_vars().events.cma_msg.delete_event_image+" <b>[#"+(row+1)+"]</b> ?<br/><br><span class='label label-danger' style='font-size: 12px;'>"+app.get_vars()._app.cma_msg.note+"</span>",
|
|
"_continue" : function() {
|
|
(action=="server")
|
|
? event_attachment.model.action.server.delete(row)
|
|
: event_attachment.model.action.client.delete(row)
|
|
}
|
|
});
|
|
},
|
|
|
|
"action" : function(action, uploadedFiles, row){
|
|
/* this condition tells if the action to be made falls under :
|
|
- adding new event and adding new data in it
|
|
- or editing event data
|
|
*/
|
|
var table = events.get_vars().event_file_attachment_list;
|
|
var action_ = (action=="edit")?table[1]+"_edit":table[1]+"_add";
|
|
|
|
switch(action_){
|
|
/*
|
|
This is when user is adding new event.
|
|
Event data are stored in temporary repository
|
|
*/
|
|
case "addEvent_edit" : event_attachment.model.action.client.update(uploadedFiles, row);
|
|
break;
|
|
|
|
case "addEvent_add" : event_attachment.model.action.client.add(uploadedFiles);
|
|
break;
|
|
/*
|
|
This is when user is editing an event.
|
|
Event data are stored directly on the server
|
|
*/
|
|
case "editEvent_edit" : event_attachment.model.action.server.update(uploadedFiles, row);
|
|
break;
|
|
|
|
case "editEvent_add" : event_attachment.model.action.server.add(uploadedFiles);
|
|
break;
|
|
|
|
default : return false;
|
|
break;
|
|
}; //end of main switch
|
|
}
|
|
},
|
|
|
|
"upload" : {
|
|
|
|
"init" : function(filechooser, action, row){
|
|
|
|
var eventfiles = document.getElementById(filechooser),
|
|
countFiles = (eventfiles.files).length,
|
|
i=0, eventForm = event_attachment.getForm(),
|
|
uploadedFiles = [],
|
|
filechooser = $('#'+filechooser),
|
|
attachment_type = 1//(action=="add")?parseInt(event_file_attachment_dropdown.val()):parseInt(filechooser.data("attachment_type"));
|
|
|
|
//if files do not exceed the allowed number of files per attachment type
|
|
if(!event_attachment.upload.validate.total_uploadFiles_exceeded(eventfiles.files, countFiles, attachment_type)) {
|
|
for (i = 0; i<countFiles; i++) {
|
|
var file=eventfiles.files[i];
|
|
event_attachment.upload.validate.isValidSize(file);
|
|
ufile_type = file.name.split('.').pop();
|
|
switch (ufile_type) {
|
|
case 'png':
|
|
case 'jpg':
|
|
case 'jpeg':
|
|
case 'gif':
|
|
case 'mp4':
|
|
case 'mp3':
|
|
break;
|
|
default:
|
|
app._notify("warning", "The file you are uploading is not allowed");
|
|
return false;
|
|
} //if file is valid
|
|
if(event_attachment.upload.validate.file_type(file, attachment_type)) {
|
|
//if file is not restricted
|
|
if(!event_attachment.upload.validate.restricted(attachment_type, file.type, file.name, uploadedFiles, row)){
|
|
file["atype"] = attachment_type;
|
|
uploadedFiles.push(file);
|
|
} else {
|
|
uploadedFiles=[];
|
|
return false;
|
|
}
|
|
} else {
|
|
uploadedFiles=[];
|
|
return false;
|
|
}
|
|
}
|
|
//when files passed all those validations above, lets continue listing the files on datatable
|
|
if(uploadedFiles.length > 0) {
|
|
event_attachment.modal.action(action, uploadedFiles, row);
|
|
}
|
|
}
|
|
uploadedFiles=[];
|
|
filechooser.val("");
|
|
$(".filechooser").val("");
|
|
return false;
|
|
},
|
|
|
|
audio_mode : {
|
|
"on_play" : function(SoundCtrl) {
|
|
SoundCtrl.play();
|
|
},
|
|
"on_stop" : function(SoundCtrl) {
|
|
SoundCtrl.pause();
|
|
},
|
|
"on_load_play" : function(_this, sCtrl) {
|
|
var SoundCtrl = $("#"+sCtrl)[0];
|
|
if (SoundCtrl.duration > 0 && !SoundCtrl.paused) {
|
|
$(_this).text(" fait une pause ");
|
|
event_attachment.upload.audio_mode.on_stop(SoundCtrl);
|
|
} else {
|
|
$(_this).text(" en jouant ");
|
|
event_attachment.upload.audio_mode.on_play(SoundCtrl);
|
|
}
|
|
}
|
|
},
|
|
|
|
"replace_file" : function(e, action, row) {
|
|
$("#editfiles_"+row).focus().trigger('click');
|
|
},
|
|
|
|
"render" : function(data, type, full, meta) {
|
|
var file = (typeof data == "object")?URL.createObjectURL(data):app.get_vars().events.attachment.events+full.file_preview;
|
|
var afile_type;
|
|
// console.log(typeof(full.file_preview));
|
|
if (typeof(full.file_preview) == 'string') {
|
|
afile_type = full.file_preview.split('.').pop();
|
|
} else {
|
|
afile_type = full.file_preview.name.split('.').pop();
|
|
}
|
|
if( full.file_setup.mime_type.match('mp4.*') || afile_type == 'mp4'){
|
|
return '<video class="text-center img-fluid" width="150" height="130" controls controlsList="nodownload"><source src="'+file+'" type="video/mp4">Your browser does not support HTML5 video.</video>';
|
|
}
|
|
else if( full.file_setup.mime_type.match('mp3.*') || afile_type == 'mp3'){
|
|
return '<button onclick="event_attachment.upload.audio_mode.on_load_play(this, \'sound-control-'+meta.row+'\');" class="text-center btn btn-primary" width="170" id="audio-mode-ctrl-'+meta.row+'"> jouer </button><audio id="sound-control-'+meta.row+'"><source src="'+file+'" type="audio/mpeg">Your browser does not support the audio element.</audio>';
|
|
}
|
|
else
|
|
return '<img class="text-center img-thumbnail img-fluid" style="height: 123px !important; width: 170px !important;" src="'+file+'"/>';
|
|
|
|
},
|
|
|
|
/* RULES
|
|
- 1 or 2 files are allowed with combinations [image & mp3], [image], [video]
|
|
- search for MP3/Video file to add autoplay[on/off] settings
|
|
- search for MP3 only, add a settings[on/off] if the user wants to use the default image or not
|
|
if not then he will be required to upload one image
|
|
*/
|
|
"validate" : {
|
|
|
|
/**
|
|
* Inform user that the image should have atleast 610 = width and 431 = heigth
|
|
* @param {*} file = file upload information
|
|
*/
|
|
"isValidSize" : function(files){
|
|
var dimensions = $("#ModalInformationSizeHeader").attr("data-valid-image-size").split("_");
|
|
var file = (typeof files == "object")?URL.createObjectURL(files):app.get_vars().events.attachment.events+full.file_preview;
|
|
var img = document.createElement('img');
|
|
img.src = file;
|
|
|
|
ufile_type = files.name.split('.').pop();
|
|
|
|
switch (ufile_type) {
|
|
case 'png':
|
|
case 'jpg':
|
|
case 'jpeg':
|
|
case 'gif':
|
|
img.addEventListener('load', function() {
|
|
if( dimensions.length > 0 && this.naturalWidth < (parseInt(dimensions[0])) && this.naturalHeight < (parseInt(dimensions[1]))) {
|
|
$("#width").html(this.naturalWidth);
|
|
$("#height").html(this.naturalHeight);
|
|
$('#isValidRationModal').modal({
|
|
show: 'false'
|
|
});
|
|
}
|
|
});
|
|
break;
|
|
}
|
|
|
|
},
|
|
|
|
/*check whether there is file of a given attachment_type */
|
|
"disable_browse_file" : function(attachment_type) {
|
|
var eventFiles = $('#eventfiles');
|
|
var browse_file_attachment = $('#browse_file_attachment');
|
|
if(browse_file_attachment.length > 0){
|
|
if(typeof events.get_vars().event_file_attachment_list != "undefined"){
|
|
|
|
var data = (events.get_vars().event_file_attachment_list)[0].data(),
|
|
file_type = [];
|
|
|
|
if(data.length >0) {
|
|
$.map(data, function(value){
|
|
if(value.attachment_type == attachment_type){
|
|
file_type.push(value.file_setup.mime_type); //extract all files with a given attachment_type
|
|
}
|
|
});
|
|
|
|
var fLength = file_type.length;
|
|
const wType= events.get_vars().workshop_session
|
|
if(attachment_type == 1 && (fLength==2 || (wType=="ENLIGNE" && fLength==1))) { //todo
|
|
browse_file_attachment.attr("disabled", "disabled");
|
|
eventFiles.removeClass("filechooser").prop("disabled", true);
|
|
return; //only one image is allowed for attachment_type 1
|
|
} else {
|
|
if(fLength == 1){
|
|
if(file_type[0].indexOf("video")!= -1){
|
|
browse_file_attachment.attr("disabled", "disabled");
|
|
eventFiles.removeClass("filechooser").prop("disabled", true);
|
|
return; // only one file is required for video
|
|
}
|
|
} else if(fLength == 2) {
|
|
browse_file_attachment.attr("disabled", "disabled");
|
|
eventFiles.removeClass("filechooser").prop("disabled", true);
|
|
return; //disable button when already reached the max number of allowed files
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
browse_file_attachment.removeAttr("disabled");
|
|
eventFiles.addClass("filechooser").prop("disabled", false);
|
|
return;
|
|
},
|
|
//this works for editing files. its a long process haha
|
|
"restricted" : function(attachment_type, file_type, file_name, uploadedFiles, row){
|
|
row = (row!=null && typeof row!= "undefined")?row:-1;
|
|
|
|
var table_data = event_attachment.upload.validate.delete_cloned_row(row, attachment_type),
|
|
table_data_len = table_data.length,
|
|
data = (table_data_len > 0)?table_data:((row>=0)?[]:uploadedFiles),
|
|
file_types = [], eventFiles = $('#eventfiles'),
|
|
duplicate_file = false;
|
|
|
|
$.map(data, function(value, key){
|
|
var atype = "", name="", mime_type = "";
|
|
if(table_data_len > 0){ //datatable
|
|
atype = parseInt(value.attachment_type);
|
|
name = (value.file_setup.file_name).toLowerCase();
|
|
mime_type = value.file_setup.mime_type;
|
|
} else { //uploadedFiles
|
|
atype = parseInt(value.atype);
|
|
name = value.name;
|
|
mime_type = value.type;
|
|
}
|
|
|
|
if(atype == parseInt(attachment_type)){
|
|
file_types.push(mime_type); //extract all files with a given attachment_type
|
|
}
|
|
if(file_name.toLowerCase() == (name).toLowerCase()){
|
|
duplicate_file = true;
|
|
return false;
|
|
}
|
|
});
|
|
|
|
if(duplicate_file){
|
|
app._notify("warning", "Uploading a possible duplicate file!");
|
|
return true;
|
|
}
|
|
|
|
var fLength = file_types.length;
|
|
if(attachment_type == 1 && fLength==2){
|
|
app._notify("warning", "Only two files is required for Joindre photo Event");
|
|
return true; //only one image is allowed for attachment_type 1
|
|
} else {
|
|
if(fLength == 2){
|
|
|
|
if(file_types[0].indexOf("video")!= -1){
|
|
app._notify("warning", "Only one file is required for Joindre photo Event detail of type mp4");
|
|
return true; // only one file is required for video
|
|
} else if(file_types[0].indexOf("audio") != -1){
|
|
/*
|
|
COMBINATIONS OF AUDIO AND IMAGE IS ALLOWED!!!
|
|
WE DO NOT ALLOW [audio and video] and [audio and another audio file].
|
|
ONLY ONE AUDIO FILE is allowed aqd the other one must be an IMAGE only if provided!!!
|
|
*/
|
|
if(file_type.indexOf("audio") != -1 || file_type.indexOf("video") != -1){
|
|
app._notify("warning", "Only one mp3/mp4 file is allowed for Joindre photo Event detail");
|
|
return true; // only one file is required for video
|
|
}
|
|
} else if(file_types[0].indexOf("image") != -1){
|
|
if(file_type.indexOf("image") != -1){
|
|
app._notify("warning", "Only one image must be on this attachment type.");
|
|
return true; // only one file is required for video
|
|
} else if(file_type.indexOf("video") != -1){
|
|
app._notify("warning", "Video is not allowed to be added with image on this attachment type.");
|
|
return true; // only one file is required for video
|
|
}
|
|
}
|
|
} else if(fLength == 2) {
|
|
app._notify("warning", "Only one or two files are required for Joindre photo Event detail");
|
|
return true; //disable button when already reached the max number of allowed files
|
|
}
|
|
}
|
|
//we will continue processing files if no conflict occurs
|
|
return false;
|
|
},
|
|
|
|
"file_type" : function(file, attachment_type){
|
|
var mp4 = (file.type.match(/video/g)||[]).length;
|
|
var mp3 = (file.type.match(/audio/g)||[]).length;
|
|
var images = (file.type.match(/image/g)||[]).length;
|
|
var attachment_type = parseInt(attachment_type);
|
|
|
|
if( mp4 || mp3 || images ) {
|
|
if( mp3 && attachment_type < 2 ) {
|
|
app._notify("warning", "mp3 uploading available only for Joindre photo Event detail");
|
|
} else if( mp4 && attachment_type < 2 ) {
|
|
|
|
app._notify("warning", "mp4 uploading available only for Joindre photo Event detail");
|
|
} else {
|
|
return true;
|
|
}
|
|
} else {
|
|
app._notify("warning", "Allowed types only image.* and mp3.* and mp4.*");
|
|
}
|
|
return false;
|
|
},
|
|
|
|
"total_uploadFiles_exceeded" : function(uploadedFiles, totalUploadFiles, attachment_type){
|
|
|
|
if(totalUploadFiles > 2 && attachment_type == 1){
|
|
//check upload size
|
|
var file_size = Math.round(parseInt(uploadedFiles[0].size) / (1024*1024));
|
|
if(file_size > 50){
|
|
app._notify("warning", "File size must not exceed 50mb.");
|
|
return true;
|
|
} else {
|
|
app._notify("warning", "Only one file is required for Joindre photo Event");
|
|
return true;
|
|
}
|
|
} else if(attachment_type == 2){
|
|
if(totalUploadFiles > 2) {
|
|
app._notify("warning", "Only one or two files are required for Joindre photo Event detail");
|
|
return true;
|
|
} else {
|
|
//check upload contents
|
|
if(totalUploadFiles == 1){
|
|
var file_size = Math.round(parseInt(uploadedFiles[0].size) / (1024*1024));
|
|
if(file_size > 50){
|
|
app._notify("warning", "File size must not exceed 50MB.");
|
|
return true;
|
|
}
|
|
} else if(totalUploadFiles == 2) {
|
|
|
|
var file_size1 = Math.round(parseInt(uploadedFiles[0].size) / (1024*1024));
|
|
var file_size2 = Math.round(parseInt(uploadedFiles[1].size) / (1024*1024));
|
|
var file_types = uploadedFiles[0].type+", "+uploadedFiles[1].type;
|
|
|
|
if(file_size1 > 50 || file_size2 > 50){
|
|
app._notify("warning", "File size must not exceed 50MB.");
|
|
return true;
|
|
} else if((file_types.match(/audio/g)||[]).length >1) {
|
|
|
|
app._notify("warning", "Only one mp3 file is required for Joindre photo Event detail");
|
|
return true;
|
|
|
|
} else if((file_types.match(/video/g)||[]).length >1) {
|
|
|
|
app._notify("warning", "Only one mp4 file is required for Joindre photo Event detail");
|
|
return true;
|
|
|
|
} else if((file_types.match(/image/g)||[]).length >1) {
|
|
|
|
app._notify("warning", "Only one image file is required for Joindre photo Event detail");
|
|
return true;
|
|
|
|
} else if((file_types.match(/video/g)||[]).length >0 && (file_types.match(/audio/g)||[]).length >0) {
|
|
app._notify("warning", "Only one mp3 or mp4 file is required for Joindre photo Event detail");
|
|
return true;
|
|
|
|
} else if((file_types.match(/video/g)||[]).length >0 && (file_types.match(/image/g)||[]).length >0) {
|
|
|
|
app._notify("warning", "MP4 file cannot added with an image for Joindre photo Event detail");
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
},
|
|
/*This is basically the process of deleting a row when user wants to replace a file by editing, we need to
|
|
exclude the row to be replaced about in order to get a proper validation message
|
|
*/
|
|
"delete_cloned_row" : function(row, attachment_type){
|
|
var table_data = $("#event_file_attachment_list").DataTable().data();
|
|
if(row>=0){
|
|
var tobe_deleted_row = $("#event_file_attachment_list").DataTable().row(parseInt(row)).data();
|
|
$.map(table_data, function(value, key){
|
|
if(typeof value!= "undefined"){
|
|
if(tobe_deleted_row.attachment_id == value.attachment_id && parseInt(attachment_type) == parseInt(value.attachment_type)){
|
|
table_data.splice(key, 1);
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
return table_data;
|
|
},
|
|
|
|
"check_file_attachment" : function(){ //this is for validating event information before sending
|
|
//only attachment type 1 is required
|
|
var table_data = $("#event_file_attachment_list").DataTable().data();
|
|
const wType = events.get_vars().workshop_session
|
|
if((table_data.length > 1) || ((wType=="ENLIGNE" || wType=="DISTANCE") && table_data.length==1)){
|
|
var found = false;
|
|
$.map(table_data, function(value, key){
|
|
if(typeof value!= "undefined"){
|
|
if(parseInt(value.attachment_type) == 1){
|
|
found = true;
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
return found;
|
|
}
|
|
return false;
|
|
},
|
|
"check_video_attachment": function(){
|
|
return event_attachment.get_trailer()
|
|
}
|
|
}
|
|
},
|
|
"add_trailer": function(videoId){
|
|
$.ajax({
|
|
url: app.get_vars().baseurl+"events/event_video/get_video_details?video_id="+videoId,
|
|
type: "GET",
|
|
success: function(result) {
|
|
const videoDetails = JSON.parse(result)
|
|
$('#trailer').val('')
|
|
if(videoDetails.status && videoDetails.status === 200) {
|
|
event_attachment.append_trailer(videoDetails.body.embed.html)
|
|
event_attachment.current_trailer = JSON.stringify(videoDetails.body.embed.html)
|
|
} else {
|
|
event_attachment.current_trailer = null
|
|
$('#trailer_video').empty()
|
|
app._notify('error', videoDetails.body.error);
|
|
}
|
|
$('#add_trailer').removeAttr('disabled', true);
|
|
}
|
|
});
|
|
},
|
|
"get_trailer":function(){
|
|
return $('#trailer_video').find('iframe')[0]
|
|
},
|
|
"current_trailer":null,
|
|
"append_trailer": function(video){
|
|
$('#trailer_video').append(video)
|
|
}
|
|
};// end of return
|
|
|
|
})(jQuery, this);
|
|
|
|
$(function() {
|
|
/* restrict file uploads by attachment type */
|
|
$("#event-file-attachment").on("change", function(e){
|
|
var attachment_type = 1//parseInt($(e.target).val());
|
|
//disable browse file
|
|
event_attachment.upload.validate.disable_browse_file(attachment_type);
|
|
|
|
if(attachment_type == 1){
|
|
$("#eventfiles").prop("multiple", false).prop("accept", "image/*");
|
|
} else {
|
|
$("#eventfiles").prop("multiple", true).prop("accept", "image/*,video/*, audio/*");
|
|
}
|
|
});
|
|
$('#add_trailer').on('click', function(){
|
|
let videoInput = $('#trailer')
|
|
if(videoInput.val() === '') {
|
|
videoInput.focus()
|
|
} else {
|
|
$('#add_trailer').attr('disabled', true);
|
|
event_attachment.add_trailer(videoInput.val())
|
|
}
|
|
})
|
|
$('#remove_trailer').on('click', function(){
|
|
$('#trailer_video').empty()
|
|
event_attachment.current_trailer = null
|
|
})
|
|
});
|