Author Topic: Opening URL link when connecting via Liquid UI Server  (Read 9318 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 95
    • View Profile
Opening URL link when connecting via Liquid UI Server
« on: October 02, 2023, 12:09:56 PM »
Purpose:
Opening a URL link is different via direct connect and Liquid UI Server.
This article explains how to open links when connecting through a Liquid UI server.


Liquid UI Code:
----------------------------------------------------------------------------------------------------------------------------------------------
Script File Name: SAPLSMTR_NAVIGATION.E0100.sjs       // SAP Easy Access
----------------------------------------------------------------------------------------------------------------------------------------------
//================================================
// User Interface
//================================================
del("X[IMAGE_CONTAINER]");
pushbutton([4,1],"Open URL/Link via LUI Server","?",{"process":openURLviaServer});



//================================================
//Function Scripts
//================================================
// Function prototype to trim blank characters from a string
String.prototype.trim = function () {
   return this.replace(/^\s+|\s+$/g, "");
}

// Function to return trimmed string
function getString(strInput) {
   return (typeof(strInput) == 'undefined' || strInput == 'undefined') ? "" : strInput.toString().trim();
}

// Function to check for blank string
// Specifically used to determine if input exist in the edit field
function isBlank(strInput) {
   var strVal = getString(strInput);
   var blank = strVal == "";
   return blank;
}

//Function to delete toolbar buttons on popup
function delButtonsRSM0400() {
   del('P[Continue]');
   del('P[Generate]');
   del('P[End Session]');
   del('P[Cancel]');
   if(<'P[Delete Session]'>.isValid)      del("P[Delete Session]");
}

//Function to display Liquid UI message popup
function procLUIMessageBox(param){
   var intHeight = 5 + 4 + param.l_message.length;
   var intPaintRow = 1;
   var intPaintCol = 3;
   enter("/o");
               
   onscreen 'RSM04000_ALV_NEW.2000'
      goto RESIZE_REPAINT;
      
   onscreen 'RSM04000_ALV.2000'
      RESIZE_REPAINT:;
      clearscreen();
      delButtonsRSM0400();
   
      title(param.l_title);
      
      if(isBlank(param.l_viewtext))   var viewTextContent='';
      else var viewTextContent = param.l_viewtext;
      if(isBlank(param.l_viewhtml))   var viewHTMLContent='';
      else var viewHTMLContent = param.l_viewhtml;
      if(isBlank(param.l_viewheight))   var viewHeight=0;
      else var viewHeight = param.l_viewheight;
      
      //Logic to render message
      for(var idxI=0; idxI<param.l_message.length; idxI++){
         var intWidth = (intWidth>param.l_message[idxI].length)?intWidth:param.l_message[idxI].length;
         if(param.l_message[idxI].indexOf("\t")==0)      //When message needs to be indented
            text([intPaintRow+idxI,intPaintCol+4], param.l_message[idxI]);
         else
            text([intPaintRow+idxI,intPaintCol], param.l_message[idxI]);
      }
      intWidth = intWidth+20;
      if(intWidth<51) intWidth=52;
      
      intPaintRow = 2 + param.l_message.length;
      if(!isBlank(fileURL)) {
         windowsize([5,5,90,intHeight+viewHeight]);
         view([intPaintRow-1,5],[intPaintRow+viewHeight,60],fileURL,{'name':fileURLName});
         intPaintRow = intPaintRow+1;
      } else if(viewTextContent.length>0) {
         textbox([intPaintRow,1],[intPaintRow+14,148],{'name':'viewTextContent','readonly':true});
         intPaintRow = intPaintRow+15;
         windowsize([5,5,150,intHeight+15]);
      } else if(viewHTMLContent.length>0) {
         var viewingFile = generatePrintableView(viewHTMLContent);
         var viewHNDL = getTodayDateTimeStr('HMS');
         //var viewingFile = viewHNDL+GP_Path_User+'PRINTCONTENT.htm';
         //view([intPaintRow,1],[intPaintRow+14,146],'&V[GP_Path_User]PRINTCONTENT.htm',{'name':viewHNDL});
         view([intPaintRow,1],[intPaintRow+14,146],viewingFile,{'name':viewHNDL});
         intPaintRow = intPaintRow+15;
         windowsize([5,5,150,intHeight+15]);
      } else {
         windowsize([5,5,intWidth,intHeight+1]);
      }
      fileURL = '';
      
      //Draw buttons according to type
      switch(param.l_type) {
         case "MB_YESNO":
            pushbutton([intPaintRow,intPaintCol], "@01@Yes", "/12",{"eventid":"YES", "size":[2,20]});
            pushbutton([intPaintRow,25], "@02@No", "/12",{"eventid":"NO", "size":[2,20]});
            break;
            
         case "MB_OKCANCEL":
            pushbutton([intPaintRow,intPaintCol], "@01@OK", "/12",{"eventid":"OK", "size":[2,20]});
            pushbutton([intPaintRow,25], "@02@Cancel", "/12",{"eventid":"CANCEL", "size":[2,20]});
            break;
            
         case "MB_OK":
            pushbutton([intPaintRow+viewHeight,intPaintCol], "@01@OK", "/12",{"eventid":"OK", "size":[2,20]});
            break;
            
         default:
            pushbutton([intPaintRow,intPaintCol], "OK", "/12",{"eventid":"OK", "size":[2,20]});
            break;
      }
}


function openURLviaServer(){
   //Set the path to where the html file can be created
   Z_PATH_LINK = "C:\\LiquidUI\\Scripts\\";
   
   onscreen "SAPLSMTR_NAVIGATION.0100"
      lFile = [];
      lLink = 'X';
      lName = 'LiquidUI_Web_Link_';
      set("V[tmpLink]","https://www.liquid-ui.com/");      //Set the link (URL) you want to open
      lFile.push([tmpLink,'LiquidUI_Web_Link']);
      reenter({'process':I_INITIAL_SCREEN_INFORMATION,'using':{'l_filename':lFile,'l_name':lName,'l_link':lLink}});
}


function I_INITIAL_SCREEN_INFORMATION(param){
   // SAP Easy Access
   enter('?');
   onscreen '*'
      var arrFiles = param.l_filename;
      var arrf1N = [];
      set('V[t1]',param.l_filename);
      
      set("V[t2]", 'Link');
      set("V[f1N]", '&V[Z_PATH_LINK]&V[t1]');
      for(var i=0;i<arrFiles.length;i++) {
         if(param.l_link == 'X') {
            set("V[f1N]", arrFiles[0]);
         } else {
            if(isBlank(param.l_type)) {
               set("V[f1N]", '&V[Z_PATH_LINK]'+arrFiles[0]);
            } else if(param.l_type == 'MACRO') {
               set("V[f1N]", '&V[Z_PATH_MACRO]'+arrFiles[0]);
            }
         }
         arrf1N.push([f1N,arrFiles[1]]);
      }
      fileURLName = param.l_name;
      fileURL = generateDynamicViewFileLinkV2(arrf1N,fileURLName+'VIEW.htm',param.l_link);
      
      title('Opening &V[t2] Please Wait...');
      strType = "MB_OK";
      strTitle = "View Link";
      aryMessage = [];
      aryMessage.push("Click to Open Link");
      reenter({"process":procLUIMessageBox, "using":{"l_type":strType, "l_title":strTitle, "l_message":aryMessage,'l_viewheight':arrFiles.length}});   
}


function generateDynamicViewFileLinkV2(arrInpFile,viewSuffix,strLink) {
   var fileName = Z_PATH_LINK+viewSuffix;
   removefile(fileName);
   var textString = "<html><head><body bgcolor='#FFFFFF'>";
   copytext({'tofile':'&V[fileName]','fromstring':'textString','appendline':true});

   for(var i=0;i<arrInpFile.length;i++) {
      if(strLink == 'X') {
         var textString1 = "<a href=\"";
      } else {
         var textString1 = "<a href=\"file:///";
      }
      var textString2 = arrInpFile[0];
      if(strLink == 'X') {
         var textString3 = "\" target=\"_blank\"><B><I><U>"+arrInpFile[1]+"</U></I></B>[/url]</BR>";
      } else {
         if(arrInpFile[0].toString().indexOf('.')>-1) {
            var textString3 = "\"><B><I><U>"+arrInpFile[1]+"</U></I></B>[/url]</BR>";
         } else {
            var textString3 = "\" target=\"_explorer.exe\"><B><I><U>"+arrInpFile[1]+"</U></I></B>[/url]</BR>";
         }
      }
      var textString = textString1+textString2+textString3;
      copytext({'tofile':'&V[fileName]','fromstring':'textString','appendline':true});
   }
   var textString = "</body></head></html>";
   copytext({'tofile':'&V[fileName]','fromstring':'textString','appendline':true});
   closefile(fileName)
   return fileName;
}


See attachments for code samples!
« Last Edit: October 02, 2023, 12:14:56 PM by Benjamin Dasari »