
// ￼?uri=sc:sm:appMake￼
Components.utils.import("chrome://scenariCommons/content/commons/actions.jsm");
Components.utils.import("chrome://scenariWsp/content/commons/servers.jsm");



var actionAddLocalWsp = new actions.Action("actionAddLocalWsp").setGroup("adminWsp").setLabel("￼Ajouter un atelier local￼").setIcon("chrome://scenariWsp/content/views/serversView/ico16/addWsp.png");
actionAddLocalWsp.execute = function(pEvent, pContext){
	var vServers = servers.getRegistry().findServers(function(pServer){
		return pServer.getId()=="emdFix";
	});
	var vLaunchContext = {
	    scServer : vServers[0],
	    callbackOnCreate : function(pOk) {
			if(pOk) {
				var vSrvControler = pContext.window.desk.getController("EmbeddedServersViewController");
				if(vSrvControler) vSrvControler.showServer(vServers[0]);
			}
		},
		thisForCbOnCreate : this
    };
	extPoints.getSvc("wspCreator").createWsp(pContext.window, vLaunchContext);
};
actionAddLocalWsp.isVisible = function(pContext){
	var vServers = servers.getRegistry().findServers(function(pServer){
		return pServer.getId()=="emdFix";
	});
	return vServers.length>0;
};
actionAddLocalWsp.findDisplayScore = function(pContext, pCb, pCbThis){

	var vServers = servers.getRegistry().findServers(function(pServer){
		return pServer.getId()=="emdFix";
	});
	var vAction = this;
	if(!this._LastScore && vServers.length>0){
		function cbLoadWspList(pEvent){
			try{
				if(pEvent.target.status == 200){
					var vWspListXml = pEvent.target.responseXML;
					vAction._LastScore = (vWspListXml && vWspListXml.documentElement.getElementsByTagName("wsp").length>0) ? -1 : 100;
				}
			} catch(e){
				log.debug(e);
			}finally{
				if(pCb) pCb.call(pCbThis, vAction._LastScore || 0);
			}
		}
		vServers[0].getDataProvider().loadFromService("/u/adminWsp?cdaction=List", cbLoadWspList);
	}else{
		if(pCb) pCb.call(pCbThis, this._LastScore || -1);
	}
};
extPoints.registerSvcByInst("actionAddLocalWsp", 21, actionAddLocalWsp);
extPoints.addSvcToList("tools:homeDesk:app", "actionAddLocalWsp", 11, "actionAddLocalWsp", 1);


var actionInstallPack = new actions.Action("actionInstallPack").setGroup("adminWsp").setLabel("￼Installer un modèle documentaire￼").setIcon("chrome://scenariWsp/content/views/serversView/ico16/install.png");
actionInstallPack.execute = function(pEvent, pContext){
	var vServers = servers.getRegistry().findServers(function(pServer){
		return pServer.getId()=="emdFix";
	});
	var vLaunchContext = {
	    scServer : vServers[0]
    };
	extPoints.getSvc("packManager").adminPack(pContext.window, vLaunchContext);
};
actionInstallPack.isVisible = function(pContext){
	var vServers = servers.getRegistry().findServers(function(pServer){
		return pServer.getId()=="emdFix";
	});
	return vServers.length>0;
};
actionInstallPack.findDisplayScore = function(pContext, pCb, pCbThis){

	var vServers = servers.getRegistry().findServers(function(pServer){
		return pServer.getId()=="emdFix";
	});
	var vAction = this;
	if(!this._LastScore && vServers.length>0){
		function cbLoadListPacks(pEvent){
			try{
				if(pEvent.target.status == 200){
					var vListPacks = pEvent.target.responseText;
					if(vListPacks) vAction._LastScore = JSON.parse(vListPacks).length>0 ? -1 : 110;
				}
			} catch(e){
				log.debug(e);
			}finally{
				if(pCb) pCb.call(pCbThis, vAction._LastScore || 0);
			}
		}
		vServers[0].getDataProvider().loadFromService("/u/adminPack?cdaction=ListPacks", cbLoadListPacks);
	}else{
		if(pCb) pCb.call(pCbThis, this._LastScore || -1);
	}
};
extPoints.registerSvcByInst("actionInstallPack", 21, actionInstallPack);
extPoints.addSvcToList("tools:homeDesk:app", "actionInstallPack", 11, "actionInstallPack", 1);
// ￼￼
