01-17-2011 12:58 PM
//<import resource="classpath:/alfresco/site-webscripts/org/alfresco/callutils.js">
function main()
{
//args["site"];
var site = "Metrologie";
//var siteId = String(json.get("siteId"));
var siteId = page.url.templateArgs.site;
model.testee = siteId;
model.dataSites = [];
model.listTitles = [];
var listdata = getListforGraph(siteId);
model.listTitles = listdata;
var longueur = listdata.length;
var itemsdata = [];
var test = [];
//model.testsite = currentSite;
for (var i = 0, ii = listdata.length; i < ii; i++)
{
test = listdata[i];
itemsdata = getDataforGraph(siteId, test.names, test.titles, test.descriptions);
}
return itemsdata;
}
var getListforGraph = function(curresite)
{
var site, container, theUrl, connector, result, lists, types = [];
//sites = 'test';
//site = currentsites;
//var curresite = "Achats";
container = 'dataLists';
theUrl = "/slingshot/datalists/lists/site/" + curresite + "/" + container + "?page=1&pageSize=512";
connector = remote.connect("alfresco");
result = connector.get(theUrl);
if (result.status == 200)
{
model.ok = " ouiii";
var ss = eval("(" + result + ")");
try
{
for each (var s in ss.datalists)
{
if (s.itemType == "graph:graphList")
{
types.push(
{
names: s.name,
titles: s.title,
descriptions: s.description,
itemtypes: s.itemType
});
}
else
{
continue;
}
}
}
catch (e)
{
}
}
if (types.size != 0)
{
model.bug = "ouiiiii"
}
else
{
model.bug = "buggg"
}
return types;
}
var getDataforGraph = function(currsite, nameliste, titleliste, descliste)
{
var site, container, theUrla, connector, result, lists, listetitle, listedesc, liste, activity = [];
model.liste = [];
//site = 'test';
//site = page.url.templateArgs.site;
container = 'dataLists';
liste = nameliste;
listetitle = titleliste;
listedesc = descliste;
theUrla = '/slingshot/datalists/data/site/' + currsite + '/' + container + '/';
var myObj = { "fields" :[ "graph_graphDate",
"graph_graphValeur",
"graph_graphTendance",
"graph_graphObjectif"
],
"filter" :{ "filterData" : "",
"filterId" : "all"
}
};
var myObjAsString = jsonUtils.toJSONString(myObj);
var itemslist = [];
siteTitle = "";
var dataSites = new Array();
connector = remote.connect("alfresco");
theUrl = theUrla + liste;
model.url = theUrl;
result = connector.post(theUrl, myObjAsString, 'application/json');
// if (response.success !== undefined)
if (result.status == 200)
{
var i, ii;
// Create javascript objects from the server response
// Each item is a favourite site that the user is a member of
//var sites = eval('(' + result + ')'), site;
var response = eval('(' + result + ')'), data;
if (response.length != 0)
{
// Sort the sites by title
//sites.sort(sortByTitle);
for (i = 0, ii = response.items.length; i < ii; i++)
{
data = response.items[i];
//if (site.shortName == currentSite)
//{
// siteTitle = data.title;
//if (ignoreCurrentSite)
//{
// The current site was piggy-backing the query call; it's not a favourite
// continue;
//}
//currentSiteIsFav = true;
//var dt=new Date(data.itemData.prop_graph_graphDate.value);
//var mois=dt.getMonth();
var date = fromISO8601(data.itemData.prop_graph_graphDate.value);
dataSites.push(
{
sitename: site,
listename: liste,
listetitle: listetitle,
listedescription: listedesc,
tdate : date,
graphDate : data.itemData.prop_graph_graphDate.value,
graphValeur : data.itemData.prop_graph_graphValeur.value,
graphTendance : data.itemData.prop_graph_graphTendance.value,
graphObjectif : data.itemData.prop_graph_graphObjectif.value
});
}
}
}
return dataSites;
}
function fromISO8601(formattedString)
{
var isoRegExp = /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(.\d+)?)?((?:[+-](\d{2}):(\d{2}))|Z)?)?$/;
var match = isoRegExp.exec(formattedString);
var result = null;
if (match)
{
match.shift();
if (match[1]){match[1]–;} // Javascript Date months are 0-based
if (match[6]){match[6] *= 1000;} // Javascript Date expects fractional seconds as milliseconds
result = new Date(match[0]||1970, match[1]||0, match[2]||1, match[3]||0, match[4]||0, match[5]||0, match[6]||0);
var offset = 0;
var zoneSign = match[7] && match[7].charAt(0);
if (zoneSign != 'Z')
{
offset = ((match[8] || 0) * 60) + (Number(match[9]) || 0);
if (zoneSign != '-')
{
offset *= -1;
}
}
if (zoneSign)
{
offset -= result.getTimezoneOffset();
}
if (offset)
{
result.setTime(result.getTime() + offset * 60000);
}
}
return result; // Date or null
}
model.dataSites = main();
recherche en faite toutes les liste de données correspondant au type graph:graphList ( modèle conçu pour les graphique ) .
<#escape x as jsonUtils.encodeJSONString(x)>
{"datajson":[
<#list dataSites as match>
{
"date" : "${match.tdate?js_string}",
<#assign currentLocale=locale />
<#setting locale="en_US" />
"valeur" : "${match.graphValeur}",
"tendance" : "${match.graphTendance}"
<#setting locale=currentLocale />
}
<#if match_has_next>,</#if>
</#list>
]
}
</#escape>
me permettant je formatter le texte json et ainsi de le passé dans mon graphique.get.html.ftl que voici :
<script type="text/javascript">//<![CDATA[
new Alfresco.Graphique("${args.htmlid}").setOptions(
{
"site": "${page.url.templateArgs.site!""}"
});
new Alfresco.widget.DashletResizer("${args.htmlid}", "${instance.object.id}");
//]]></script>
<div class="dashlet graphique">
<div id="chart">Loading…</div>
</div>
<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
var healthtab = function() {
YAHOO.widget.Chart.SWFURL = "http://yui.yahooapis.com/2.8.2r1/build/charts/assets/charts.swf";
YAHOO.example.puppies = [
{ name: "Ashley", breed: "German Shepherd", age: 12.05 },
{ name: "Dirty Harry", breed: "Norwich Terrier", age: 5.20 },
{ name: "Emma", breed: "Labrador Retriever", age: 9.10 },
{ name: "Oscar", breed: "Yorkshire Terrier", age: 6 },
{ name: "Riley", breed: "Golden Retriever", age: 6 },
{ name: "Shannon", breed: "Greyhound", age: 12 },
{ name: "Washington" ,breed: "English Bulldog", age: 8 },
{ name: "Zoe", breed: "Labrador Retriever", age: 3 }
];
//— Ajax call
// var healthDataSource = new YAHOO.util.DataSource(YAHOO.example.puppies);
var healthDataSource = new YAHOO.util.XHRDataSource("/share/service/components/dashlets/graphique.json");
healthDataSource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
healthDataSource.responseSchema = {
resultsList:"datajson",
fields: ["date", "valeur", "tendance"]
};
var seriesDef = [
{ displayName: "Valeur", yField: "valeur" },
{ displayName: "Tendance", yField: "tendance" }
];
//— chart
var mychart = new YAHOO.widget.LineChart( "chart", healthDataSource,
{
xField: "date",
series: seriesDef
});
}();
});
</script>
{
"status" :
{
"code" : 500,
"name" : "Internal Error",
"description" : "An error inside the HTTP server which prevented it from fulfilling the request."
},
"message" : "00170031 Failed to execute script 'classpath*:alfresco\/site-webscripts\/org\/alfresco\/components\/graph\/graph.get.js': 00170030 ReferenceError: \"page\" n'est pas d\u00e9fini (file:\/C:\/Alfresco\/tomcat\/webapps\/share\/WEB-INF\/classes\/alfresco\/site-webscripts\/org\/alfresco\/components\/graph\/graph.get.js#9)",
"exception" : "org.springframework.extensions.webscripts.WebScriptException - 00170031 Failed to execute script 'classpath*:alfresco\/site-webscripts\/org\/alfresco\/components\/graph\/graph.get.js': 00170030 ReferenceError: \"page\" n'est pas d\u00e9fini (file:\/C:\/Alfresco\/tomcat\/webapps\/share\/WEB-INF\/classes\/alfresco\/site-webscripts\/org\/alfresco\/components\/graph\/graph.get.js#9)",
….
01-18-2011 02:45 AM
<family>site-dashlet</family>
Pourriez vous nous montrer le contenu du fichier graphique.get.desc.xml svp ?<script type="text/javascript">//<![CDATA[
new Alfresco.Graphique("${args.htmlid}").setOptions(
{
"site": "${page.url.templateArgs.site!""}"
});
new Alfresco.widget.DashletResizer("${args.htmlid}", "${instance.object.id}");
//]]></script>
<webscript>
<shortname>TEST</shortname>
<description>Dashlet de test</description>
<family>site-dashlet</family>
<url>/components/dashlets/test</url>
</webscript>
model.nomdusite = page.url.templateArgs.site;
<div class="dashlet">
<div class="title">TEST</div>
<div class="body">
${nomdusite}
</div>
</div>
01-18-2011 03:10 AM
var healthDataSource = new YAHOO.util.XHRDataSource("/share/service/components/dashlets/graphique.json");
new YAHOO.util.XHRDataSource("/share/service/components/url-vers-votre-ws/nom-du-webscript.json?siteId=${page.url.templateArgs.site}")
01-18-2011 03:17 AM
<webscript>
<shortname>Graphiques</shortname>
<description>Dashlet pour les Graphiques</description>
<family>site-dashlet</family>
<url>/components/dashlets/graphique</url>
</webscript>
il est bien défini en site-dashlet.01-18-2011 03:21 AM
01-18-2011 03:33 AM
<webscript>
<shortname>Graphiques</shortname>
<description>Dashlet pour les Graphiques</description>
<family>site-dashlet</family>
<url>/components/graph/getDataListData</url>
</webscript>
<#escape x as jsonUtils.encodeJSONString(x)>
{"datajson":[
<#list dataSites as match>
{
"date" : "${match.tdate?js_string}",
<#assign currentLocale=locale />
<#setting locale="en_US" />
"valeur" : "${match.graphValeur}",
"tendance" : "${match.graphTendance}"
<#setting locale=currentLocale />
}
<#if match_has_next>,</#if>
</#list>
]
}
</#escape>
//<import resource="classpath:/alfresco/site-webscripts/org/alfresco/callutils.js">
function main()
{
//args["site"];
var site = "Metrologie";
var siteId;
//var siteId = String(json.get("siteId"));
siteId = page.url.args.siteId;
model.testee = siteId;
model.dataSites = [];
model.listTitles = [];
var listdata = getListforGraph(siteId);
model.listTitles = listdata;
var longueur = listdata.length;
var itemsdata = [];
var test = [];
//model.testsite = currentSite;
for (var i = 0, ii = listdata.length; i < ii; i++)
{
test = listdata[i];
itemsdata = getDataforGraph(siteId, test.names, test.titles, test.descriptions);
}
return itemsdata;
}
var getListforGraph = function(curresite)
{
var site, container, theUrl, connector, result, lists, types = [];
//sites = 'test';
//site = currentsites;
//var curresite = "Achats";
container = 'dataLists';
theUrl = "/slingshot/datalists/lists/site/" + curresite + "/" + container + "?page=1&pageSize=512";
connector = remote.connect("alfresco");
result = connector.get(theUrl);
if (result.status == 200)
{
model.ok = " ouiii";
var ss = eval("(" + result + ")");
try
{
for each (var s in ss.datalists)
{
if (s.itemType == "graph:graphList")
{
types.push(
{
names: s.name,
titles: s.title,
descriptions: s.description,
itemtypes: s.itemType
});
}
else
{
continue;
}
}
}
catch (e)
{
}
}
if (types.size != 0)
{
model.bug = "ouiiiii"
}
else
{
model.bug = "buggg"
}
return types;
}
var getDataforGraph = function(currsite, nameliste, titleliste, descliste)
{
var site, container, theUrla, connector, result, lists, listetitle, listedesc, liste, activity = [];
model.liste = [];
//site = 'test';
//site = page.url.templateArgs.site;
container = 'dataLists';
liste = nameliste;
listetitle = titleliste;
listedesc = descliste;
theUrla = '/slingshot/datalists/data/site/' + currsite + '/' + container + '/';
var myObj = { "fields" :[ "graph_graphDate",
"graph_graphValeur",
"graph_graphTendance",
"graph_graphObjectif"
],
"filter" :{ "filterData" : "",
"filterId" : "all"
}
};
var myObjAsString = jsonUtils.toJSONString(myObj);
var itemslist = [];
siteTitle = "";
var dataSites = new Array();
connector = remote.connect("alfresco");
theUrl = theUrla + liste;
model.url = theUrl;
result = connector.post(theUrl, myObjAsString, 'application/json');
// if (response.success !== undefined)
if (result.status == 200)
{
var i, ii;
// Create javascript objects from the server response
// Each item is a favourite site that the user is a member of
//var sites = eval('(' + result + ')'), site;
var response = eval('(' + result + ')'), data;
if (response.length != 0)
{
// Sort the sites by title
//sites.sort(sortByTitle);
for (i = 0, ii = response.items.length; i < ii; i++)
{
data = response.items[i];
//if (site.shortName == currentSite)
//{
// siteTitle = data.title;
//if (ignoreCurrentSite)
//{
// The current site was piggy-backing the query call; it's not a favourite
// continue;
//}
//currentSiteIsFav = true;
//var dt=new Date(data.itemData.prop_graph_graphDate.value);
//var mois=dt.getMonth();
var date = fromISO8601(data.itemData.prop_graph_graphDate.value);
dataSites.push(
{
sitename: site,
listename: liste,
listetitle: listetitle,
listedescription: listedesc,
tdate : date,
graphDate : data.itemData.prop_graph_graphDate.value,
graphValeur : data.itemData.prop_graph_graphValeur.value,
graphTendance : data.itemData.prop_graph_graphTendance.value,
graphObjectif : data.itemData.prop_graph_graphObjectif.value
});
}
}
}
return dataSites;
}
function fromISO8601(formattedString)
{
var isoRegExp = /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(.\d+)?)?((?:[+-](\d{2}):(\d{2}))|Z)?)?$/;
var match = isoRegExp.exec(formattedString);
var result = null;
if (match)
{
match.shift();
if (match[1]){match[1]–;} // Javascript Date months are 0-based
if (match[6]){match[6] *= 1000;} // Javascript Date expects fractional seconds as milliseconds
result = new Date(match[0]||1970, match[1]||0, match[2]||1, match[3]||0, match[4]||0, match[5]||0, match[6]||0);
var offset = 0;
var zoneSign = match[7] && match[7].charAt(0);
if (zoneSign != 'Z')
{
offset = ((match[8] || 0) * 60) + (Number(match[9]) || 0);
if (zoneSign != '-')
{
offset *= -1;
}
}
if (zoneSign)
{
offset -= result.getTimezoneOffset();
}
if (offset)
{
result.setTime(result.getTime() + offset * 60000);
}
}
return result; // Date or null
}
model.dataSites = main();
var healthDataSource = new YAHOO.util.XHRDataSource("/share/service/components/graph/getDataListData.json?siteId=${page.url.templateArgs.site}");
01-18-2011 03:36 AM
args.siteId
ou url.args.siteId
01-18-2011 04:06 AM
01-18-2011 06:39 AM
01-21-2011 03:49 AM
Maintenant il va me falloir étudier la création de la classe. Penses tu que c'est plus propre de passer par une classe ? Quel avantage je vais en tirer ?Désolé pour la réponse tardive, oui je pense que c'est plus propre.
Dans mon js je récupère bien le nom des listes et il est bien transmis en json mais cependant je dois avoir un probleme dans ma boucle car mon itemsdata ne me retourne que les valeurs de la derniere liste.A chaque itération, vous écrasez la valeur précédente de 'itemsdata '.
var itemsdata = [];
for (var i = 0, ii = listdata.length; i < ii; i++) {
test = listdata[i];
itemsdata = getDataforGraph(siteId, test.names, test.titles, test.descriptions);
}
return itemsdata;
Il faudrait plutôt faire quelque chose du genre : for (var i = 0, ii = listdata.length; i < ii; i++) {
test = listdata[i];
itemsdata.push(getDataforGraph(siteId, test.names, test.titles, test.descriptions));
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.