Difference between revisions of "Static Resources"

From AgileApps Support Wiki
imported>Aeric
Β 
imported>Aeric
Β 
(79 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''[[File:GearIcon.png]] > Customization > Developer Resources > Static Resources'''
Static resources are external files that can be uploaded and used in JSP [[Pages]].
==About Static Resources==
In a web application, programmers need to refer to resources such as static images, stylesheets and external JavaScripts to build powerful applications. This functionality allows developers and designers to package and upload the following resources and invoke them programmatically in [[Pages]]:
In a web application, programmers need to refer to resources such as static images, stylesheets and external JavaScripts to build powerful applications. This functionality allows developers and designers to package and upload the following resources and invoke them programmatically in [[Pages]]:
*Images (.gif, .jpg, etc.)
:*Images (.gif, .jpg, etc.)
*Stylesheets (.css)
:*Stylesheets (.css)
*JavaScript files (.js)
:*JavaScript files (.js)
*Compressed files (.zip, .tar)
:*Compressed files (.zip, .tar)


==How it Works==
===How it Works===
Add Static Resource files to the platform, which can then be used to build [[Pages]].
Add Static Resource files to the platform, which can then be used to build [[Pages]].


Detailed instructions are provided here to Add, View, Edit, Replace or Delete Static Resources. See [[#Usage|Usage]] for sample HTML code you can copy and use to apply these resources.
Detailed instructions are provided here to Add, View, Edit, Replace or Delete Static Resources. See [[#Usage|Usage]] for sample HTML code you can copy and use to apply these resources.


===Resource Attributes===
==Working with Static Resources==
Β 
===View Static Resources===
#Click '''[[File:GearIcon.png]] > Customization > Developer Resources > Static Resources'''
{{SearchFilterView|Static Resources}}
# The following columns are displayed in the view:
:;Name:Name of the resource, used by developers to reference this resource in a page
:;Name:Name of the resource, used by developers to reference this resource in a page
::Name must contain only alphanumeric characters and underscores: <tt>(a-z, A-Z, 0-9 and "_")</tt>
::Name can contain only alphanumeric characters and underscores: <tt>(a-z, A-Z, 0-9, and "_")</tt>
:;Description: Description of the resource
:;Description: Description of the resource
:;File Size: Size of the resource
:;File Size: Size of the resource
Line 20: Line 30:


===Add a Static Resource File===
===Add a Static Resource File===
#Click '''Designer > Logic > Static Resources'''
#Click '''[[File:GearIcon.png]] > Customization > Developer Resources > Static Resources'''
#Click the [New Resource] button to add a new resource. Complete the following information for each resource that is added:
#Click the '''[New Resource]''' button to add a new resource. Complete the following information for each resource that is added:
#:;Name:Name of the resource
#:;Name:Name of the resource
#:;File:Click the [Browse] button to navigate to the file
#:;File:Click the '''[Browse]''' button to navigate to the file
#:;Description: Enter a simple description of the file
#:;Description: Enter a simple description of the file
#Click '''[Save]'''
#Click '''[Save]'''
Line 29: Line 39:
#:;File Size: Size of the resource
#:;File Size: Size of the resource
#:;MIME Type: The type of the resource
#:;MIME Type: The type of the resource
{{Note|If the {{^MIME}} type is incorrect for the resource, the file may not be handled properly when sent to a user's browser. In that case, the platform must be configured to recognize it.<br>''Learn more:'' [[Adding MIME Types]]}}


===View, Edit, Replace or Delete a Static Resource File ===
===View, Edit, Replace or Delete a Static Resource File ===
#Click '''Designer > Logic > Static Resources'''
#Click '''[[File:GearIcon.png]] > Customization > Developer Resources > Static Resources'''
#Click the name of the resource
#Click the name of the resource
#Choose from any of the following:
#Choose from any of the following:
Line 37: Line 48:
#;Replace:Replace the resource (load a new resource in place of the current resource)
#;Replace:Replace the resource (load a new resource in place of the current resource)
#;Delete:Delete the resource
#;Delete:Delete the resource
#;Back:Cancel the operation and return to the resource list


==Usage==
==Accessing a JavaScript Resource from an Object Form==
Use the custom tag library in [[Pages]] to invoke a static resource file.


Note that the following code is required, and is used to include this library in custom pages:
It is possible to use JavaScript resource in an Object form.<br>
{{Note|For more information about API related permissions, see [[REST API:staticResource Resource]].}}
To do so:
# Upload the JavaScript file as a static resource.
#:
# In your browser, use the REST Static Resource API to list the available resources:
#: https://{yourDomain}/networking/rest/staticResource
#:
# Copy the resource ID for the JavaScript file (a long string of numbers and letters):
#:<tt><platform>
#::<staticResource>
#:::<id></tt><font style="background-color:yellow"><tt>{resourceID}</tt></font><tt></id>
#:::<name>HelpButton_js</name>
#:::<resource_file_name>HelpButton.js</resource_file_name>
#:::...</tt>
#:
# Put the following code into your [[Form Script]] or [[Field Script]], and insert the resource ID:
#:<tt><nowiki>$.get("https://{yourDomain}/networking/rest/staticResource/</nowiki></tt><font style="background-color:yellow"><tt>{resourceID}</tt></font><tt>?getFile=true",
#: function( data ) {
#:: eval(data);
#:: yourFunction();
#:});</tt>


<%@ taglib uri="/WEB-INF/tlds/StaticResources.tld" prefix="statres" %>
That code uses the REST API to get the contents of the file in the <tt>data</tt> string. That string is passed to an anonymous function that does an <tt>eval</tt> to make function definitions in the file available to the current script. Finally, the code calls the function defined in the file.


===Image===
{{Important|<br>When you have a new version of the JavaScript file to upload, go to the existing static resource and click '''[Replace]'''.<br>That operation preserves the record ID, so references to the file get the updated version.}}
<syntaxhighlight lang="html4strict" enclose="div">
<%@ taglib uri="/WEB-INF/tlds/StaticResources.tld" prefix="statres" %>
<html>
<head></head>
<body>
<img src='<statres:resource name="Autumn_Leaves"/>'/>
</body>
</html>
</syntaxhighlight>


===StyleSheet===
<syntaxhighlight lang="html4strict" enclose="div">
<%@ taglib uri="/WEB-INF/tlds/StaticResources.tld" prefix="statres" %>
<html>
<head></head>
<link href='<statres:resource name="fixedstylesheet"/>' rel="stylesheet" type="text/css">
<body>
<span class="DarkText">Helloooooooooooo</span>
</body>
</html>
</syntaxhighlight>


===External Java Script===
==Accessing Static Resources in a JSP Page==
<syntaxhighlight lang="html4strict" enclose="div">
The examples below use the custom tag library in [[Pages]] to access static resource files. The examples assume that the "Acme" company is building the application.
<%@ taglib uri="/WEB-INF/tlds/StaticResources.tld" prefix="statres" %>
<html>
<head></head>
<script src='<statres:resource name="functions"/>'</script>
<script>
Β  Β  Β  function callFunction()
Β  Β  Β  {
Β  Β  Β  Β  Β  alert((document.mainform.input.value).length);
Β  Β  Β  Β  Β  alert(trim(document.mainform.input.value).length)Β  Β  ;
Β  Β  Β  }
</script>
<body>
<form name='mainform'>
<input type='text' name='input'/>
<input type='button' onclick='javascript:callFunction();'/>
</form>
</body>
</html>
</syntaxhighlight>


===Compressed Files===
Note that the following code is required, and is used to include this library in custom pages:
In this example, the compressed file contains all the files above, including additional resource files. The 'path' parameter must be specified in the tag if the resources are bundled in .zip/.tar, so the path is used to distinguish the actual name of the resource.
:<syntaxhighlight lang="java" enclose="div">
Β 
<%@ taglib prefix="sr" uri="/staticresources" %> Β 
<syntaxhighlight lang="html4strict" enclose="div">
<%@ taglib uri="/WEB-INF/tlds/StaticResources.tld" prefix="statres" %>
<html>
<head></head>
<link href='<statres:resource name="reszip" path="fixedstyle.css"/>' rel="stylesheet" type="text/css">
<script src='<statres:resource name="functions"/>'</script>
<script>
Β  Β  Β  function callFunction()
Β  Β  Β  {
Β  Β  Β  Β  Β  alert((document.mainform.inp.value).length);
Β  Β  Β  Β  Β  alert(trim(document.mainform.inp.value).length)Β  Β  ;
Β  Β  Β  }
</script>
<body>
<span class="DarkText">Helloooooooooooo</span>
<img src='<statres:resource name="reszip" path="image1.gif"/>'/>
<img src='<statres:resource name="reszip" path="/img/image2.gif"/>'/>
<form name='mainform'>
<input type='text' name='inp'/>
<input type='button' onclick='javascript:callFunction();'/>
</form>
</body>
</html>
</syntaxhighlight>
</syntaxhighlight>


==Global Resources==
===Image===
Static Resources, when created by [[Service Provider]]s, are called Global Resources.
Here, the resource has been loaded under the name "Autumn_Leaves". The actual file might be <tt>falling_leaves.jpg</tt> or <tt>autumn_colors.gif</tt>, but the resource name is sufficient to access it.
Β 
:<syntaxhighlight lang="java" enclose="div">
{{#if: {{ShowIsvInfo}} {{ShowMspInfo}} |
<%@ taglib prefix="sr" uri="/staticresources" %>
===How to Do It===
Resources can be uploaded in ISV tenant or MSP tenant, and can be used in Pages.
:''Learn more: [[Static_Resources#How_it_Works|How it Works]]
}}
Β 
===Usage===
Use the custom tag library in [[Pages]] to invoke a static resource file.
Β 
Β  Β  Β  Β 
====Image====
<syntaxhighlight lang="html4strict" enclose="div">
<%@ taglib uri="/LJTagLib" prefix="lj" %>
<html>
<html>
<head></head>
<head>
</head>
<body>
<body>
<img src='<lj:resource namespace="leapfrog" name="Autumn_Leaves"/>' />
Β  Β  <img src='<sr:resource name="Autumn_Leaves"/>'/>
</body>
</body>
</html>
</html>
</syntaxhighlight>
</syntaxhighlight>
Β  Β 
Β 
====StyleSheet====
===StyleSheet===
<syntaxhighlight lang="html4strict" enclose="div">
In this example, a CSS stylesheet was uploaded under the name "AcmeStyles". The <tt>FormHeader</tt> style it defines is then used in the body of the page.
<%@ taglib uri="/LJTagLib" prefix="lj" %>
:<syntaxhighlight lang="java" enclose="div">
<%@ taglib prefix="sr" uri="/staticresources" %>
<html>
<html>
<head></head>
<head>
<link href='<lj:resource namespace="leapfrog"/>' rel="stylesheet" type="text/css">
Β  Β  <link href='<sr:resource name="AcmeStyles"/>' rel="stylesheet" type="text/css" />
</head>
<body>
<body>
<span class="DarkText">Helloooooooooooo</span>
Β  Β  <span class="FormHeader">Place Your Order:</span>
</body>
</body>
</html>
</html>
</syntaxhighlight>
</syntaxhighlight>


====External Java Script====
===External Java Script===
<syntaxhighlight lang="html4strict" enclose="div">
In this example, a JavaScript file was uploaded under the name "functions". This example calls the <tt>verifyOrder</tt> function it contains.
<%@ taglib uri="/LJTagLib" prefix="lj" %>
:<syntaxhighlight lang="java" enclose="div">
<%@ taglib prefix="sr" uri="/staticresources" %>
<html>
<html>
<head></head>
<head>
<script src='<lj:resource namespace="leapfrog" name="functions"/>'</script>
Β  Β  <script src='<sr:resource name="functions"/>'></script>
<script>
</head>
function callFunction()
{
Β  Β  Β  Β  alert((document.mainform.input.value).length);
Β  Β  Β  Β  alert(trim(document.mainform.input.value).length);
Β  Β  }
</script>
<body>
<body>
<form name='mainform'>
Β  Β  <form name='mainform'>
<input type='text' name='input'/>
Β  Β  Β  Β  <input type='text' name='input' />
<input type='button' onclick='javascript:callFunction();'/>
Β  Β  Β  Β  <input type='button' onclick='javascript:verifyOrder();' />
</form>
Β  Β  </form>
</body>
</body>
</html>
</html>
</syntaxhighlight>
</syntaxhighlight>


====Compressed Files====
===Compressed Files===
In this example, the compressed file contains all the files above, including additional resource files. The 'path' parameter must be specified in the tag if the resources are bundled in .zip/.tar, so the path is used to distinguish the actual name of the resource.
In this example, an archive file (<tt>.zip</tt>, <tt>.tar</tt>, or <tt>.jar</tt>) containing all the files above was uploaded under the name "AcmeResources". The 'path' parameter must be specified in that case, to identify the file contained in that resource.


<syntaxhighlight lang="html4strict" enclose="div">
:<syntaxhighlight lang="java" enclose="div">
<%@ taglib uri="/LJTagLib" prefix="lj" %>
<%@ taglib prefix="sr" uri="/staticresources" %>
<html>
<html>
<head></head>
<head>
<link href='<lj:resource namespace="leapfrog" name="reszip" path="fixedstyle.css"/>' rel="stylesheet" type="text/css">
Β  Β  <link href='<sr:resource name="AcmeResources" path="acmestyles.css"/>' Β 
<script src='<lj:resource namespace="leapfrog" name="functions"/>'</script>
Β  Β  Β  Β  Β  rel="stylesheet" type="text/css" />
<script>
Β  Β  <script src='<sr:resource name="functions"/>'></script>
function callFunction()
</head>
{
alert((document.mainform.inp.value).length);
alert(trim(document.mainform.inp.value).length)Β  Β  ;
}
</script>
<body>
<body>
<span class="DarkText">Helloooooooooooo</span>
Β  Β  <span class="FormHeader">Place Your Order:</span>
<img src='<lj:resource namespace="leapfrog" name="reszip" path="image1.gif"/>'/>
Β  Β  <img src='<sr:resource name="AcmeResources" path="image1.gif"/>'/>
<img src='<lj:resource namespace="leapfrog" name="reszip" path="/img/image2.gif"/>'/>
Β  Β  <img src='<sr:resource name="AcmeResources" path="/img/image2.gif"/>'/>
<form name='mainform'>
Β  Β  <form name='mainform'>
<input type='text' name='inp'/>
Β  Β  Β  Β  <input type='text' name='inp'/>
<input type='button' onclick='javascript:callFunction();'/>
Β  Β  Β  Β  <input type='button' onclick='javascript:verifyOrder();'/>
</form>
Β  Β  </form>
</body>
</body>
</html>
</html>
Line 206: Line 155:




<noinclude>[[Category:Develop| 60]]</noinclude>
[[Category:Logic| 5]]
</noinclude>

Latest revision as of 08:52, 28 August 2020

GearIcon.png > Customization > Developer Resources > Static Resources

Static resources are external files that can be uploaded and used in JSP Pages.

About Static Resources

In a web application, programmers need to refer to resources such as static images, stylesheets and external JavaScripts to build powerful applications. This functionality allows developers and designers to package and upload the following resources and invoke them programmatically in Pages:

  • Images (.gif, .jpg, etc.)
  • Stylesheets (.css)
  • JavaScript files (.js)
  • Compressed files (.zip, .tar)

How it Works

Add Static Resource files to the platform, which can then be used to build Pages.

Detailed instructions are provided here to Add, View, Edit, Replace or Delete Static Resources. See Usage for sample HTML code you can copy and use to apply these resources.

Working with Static Resources

View Static Resources

  1. Click GearIcon.png > Customization > Developer Resources > Static Resources
    Static Resources are displayed in a View.
  2. Use standard Searching and Filtering operations to determine which records are displayed.
  3. The following columns are displayed in the view:
Name
Name of the resource, used by developers to reference this resource in a page
Name can contain only alphanumeric characters and underscores: (a-z, A-Z, 0-9, and "_")
Description
Description of the resource
File Size
Size of the resource
Displayed after a resource is loaded
MIME Type
Type of the resource (GIF, PDF, JPG, CSS, etc.)
Displayed after a resource is loaded

Add a Static Resource File

  1. Click GearIcon.png > Customization > Developer Resources > Static Resources
  2. Click the [New Resource] button to add a new resource. Complete the following information for each resource that is added:
    Name
    Name of the resource
    File
    Click the [Browse] button to navigate to the file
    Description
    Enter a simple description of the file
  3. Click [Save]
    The following information is displayed as a record of the upload:
    File Size
    Size of the resource
    MIME Type
    The type of the resource

Notepad.png

Note: If the MIME type is incorrect for the resource, the file may not be handled properly when sent to a user's browser. In that case, the platform must be configured to recognize it.
Learn more: Adding MIME Types

View, Edit, Replace or Delete a Static Resource File

  1. Click GearIcon.png > Customization > Developer Resources > Static Resources
  2. Click the name of the resource
  3. Choose from any of the following:
    Edit
    Edit the Name or Description of the resource
    Replace
    Replace the resource (load a new resource in place of the current resource)
    Delete
    Delete the resource

Accessing a JavaScript Resource from an Object Form

It is possible to use JavaScript resource in an Object form.

Notepad.png

Note: For more information about API related permissions, see REST API:staticResource Resource.

To do so:

  1. Upload the JavaScript file as a static resource.
  2. In your browser, use the REST Static Resource API to list the available resources:
    https://{yourDomain}/networking/rest/staticResource
  3. Copy the resource ID for the JavaScript file (a long string of numbers and letters):
    <platform>
    <staticResource>
    <id>{resourceID}</id>
    <name>HelpButton_js</name>
    <resource_file_name>HelpButton.js</resource_file_name>
    ...
  4. Put the following code into your Form Script or Field Script, and insert the resource ID:
    $.get("https://{yourDomain}/networking/rest/staticResource/{resourceID}?getFile=true",
    function( data ) {
    eval(data);
    yourFunction();
    });

That code uses the REST API to get the contents of the file in the data string. That string is passed to an anonymous function that does an eval to make function definitions in the file available to the current script. Finally, the code calls the function defined in the file.

Warn.png

Important:
When you have a new version of the JavaScript file to upload, go to the existing static resource and click [Replace].
That operation preserves the record ID, so references to the file get the updated version.


Accessing Static Resources in a JSP Page

The examples below use the custom tag library in Pages to access static resource files. The examples assume that the "Acme" company is building the application.

Note that the following code is required, and is used to include this library in custom pages:

<syntaxhighlight lang="java" enclose="div">

<%@ taglib prefix="sr" uri="/staticresources" %> </syntaxhighlight>

Image

Here, the resource has been loaded under the name "Autumn_Leaves". The actual file might be falling_leaves.jpg or autumn_colors.gif, but the resource name is sufficient to access it.

<syntaxhighlight lang="java" enclose="div">

<%@ taglib prefix="sr" uri="/staticresources" %> <html> <head> </head> <body>

   <img src='<sr:resource name="Autumn_Leaves"/>'/>

</body> </html> </syntaxhighlight>

StyleSheet

In this example, a CSS stylesheet was uploaded under the name "AcmeStyles". The FormHeader style it defines is then used in the body of the page.

<syntaxhighlight lang="java" enclose="div">

<%@ taglib prefix="sr" uri="/staticresources" %> <html> <head>

   <link href='<sr:resource name="AcmeStyles"/>' rel="stylesheet" type="text/css" />

</head> <body>

   Place Your Order:

</body> </html> </syntaxhighlight>

External Java Script

In this example, a JavaScript file was uploaded under the name "functions". This example calls the verifyOrder function it contains.

<syntaxhighlight lang="java" enclose="div">

<%@ taglib prefix="sr" uri="/staticresources" %> <html> <head>

   <script src='<sr:resource name="functions"/>'></script>

</head> <body>

   <form name='mainform'>
       <input type='text' name='input' />
       <input type='button' onclick='javascript:verifyOrder();' />
   </form>

</body> </html> </syntaxhighlight>

Compressed Files

In this example, an archive file (.zip, .tar, or .jar) containing all the files above was uploaded under the name "AcmeResources". The 'path' parameter must be specified in that case, to identify the file contained in that resource.

<syntaxhighlight lang="java" enclose="div">

<%@ taglib prefix="sr" uri="/staticresources" %> <html> <head>

   <link href='<sr:resource name="AcmeResources" path="acmestyles.css"/>' 
         rel="stylesheet" type="text/css" />
   <script src='<sr:resource name="functions"/>'></script>

</head> <body>

   Place Your Order:
   <img src='<sr:resource name="AcmeResources" path="image1.gif"/>'/>
   <img src='<sr:resource name="AcmeResources" path="/img/image2.gif"/>'/>
   <form name='mainform'>
       <input type='text' name='inp'/>
       <input type='button' onclick='javascript:verifyOrder();'/>
   </form>

</body> </html> </syntaxhighlight>