Last active
December 27, 2023 23:59
-
-
Save benjsicam/6247022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* WIZARD CODE | |
* This is the step where you create your file upload page. | |
*/ | |
if (step == 'custstep_upload_file') { | |
var fileField = this.wizard.addField('custpage_file', 'select', 'File'); | |
var uploadButton = this.wizard.addField('custpage_btn_upload', 'inlinehtml', 'Browse'); | |
fileField.setPadding(2); | |
fileField.setMandatory(true); | |
fileField.setDisplayType('disabled'); | |
/* This is the upload button markup. The button ID is select (id="select")*/ | |
uploadButton.setDefaultValue('<table id="custbl_button"> <tbody> <tr> <td> <table id="tbl_select" cellpadding="0" cellspacing="0" border="0" style="margin-left:133px;cursor:hand;"> <tbody> <tr id="tr_select" class="pgBntG"> <td id="tdleftcap_select"> <img src="/images/nav/ns_x.gif" class="bntLT" border="0" height="50%" width="3"> <img src="/images/nav/ns_x.gif" class="bntLB" border="0" height="50%" width="3"> </td> <td id="tdbody_select" height="20" valign="top" nowrap="" class="bntBgB"> <input type="button" style="" class="rndbuttoninpt bntBgT" value="Upload a File" id="select" name="select" onmousedown="this.setAttribute(\'_mousedown\',\'T\'); setButtonDown(true, true, this);" onmouseup="this.setAttribute(\'_mousedown\',\'F\'); setButtonDown(false, true, this);" onmouseout="if(this.getAttribute(\'_mousedown\')==\'T\') setButtonDown(false, true, this);" onmouseover="if(this.getAttribute(\'_mousedown\')==\'T\') setButtonDown(true, true, this);"> </td> <td id="tdrightcap_select"> <img src="/images/nav/ns_x.gif" height="50%" class="bntRT" border="0" width="3"> <img src="/images/nav/ns_x.gif" height="50%" class="bntRB" border="0" width="3"> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table>'); | |
} | |
//--------------END OF WIZARD CODE-------------------- | |
/** | |
* CSS Code | |
* Bind this CSS on the Wizard | |
*/ | |
function onPageInit() { | |
var fileUploadButton = jQuery('#select'); | |
if (fileUploadButton == '' || fileUploadButton == null || fileUploadButton == undefined) | |
return true; | |
nlapiRemoveSelectOption('custpage_file', null); | |
nlapiInsertSelectOption('custpage_file', '', 'Please upload a File', true); | |
/* Bind the click event on the button. */ | |
jQuery('#select').on('click', function () { | |
var fileUploadSuiteletURL = nlapiResolveURL('SUITELET', 'customscript_file_upload_slet', 'customdeploy_file_upload_slet'); | |
var width = 480; | |
var height = 160; | |
var left = (screen.width / 2) - (width / 2); | |
var top = (screen.height / 2) - (height / 2); | |
/* Open the File Upload suitelet on the center of the wizard screen. */ | |
window.open(fileUploadSuiteletURL, 'UploadFile', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left); | |
}); | |
}; | |
function setFile(fileId, fileName) { | |
nlapiRemoveSelectOption('custpage_file', null); | |
nlapiInsertSelectOption('custpage_file', '', 'Please upload a File', true); | |
nlapiInsertSelectOption('custpage_file', fileId, fileName, false); | |
nlapiSetFieldValue('custpage_file', fileId, true, true); | |
} | |
//---------------------END OF CSS Code --------------------------- | |
/** | |
* Suitelet Code | |
* This is the suitelet which will get opened when the Browse button is clicked on the wizard. | |
*/ | |
FileUploadSLET.doGet = function (request, response) { | |
var form = nlapiCreateForm('Upload a File', true); | |
form.addField('custpage_file', 'file', 'File').setMandatory(true); | |
var folderField = form.addField('custpage_folder', 'select', 'Folder').setMandatory(true); | |
var folder = nlapiCreateRecord('folder'); | |
var folders = folder.getField('parent').getSelectOptions(); | |
folderField.addSelectOption('', '', true); | |
for(var i = 0; i < folders.length; i++) | |
folderField.addSelectOption(folders[i].getId(), folders[i].getText()); | |
form.addSubmitButton('Upload'); | |
response.writePage(form); | |
}; | |
FileUploadSLET.doPost = function (request, response) { | |
var file = request.getFile('custpage_file'); | |
file.setFolder(request.getParameter('custpage_folder')); | |
file.setEncoding('UTF-8'); | |
var newFileId = nlapiSubmitFile(file); | |
response.setContentType('HTMLDOC'); | |
response.write('<!DOCTYPE html><html><head><title>Upload Successful</title></head><body><h3>Upload Successful</h3><script type="text/javascript">window.opener.setFile("' + newFileId + '", "' + fileName + '"); window.close();</script></body></html>'); | |
}; | |
//---------------------END OF Suitelet Code --------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment