All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javasimon.console.resource.js.javasimon-plugin.js Maven / Gradle / Ivy

There is a newer version: 4.2.0
Show newest version
(function(tns,domUtil) {
	"use strict";
	/**
	 * View plugin class
	 */
	tns.ViewPlugin=function(oPlugin) {
		this.resourceCount=0;
		this.state="NEW";
		this.id=oPlugin.id;
		this.resources=oPlugin.resources;
	};
	tns.ViewPlugin.prototype={
		/**
		 * Add JS and CSS resources to page header
		 */
		loadResources:function(){
			var oResource, sResourcePath, eResource, self=this, 
				resourceNb=this.resources.length, i,
				fnOnLoad=function(data, textStatus, jqxhr) {
					self.resourceCount--;
					self.onLoaded(); 
				};
			this.state="LOADING";
			if (resourceNb>0) {
				for(i=0;i", {
                                rel: "stylesheet",
                                type: "text/css",
                                href: sResourcePath
                            }).appendTo("head");
							break;
					}
				}
			} else {					
				this.onLoaded(); // No resource to load
			}
		},
		/**
		 * Inject plugin data
		 */
		setData:function(oView, eTableBody, oData) {
			this.data=oData;
			this.view=oView;
			this.tableBody=eTableBody;
			this.onLoaded();
		},
		/**
		 * When all resources and data is loaded try to render
		 */
		onLoaded:function() {
			if (this.resourceCount<=0 && this.data && this.state==="LOADING") {
				this.state="LOADED";
				this.onRender();
			}
		},
		/**
		 * Inject rendering function (call by plugin itself once JS is loaded),
		 * and then try to render
		 */
		setRenderer:function(fnRenderer) {
			this.fnRenderer=fnRenderer;
			this.onRender();
		},
		/**
		 * When JS is loaded, data and rendering function where injected
		 * then run rendering
		 */
		onRender:function() {
			if (this.fnRenderer && this.state==="LOADED") {
				this.fnRenderer.call(this.view, this.tableBody, this.data);
				this.state="RENDERED";
			}
		}
	};
	/**
	 * Detail view plugin manager
	 */
	tns.ViewPluginManager={
		/**
		 * Plugins indexed by id
		 */
		plugins:{},
		/**
		 * URL of the PluginsJsonAction
		 */
		sUrl:"data/plugins.json",
		/**
		 * Load via an Ajax call the list of plugins
		 */
		fnLoadPlugins:function(sType, fnCallback) {
			var self=this, 
				fnAjaxCallback=function(aoPlugins){
					for(var i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy