viewLoad question

Hi,

viewLoad doesn’t work properly with any .js files which have IncludeJavaScript() calls . Is there any way to include other .js files in .js?

thanks!
steven

What is “IncludeJavaScript()”?

Let me restate my question:

what is the alternative to call

<script language=“JavaScript” type=“text/javascript” src=“events.js”></script>

in .js, which works with viewLoad?

Hi xwang,

ViewLoader is a thin wrapper around rpcRequest.evalResult, which you could use directly. There is also the FileLoader.loadJSFiles() API, which can load multiple JS files and give you a callback when all have been loaded.

However, at a high level:

  1. if you are trying to use ViewLoader every time you are showing some new UI component, you’re using the wrong architecture, as indicated by the docs for ViewLoader. Read the top-level SmartClient Architecture topic for an overview.

  2. if you are trying to load an entire application module - that is, a large number of related screens and a set of custom SmartClient components that support them - then the FileLoader.loadJSFiles() API is the right approach.

It is a view (complete UI, rather than a component) which needs some supporting functions saved in different files. Those supporting functions are only used by the view. Here are two questions:

  1. the following code doesn’t work if FileLoader.LoadJSFile is called. Removing it, the codes works. What is wrong in the way to use loadJSFiles.
  2. if “event.js” gets loaded two times, what might be problem?
    thanks!
FileLoader.loadJSFiles(["events.js", "editor.js"]);

isc.DynamicForm.create({
	ID:"edit",
	useAllDataSourceFields:false,
	fields:[
		{name:"ID", title: "ID", type:"text"},
		{name:"StartTime", title: "Start Time",rowSpan:2, useTextField:true,type:"date", startRow: true},
		{name:"Status", title: "Status",type:"text",startRow: true},
		{name:"Description", rowSpan:3, colSpan:4, type:"textArea", width:300, startRow: true},
		{name:"savebtn", editorType:"button", align:"center", 
            width:100, colSpan:4, title:"Save Item", click:"editSchedule.saveData()"}
	],
	width:300,
	numCols:7,
	colWidths:[50,100,50,100,100,100],
    margin:25,
	cellPadding:5,
	autoFocus:false
});
<html>

<head>
<script>
var isomorphicDir='/isomorphic/';
</script>

<SCRIPT SRC=/isomorphic/system/modules/ISC_Core.js></SCRIPT>
<SCRIPT SRC=/isomorphic/system/modules/ISC_Foundation.js></SCRIPT>
<SCRIPT SRC=/isomorphic/system/modules/ISC_Containers.js></SCRIPT>
<SCRIPT SRC=/isomorphic/system/modules/ISC_Grids.js></SCRIPT>
<SCRIPT SRC=/isomorphic/system/modules/ISC_Forms.js></SCRIPT>
<SCRIPT SRC=/isomorphic/system/modules/ISC_DataBinding.js></SCRIPT>
<SCRIPT SRC=isomorphic/system/modules/ISC_FileLoader.js></SCRIPT>
<SCRIPT SRC=/isomorphic/skins/SmartClient/load_skin.js></SCRIPT>

</head>
<body>
<script>

isc.Window.create({
    width:500,height:500,
    autoDraw:false,
    ID:"TEST",
    title:"TEST",
    headerIconProperties:{src:"foo.gif"},
    canDragResize:true,
    showMinimizeButton:false,
    dragAppearance:"outline",
    autoSize:false,
    items: [
          isc.ViewLoader.create({
            autoDraw:false,
            viewURL: "sample.js",
            loadingMessage:"Loading view.."
          })]
});

TEST.show();

</script>
</body>
</html>
  1. is isc.FileLoader actually loading properly? Your SCRIPT include differs for it (no leading slash)

  2. typically, autoDraw. But you aren’t showing example code for that, right? (since you said it’s not working as written)

it is working codes. Commented out LoadJSFile…, it is successful loading.

put LoadJSFile back, it fails to load.

Then we would suggest troubleshooting that. There are many, many basic steps to take and many obvious things to report in order to allow people to help you - see the Debugging topic.

sorry, my mistake.

However, the explanation in viewLoader is really hard to understand.

I got file loaded; use a callback to display the view. However the UI is not displayed in the window which loads the view; instead it goes to the browser background. Reading this section of doc “the special variable “viewLoader” is available to refer to the ViewLoader instance that is loading components. The intended usage is that the returned script creates a view consisting of SmartClient components, then calls viewLoader.setView(myView) to place the loaded view into the ViewLoader. If the view does not call setView() explicitly”

I guess that I need call viewLoader.setView in the callback. But I am not sure where/when ‘myView’ could be passed to the loaded .js. One possible way is from callback. How to get the current view pointer?

thanks!

You call setView() from within the code of the view itself. However as that documentation goes on to explain, this is usually not necessary.

Taking a step back - have you reviewed the documentation on the SmartClient architecture? Is there some definite reason you are not loading these JS files up front, and choosing this more complicated route? Using the techniques described in the SmartClient Architecture document, there is no performance impact to loading the views up front other than actual bytes transferred, which is in turn almost negligible given HTTP compression.

Read architecture doc before; just read it again. I think we have valid reasons to use FileLoader. Here are two major reasons:

  1. usage model
    The application that we work on has many functional independent modules. Users only use some of them; it is configurable for user to choose.

2 development model
Some scripts will get quite long if putting everything into one file; some of supporting functions are saved into separate files. functions are developed by different developers.

due to reason-1, we need viewLoader;
due to reason-2, we need FileLoader;

do you have other suggestions?

thanks!

The SmartClient architecture does not suggest putting everything in one file (that’s pretty funny). It suggests loading code up front unless the code itself is prohibitively large in terms of bandwidth usage.

Even with functionally independent models, again, it makes sense to do up front loading unless the total size of the code for the module exceeds, for example, 20k compressed and it is unusual for the user to load that module. For perspective, 20k is larger than the entirety of the TabSet, Window and Dialog SmartClient classes - 20k of code would indicate dozens of screens worth of application functionality.

As far as loading new application modules, ViewLoader is not necessarily the right approach. Consider that there may be more than one way of causing a module to be loaded, and you probably want to avoid duplicate loads - it makes more sense to have a function that is called from any place in the UI that causes a module to be loaded, have this function check for duplicate loads, and have it achieve the module loading via a call to FileLoader.loadJSFiles().