//Set Javascript Security Levels var DocumentsSecurityView = true; var DocumentsSecurityEdit = false; var DocumentsSecurityAdmin = false; //NOTE THAT THESE NEED TO BE SET BY MODULE CALLING THIS //LIBRARY BEFORE INCLUDING LIBRARY. //var DocumentsSecurityView = false; //var DocumentsSecurityEdit = false; //var DocumentsSecurityAdmin = false; //var DocumentsSecurityRole = Required Role; var FolderSeperator = "XXXX"; //RETRIEVE ALL FOLDERS var folders = []; getFolders("Documents"); function getFolders(OpenFolderID) { if (!DocumentsSecurityView ) { $("#docsection-elements").hide(); alertMsg("You do not have access to this inforamtion!"); return; } var data = {}; data['sf'] = 'folders'; $.ajax({ url: '/data/documents/', type: 'get', data: data, dataType: 'json', async: true, success: function(data) { folders = data.Folders; setFolders(OpenFolderID); }, error: function (jqXHR, textStatus, errorThrown) { alertMsg(jqXHR.responseText); } }); } var foldersIndex = []; function setFolders(OpenFolderID) { //CLEAR CURRENT FOLDER LIST IF ANY $("#FOLDERS").html(""); //SET ROOT FOLDER THEN OPEN IT var FOLDER_table_body = document.createElement("tbody"); FOLDER_table_body.id = "FOLDER_table_body"; $("#FOLDERS").append(FOLDER_table_body); var folderPadding = 10; setFolder(folders[0],folderPadding,foldersIndex,true); $("#doc_"+folders[0].ID).show(); var folderKeys = OpenFolderID.split(FolderSeperator); var folderKey = ""; for ( var i=0; i < folderKeys.length; i++ ) { if ( folderKey == "" ) folderKey = folderKeys[i]; else folderKey = folderKey + FolderSeperator + folderKeys[i]; openFolder(folderKey,true); } } function setFolder(folder,folderPadding,fIndex,rootFolder) { var ROOT_FOLDER_row = document.createElement("tr"); ROOT_FOLDER_row.id = "doc_"+folder.ID; $("#FOLDERS").append(ROOT_FOLDER_row); folder.open = false; folder.selected = false; folder.padding = folderPadding; folder.rootFolder = rootFolder; fIndex[folder.ID] = folder; $("#doc_"+folder.ID).hide(); for ( var i=0; i < folder.Folders.length; i++) { var ROOT_FOLDER_row = document.createElement("tr"); ROOT_FOLDER_row.id = folder.Folders[i].ID; $("#FOLDERS").append(ROOT_FOLDER_row); setFolder(folder.Folders[i],folderPadding+20,fIndex,false); } } function openFolder(folderID, firstIteration) { var folder = foldersIndex[folderID]; folder.open = true; var folderIcon = "fa-folder-open-o"; var folderOperation = "close"; var folderWidth = "100"; if ( !firstIteration ) { folder.open - false; folderIcon = "fa-folder-o"; folderOperation = "open"; } var folderHTML = ""; if (DocumentsSecurityAdmin ) { folderWidth = "75"; folderHTML = getAdminTD(folder); } folderHTML = folderHTML + getFolderTD(folder,folderIcon,folderOperation,folderWidth,false); $("#doc_"+folder.ID).html(folderHTML); if ( firstIteration ) { selectFolder(folderID,true); for ( var i=0; i < folder.Folders.length; i++ ) { openFolder(folder.Folders[i].ID,false); $("#doc_"+folder.Folders[i].ID).show(); folder.Folders[i].open = false; } } } function closeFolder(folderID) { var folder = foldersIndex[folderID]; folder.open = false; var folderIcon = "fa-folder-o"; var folderOperation = "open"; var folderWidth = "100"; var folderHTML = ""; if (DocumentsSecurityAdmin ) { folderWidth = "75"; folderHTML = getAdminTD(folder); } folderHTML = folderHTML + getFolderTD(folder,folderIcon,folderOperation,folderWidth,false); $("#doc_"+folder.ID).html(folderHTML); for ( var i=0; i < folder.Folders.length; i++ ) { $("#doc_"+folder.Folders[i].ID).hide(); folder.Folders[i].open = false; closeFolder(folder.Folders[i].ID); } selectFolder(folderID,true); } selectedFolder = ""; function selectFolder(folderID,select) { if ( select && selectedFolder != "" ) { selectFolder(selectedFolder,false); } var folder = foldersIndex[folderID]; folder.selected = true; selectedFolder = folder.ID; var folderIcon = "fa-folder-o"; var folderOperation = "open"; var folderWidth = "100"; if ( folder.open ) { folderIcon = "fa-folder-open-o"; folderOperation = "close"; } var folderHTML = ""; if (DocumentsSecurityAdmin ) { folderWidth = "75"; folderHTML = getAdminTD(folder); } folderHTML = folderHTML + getFolderTD(folder,folderIcon,folderOperation,folderWidth,select); $("#doc_"+folder.ID).html(folderHTML); if ( select ) displayDocuments(folder); } function displayDocuments(folder) { $("#DOCS").html(""); var DOC_table_body = document.createElement("tbody"); DOC_table_body.id = "DOC_table_body"; $("#DOCS").append(DOC_table_body); if ( folder.Documents.length == 0 ) { var DOC_row = document.createElement("tr"); DOC_row.id = "docS_EMPTY"; $("#DOCS").append(DOC_row); if ( DocumentsSecurityEdit ) { $("#docS_EMPTY").html( "  UPLOAD DOCUMENTS" ); } else { $("#docS_EMPTY").html( "FOLDER EMPTY" ); } } else { if ( DocumentsSecurityEdit ) { var DOC_rowAdd = document.createElement("tr"); DOC_rowAdd.id = "docS_ADD"; $("#DOCS").append(DOC_rowAdd); $("#docS_ADD").html( "  UPLOAD DOCUMENTS" ); } for ( var i=0; i < folder.Documents.length; i++ ) { var DOC_row = document.createElement("tr"); DOC_row.id = "docS_"+folder.Documents[i].Key; $("#DOCS").append(DOC_row); if ( DocumentsSecurityEdit ) { $("#"+"docS_"+folder.Documents[i].Key).html( "  " + "" + folder.Documents[i].Name + "" + "" + folder.Documents[i].Date + "" ); } else { $("#"+"docS_"+folder.Documents[i].Key).html( "" + folder.Documents[i].Name + "" + "" + folder.Documents[i].Date + "" ); } } } } function addDocument(folderID) { var folder = foldersIndex[folderID]; var folder_path = folder.ID; folder_path = folder_path.replaceAll(FolderSeperator, '/'); $("#DOC_UPLOADER_MODAL_DIV").html(""); setUploaderModal(folder_path); // folder/folder/folder $("#ModalDocumentUpload").modal(); } function saveUploadedDocument(FileName,folderPath) { var newDocument = {}; newDocument.Name = FileName; newDocument.Date = "Today"; newDocument.URL = folderPath + "/" + FileName; newDocument.Key = FileName.replaceAll('.', '_'); newDocument.Key = newDocument.Key.replaceAll(' ', '_'); var folder_key = folderPath.replaceAll('/', FolderSeperator); var folder = foldersIndex[folder_key]; folder.Documents[folder.Documents.length] = newDocument; if ( !DocumentsSecurityAdmin && !DocumentsSecurityEdit ) { alertMsg("You do not have access to this function!"); } else { var DOC_row = document.createElement("tr"); DOC_row.id = "docS_" + newDocument.Key; $("#DOCS").append(DOC_row); if ( DocumentsSecurityEdit ) { $("#"+"docS_"+newDocument.Key).html( "  " + "" + newDocument.Name + "" + "Today" ); } else { $("#"+"docS_"+document.Key).html( "" + newDocument.Name + "" + "Today" ); } } $("#ModalDocumentUpload").modal("hide"); } function removeDocument(folderID, docName, docKey) { if ( DocumentsSecurityAdmin || DocumentsSecurityEdit ) { $.confirm({ 'title' : 'REMOVE DOCUMENT', 'message' : 'You are about to delete this document.
This is a permanent deletion! Continue?', 'buttons' : { 'Yes' : { 'class' : 'blue', 'action': function(){ removeDocumentGo(folderID,docName,docKey); } }, 'No' : { 'class' : 'gray', 'action': function(){} // Nothing to do in this case. You can as well omit the action property. } } }); } } function removeDocumentGo(folder,fileName,docKey) { folder = folder.replaceAll('Documents'+FolderSeperator, ''); folder = folder.replaceAll(FolderSeperator, '/'); if ( folder == "Documents" ) folder = ""; if ( DocumentsSecurityAdmin || DocumentsSecurityEdit ) { var data = {}; data['sf'] = 'removedocument'; data['FileName'] = fileName; data['Folder'] = folder; $.ajax({ url: '/data/documents/', type: 'get', data: data, dataType: 'json' }); $("#docS_"+docKey).remove(); } } function addFolder(folderID) { folderID = folderID.replaceAll('Documents'+FolderSeperator, ''); folderID = folderID.replaceAll(FolderSeperator, '/'); if ( folderID == "Documents" ) folderID = ""; $("#ParentFolder").val(folderID); $("#FolderTabName").val(""); $("#ModalFolderTabEdit").modal(); } function saveFolderTab() { if ( DocumentsSecurityAdmin ) { if ( $("#FolderTabName").val() == "" ) { alertMsg("You must enter a folder name!"); return; } var data = {}; data['sf'] = 'savefoldertab'; data['FolderTabName'] = $("#FolderTabName").val(); data['ParentFolder'] = $("#ParentFolder").val(); data['FolderType'] = "FOLDERS"; var NewFolderKey = "Documents"; if ( $("#ParentFolder").val() != "" ) NewFolderKey = "Documents/" + $("#ParentFolder").val() + "/" + $("#FolderTabName").val(); NewFolderKey = NewFolderKey.replaceAll('/', FolderSeperator); $.ajax({ url: '/data/documents/', type: 'get', data: data, dataType: 'json', success: function(data) { if ( data.message == '' ) { folders = []; getFolders(NewFolderKey); } else { alertMsg(data.message); } }, error: function (jqXHR, textStatus, errorThrown) { alertMsg(jqXHR.responseText); } }); } } function moveFolder(folderID) { var folderList = getFolderList(folderID,""); if ( DocumentsSecurityEdit ) { $.confirm({ 'title' : 'MOVE FOLDER', 'message' : 'Select the Folder to move selected folder to....' + folderList, 'buttons' : { 'Cancel' : { 'class' : 'blue', 'action': function(){ } } } }); } } function moveDocument(folderID, docName) { var folderList = getFolderList(folderID,docName); if ( DocumentsSecurityEdit ) { $.confirm({ 'title' : 'MOVE DOCUMENT', 'message' : 'Select the Folder to move document to....' + folderList, 'buttons' : { 'Cancel' : { 'class' : 'blue', 'action': function(){ } } } }); } } function getFolderList(folderID,docName) { var folderList = "
"; for ( var i=0; i < folders.length; i++ ) { var folderKey = folders[i].ID.replaceAll(FolderSeperator, '/'); if ( folders[i].ID != folderID ) folderList = folderList + "" + folderKey + "
"; folderList = getFolderListChildren(folderList,folders[i].Folders,folderID,docName); } return folderList + "
"; } function getFolderListChildren(folderList,childFolders,folderID,docName) { for ( var i=0; i < childFolders.length; i++ ) { var folderKey = childFolders[i].ID.replaceAll(FolderSeperator, '/'); if ( childFolders[i].ID != folderID ) folderList = folderList + "" + folderKey + "
"; folderList = getFolderListChildren(folderList, childFolders[i].Folders, folderID, docName); } return folderList; } function moveDocumentToFolder(folderID, docName, newFolderID) { var newFolderKey = newFolderID; folderID = folderID.replaceAll('Documents'+FolderSeperator, ''); folderID = folderID.replaceAll(FolderSeperator, '/'); if ( folderID == "Documents" ) folderID = ""; newFolderID = newFolderID.replaceAll('Documents'+FolderSeperator, ''); newFolderID = newFolderID.replaceAll(FolderSeperator, '/'); if ( newFolderID == "Documents" ) newFolderID = ""; if ( DocumentsSecurityEdit ) { var data = {}; data['sf'] = 'movedocument'; data['FileName'] = docName; data['CurFolder'] = folderID; data['NewFolder'] = newFolderID; $.ajax({ url: '/data/documents/', type: 'get', data: data, dataType: 'json', success: function(data) { if ( data.message == '' ) { $.confirm.hide(); folders = []; getFolders(newFolderKey); } else { alertMsg(data.message); } }, error: function (jqXHR, textStatus, errorThrown) { alertMsg(jqXHR.responseText); } }); } } function removeFolder(folderID) { if ( DocumentsSecurityAdmin ) { $.confirm({ 'title' : 'REMOVE FOLDER TAB', 'message' : 'You are about to delete this folder/tab.
This is a permanent deletion and will also delete all the documents in the folder/tab! Continue?', 'buttons' : { 'Yes' : { 'class' : 'blue', 'action': function(){ removeFolderGo(folderID); } }, 'No' : { 'class' : 'gray', 'action': function(){} // Nothing to do in this case. You can as well omit the action property. } } }); } } function removeFolderGo(folder) { var ParentFolderKey = ""; var folderKeys = folder.split(FolderSeperator); for ( var i=0; i < folderKeys.length-1; i++ ) { if ( ParentFolderKey == "" ) ParentFolderKey = folderKeys[i]; else ParentFolderKey = ParentFolderKey + FolderSeperator + folderKeys[i]; } folder = folder.replaceAll('Documents'+FolderSeperator, ''); folder = folder.replaceAll(FolderSeperator, '/'); if ( folder == "Documents" ) { alertMsg("You cannot remove the root folder!"); return; } if ( DocumentsSecurityAdmin ) { var data = {}; data['sf'] = 'removefolder'; data['FolderTabName'] = folder; $.ajax({ url: '/data/documents/', type: 'get', data: data, dataType: 'json' }); folders = []; getFolders(ParentFolderKey); } } function getAdminTD(folder) { if ( folder.rootFolder ) { return ""; } else { return "    "; } } var selectedFolder = ""; function getFolderTD(folder,folderIcon,folderOperation,folderWidth,folderSelected) { var selectedStart = ""; var selectedEnd = ""; if ( folderSelected ) { selectedStart = ""; selectedEnd = ""; } return "  " + selectedStart + folder.Name + selectedEnd + ""; } function setUploaderModal(folder) { if ( DocumentsSecurityAdmin || DocumentsSecurityEdit ) { $("#DOC_UPLOADER_MODAL").filer({ limit: 30, maxSize: null, extensions: ["pdf","std","mdb","rec","txt","cl2","xls","doc","xlsx","docx","zip"], changeInput: '

