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-21-2011 07:48 AM
07-11-2011 05:45 AM
07-11-2011 05:47 AM
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.