Drag&Drop files here

or
Browse Files
', showThumbs: true, theme: "dragdropbox", dragDrop: { dragEnter: null, dragLeave: null, drop: null, dragContainer: null, }, uploadFile: { url: '/data/documents/', type: 'post', data: {sf: "uploaddocument", Folder: folder}, enctype: 'multipart/form-data', synchron: true, beforeSend: function(){}, success: function(data, itemEl, listEl, boxEl, newInputEl, inputEl, id){ //data: "\"CCF0613.cl2\"" //itemE1 {"0":{"jfiler_id":0,"jQuery3110134999583825587081":{"display":""}},"length":1} //listE1: {"0":{"jQuery311074496424733529711":{"events":{"click":[{"type":"click","origType":"click","guid":52,"selector":".jFiler-item-trash-action","needsContext":false,"namespace":""}]}}},"length":1} data = JSON.parse(data); var new_file_name = data.fileName; var filerKit = inputEl.prop("jFiler"); filerKit.files_list[id].name = new_file_name; selectedFileName = new_file_name; itemEl.find(".jFiler-jProgressBar").fadeOut("slow", function(){ saveUploadedDocument(data.fileName, folder); }); }, error: function(el){ var parent = el.find(".jFiler-jProgressBar").parent(); el.find(".jFiler-jProgressBar").fadeOut("slow", function(){ $("
Error
").hide().appendTo(parent).fadeIn("slow"); }); }, statusCode: null, onProgress: null, onComplete: null }, files: null, addMore: false, allowDuplicates: true, clipBoardPaste: true, excludeName: null, beforeRender: null, afterRender: null, beforeShow: null, beforeSelect: null, onSelect: null, afterShow: null, onRemove: function(itemEl, file, id, listEl, boxEl, newInputEl, inputEl){ var filerKit = inputEl.prop("jFiler"), file_name = filerKit.files_list[id].name; }, onEmpty: null, options: null, dialogs: { alert: function(text) { return alertMsg(text); }, confirm: function (text, callback) { confirm(text) ? callback() : null; } }, captions: { button: "Choose Files", feedback: "Choose files To Upload", feedback2: "files were chosen", drop: "Drop file here to Upload", removeConfirmation: "Are you sure you want to remove this file?", errors: { filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.", filesType: "This file type is not supported here.", filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.", filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB." } } }); } } $(document).ready(function() { $('#ModalEmailText').summernote({ tabsize: 2, height: 175, toolbar: [ ['style', ['style']], ['font', ['bold', 'underline', 'clear', 'fontname', 'fontsize']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['table', ['table']], ['insert', ['link', 'picture', 'video']], ['view', ['fullscreen', 'codeview', 'help']] ] }); }); /* Screens that include email must include this JS file and prepare an array as follows: Element 0: - list = "on/off" If ON then listname is used. - listname = "The Name of the List if emailing more than one recipent" - role = "Role required to send this email" - from = "Name of Email Sender like NVblu Service" - replyto = "Reply To Email Address" - direct = "on/off" If bypassing pop up screen -- subject/text required for this to work - codes = array of codes that match fields in recipent objects. codes can be selected in email pop up screen to insert matching data from recipient - bcc = BCC Email - subject = Email Subject - text = Email Text - attachment = Description of attachment file for list Element 1: First recipient (always required whether list is on or not) Element 2-n: Rest of recipents for a list....only used if list is on - email: Email for this recipent (required) - name: Name for this recipent (required) - attachment: URI with recipient parms for file being attached - CODES: Object of codes matching codes in Element 0 {CODE_NAME:"VALUE",CODE_NAME:"VALUE"} */ var modal_emails = []; function prepareEmail(emails) { //SET MASTER FOR SENDING modal_emails = emails; if ( emails[0].direct && emails[0].direct.toUpperCase() == "ON" ) { if ( (!emails[0].subject || emails[0].subject == "") || (!emails[0].text || emails[0].text == "") ) { alertMsg("You must provide a subject and email text for a direct email request."); } else { modalEmailSendEmail(); } return; } $("#ModalEmailCodes").html(""); var email_codes = ""; for ( var i=0; i < emails[0].codes.length; i++ ) { email_codes = email_codes + "[[" + emails[0].codes[i] + "]]

"; } $("#ModalEmailCodes").html(email_codes); if ( email_codes != "" ) $("#ModalEmailCodesBlock").show(); else $("#ModalEmailCodesBlock").hide(); $("#ModalEmails").empty(); if ( emails[0].list && emails[0].list.toUpperCase() == "ON" ) { $("#ModalEmailLabel").html("" + emails[0].listname + ":"); $("#ModalEmail").hide(); $("#ModalEmails").show(); for ( var i=1; i < emails.length; i++ ) { $("#ModalEmails").append(''); } } else { $("#ModalEmailLabel").html("Email " + emails[1].name + ":"); $("#ModalEmail").show(); $("#ModalEmails").hide(); $("#ModalEmail").val(emails[1].email); } if ( emails[0].attachment ) { $("#ModalEmailAttachment").html("Attachment: " + emails[0].attachment ); $("#ModalEmailAttachment").show(); } else { $("#ModalEmailAttachment").html(""); $("#ModalEmailAttachment").hide(); } if ( emails[0].bcc ) $("#ModalBCCEmail").val(emails[0].bcc); else $("#ModalBCCEmail").val(""); if ( emails[0].subject ) $("#ModalEmailSubject").val(emails[0].subject); else $("#ModalEmailSubject").val(""); if ( emails[0].text ) $('#ModalEmailText').summernote('code', emails[0].text); else $('#ModalEmailText').summernote('code', ''); //PRE PREPARED EMAILS CAN SKIP THE MODAL POPUP $("#ModalEmailModule").modal(); } function modalEmailSendEmailPrepare() { if ( $("#ModalEmailSubject").val() == "" || $('#ModalEmailText').summernote('code') == "" ) { alertMsg("EMAIL FAILED! Emails require a Subject and Text!"); return; } if ( emails[0].list && emails[0].list.toUpperCase() == "ON" ) { modal_emails[0].email = ""; } else { if ( $("#ModalEmail").val() == "" ) { alertMsg("EMAIL FAILED! You need to enter an email address!"); return; } emails[1].email = $("#ModalEmail").val(); } modal_emails[0].bcc = $("#ModalBCCEmail").val(); modal_emails[0].subject = $("#ModalEmailSubject").val(); modal_emails[0].text = $('#ModalEmailText').summernote('code'); modalEmailSendEmail(); } function modalEmailSendEmail() { var email_codes = ""; for ( var i=0; i < modal_emails[0].codes.length; i++ ) { if ( i > 0 ) email_codes = email_codes + "|"; email_codes = email_codes + modal_emails[0].codes[i]; } var emails = ""; for ( var i=1; i < modal_emails.length; i++ ) { if ( i > 1 ) emails = emails + "|"; var user_codes = ""; if ( modal_emails[i].codes ) { for ( var ii=0; ii < modal_emails[0].codes.length; ii++ ) { if ( ii > 0 ) user_codes = user_codes + ":"; if ( modal_emails[i].codes[modal_emails[0].codes[ii]] ) { user_codes = user_codes + modal_emails[0].codes[ii] + "=" + modal_emails[i].codes[modal_emails[0].codes[ii]]; } else { user_codes = user_codes + modal_emails[0].codes[ii] + "="; } } } if ( !modal_emails[i].attachment ) modal_emails[i].attachment = ""; emails = emails + modal_emails[i].email + ";" + modal_emails[i].name + ";" + modal_emails[i].attachment + ";" + user_codes; } if ( !modal_emails[0].role ) modal_emails[0].role = "ROOT"; if ( !modal_emails[0].replyto ) modal_emails[0].replyto = "eric@nvblu.com"; if ( !modal_emails[0].from ) modal_emails[0].from = "NVblu Service"; var data = {}; data['sf'] = 'sendemail'; data['Subject'] = modal_emails[0].subject; data['EmailText'] = modal_emails[0].text; data['BCC'] = modal_emails[0].bcc; data['Role'] = modal_emails[0].role; data['ReplyTo'] = modal_emails[0].replyto; data['From'] = modal_emails[0].from; data['Attachment'] = modal_emails[0].attachment; data['CODES'] = email_codes; data['EMAILS'] = emails; $.ajax({ url: '/data/documents/', type: 'post', data: data, dataType: 'json', success: function(data) { if ( data.message != "" ) { alertMsg(data.message); } }, error: function (jqXHR, textStatus, errorThrown) { alertMsg(jqXHR.responseText); } }); } function modalEmailSelectEmail() { if ( $("#ModalEmailID").val() == "" ) { $("#ModalEmailSubject").val(""); $('#ModalEmailText').summernote('code', ""); return; } var data = {}; data['sf'] = 'emailtemplate'; data['EmailTemplateID'] = $("#ModalEmailID").val(); $.ajax({ url: '/data/configuration/', type: 'get', data: data, dataType: 'json', success: function(data) { if ( data.message != "" ) alertMsg(data.message); else { $("#ModalEmailSubject").val(data.emailtemplate.Subject); $('#ModalEmailText').summernote('code', data.emailtemplate.EmailText); } }, error: function (jqXHR, textStatus, errorThrown) { alertMsg(jqXHR.responseText); } }); }