/** * ----------------------------------------------------------------------------- * file: estatPM.js * file version: 1.0.0 * date: 2011-12-02 * * Page Manager */ var themeColor={ border:'#666666', background:'#222222' } /** * estatPM class * used to manage the admin interface * * public functions : * - changePage(pageName) */ $.EStatManagePages = function (fct, values) { var $this = this, properties={ url:'', urlExport:'', token:'', currentPage:'Stats_by_period', initPhase:false, graph:{ axis:{ color:'#666666', ticksSize:{ small:1, big:10 }, minSpaceLast:5, frequency:{ small:2, big:5 }, value:{ rotateH:20, rotateV:0, fontName:'arial', fontSize:8 } }, colors:{ normal:[ '#ffdd18', // 0: yellow '#b73561', // 1: red purple '#00a14b', // 2: green '#fe4819', // 3: red-orange '#21409a', // 4: blue '#f99d28', // 5: yellow-orange '#7f4098', // 6: purple '#8cc63f', // 7: yellow-green '#ed1c24', // 8: red '#07707d', // 9: blue-green '#f26522', // 10: orange '#584099' // 11: blue-purple ], light:[ '#ffe466', // 0: yellow '#c5667a', // 1: red purple '#6ab574', // 2: green '#f58256', // 3: red-orange '#5a64ac', // 4: blue '#fcbe75', // 5: yellow-orange '#996caf', // 6: purple '#a8d171', // 7: yellow-green '#f16045', // 8: red '#548490', // 9: blue-green '#f78f58', // 10: orange '#7968ae' // 11: blue-purple ], dark:[ '#bfa417', // 0: yellow '#872146', // 1: red purple '#057938', // 2: green '#b23016', // 3: red-orange '#142a75', // 4: blue '#b8761f', // 5: yellow-orange '#5f2974', // 6: purple '#66952d', // 7: yellow-green '#b11016', // 8: red '#05535d', // 9: blue-green '#b34b14', // 10: orange '#422a74' // 11: blue-purple ], gray:[ '#111111', // 0: '#222222', // 1: '#333333', // 2: '#444444', // 3: '#555555', // 4: '#666666', // 5: '#777777', // 6: '#888888', // 7: '#999999', // 8: '#AAAAAA', // 9: '#BBBBBB', // 10: '#CCCCCC', // 11: '#DDDDDD', // 12: '#EEEEEE' // 13: ] } }, history:{ graphAllPeriods:{ axis:null, serieTotal:null, serieComputer:null, serieMobile:null, serieCrawler:null, serieOther:null }, graphCurrentPeriod:{ axis:null, serieTotal:null, serieComputer:null, serieMobile:null, serieCrawler:null, serieOther:null } }, period:{ graph:{ axis:null, serieViewedAlbums:null, serieViewedImages:null, serieViewedPages:null, serieUniqueIP:null } }, ip:{ graphType:{ axis:null, serie:null }, graphCountry:{ axis:null, serie:null } } }, // << properties={...} /** * ------------------------------------------------------------------------- * set the properties values * ------------------------------------------------------------------------- */ setProperties = function (values) { if(values==null) values=$(window).data('EStatMPProperties'); if(values==null) return(false); if(values.url) properties.url=values.url; if(values.urlExport) properties.urlExport=values.urlExport; if(values.token) properties.token=values.token; if(values.currentPage) properties.currentPage=values.currentPage; if(values.history) properties.history=values.history; if(values.period) properties.period=values.period; if(values.ip) properties.ip=values.ip; $(window).data('EStatMPProperties', properties); return(true); }, // << setProperties() /** * ------------------------------------------------------------------------- * * INITIALIZATION FUNCTIONS * * * ------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------- * this function initialize the page (jquery objects) and preload data page * ------------------------------------------------------------------------- */ init=function () { properties.initPhase=true; initGlobalObjects(); //initPageSynthesis(); initPagePeriod(); initPageIP(); initPageCategory(); initPageImage(); initPageHistory(); //initPageConfig(); //initPageTools(); properties.initPhase=false; changePage('Stats_by_period'); }, /** * ------------------------------------------------------------------------- * initialise objects common to all pages * ------------------------------------------------------------------------- */ initGlobalObjects = function() { $('#iFilterCatId').categorySelector( { listMaxWidth:600, listMaxHeight:350, displayStatus:true, displayPath:true, multiple:true, levelIndent:20, userMode:'public', galleryRoot:false, load: function (event) { $(this).categorySelector('expand', ':all+0'); //$(this).categorySelector('value', ':first'); }, change: function (event) { loadPage(); } } ); $('#iFilterPeriodId').inputTreeList( { listMaxWidth:600, listMaxHeight:350, levelIndent:15, iconWidthEC:10, displayPath:true, postUrl:properties.url, displayNfo:false, multiple:false, postData:{ ajaxfct:"admin.stat.periodTreeList", token:properties.token }, load: function (event) { $(this).inputTreeList('collapse', ':all+0'); $(this).inputTreeList('value', ':first'); }, change: function (event) { loadPage(); } } ); }, // << initGlobalObjects() initPageSynthesis = function() { }, // << initPageSynthesis() /** * ------------------------------------------------------------------------- * initialise objects for period page * ------------------------------------------------------------------------- */ initPagePeriod = function() { // create history dynamic table $('#iPeriodTable').dynamicTable( { columns: [ { id:'period', title:translateString.period, sortable:'no', width:'20%' }, { id:'viewedPages', title:translateString.viewedPages, sortable:'no', width:'20%' }, { id:'viewedAlbums', title:translateString.viewedAlbums, sortable:'no', width:'20%' }, { id:'viewedImages', title:translateString.viewedImages, sortable:'no', width:'20%' }, { id:'uniqueIP', title:translateString.uniqueIP, sortable:'no' } ], showTotalRow:'visible', showSaveButton:false, autoLoad:false, postUrl:properties.url, postData: { ajaxfct:"admin.stat.period", token:properties.token, period:'' }, minHeight:350, maxHeight:350, footerString: { singular:'', plural:'' }, /* pageChanged: function (event, value) { }, */ contentLoading: function (event, value) { $('#iPeriodTable').dynamicTable('click', 'clear'); }, contentLoaded: function (event, value) { switch($('#iPeriodPath').inputPath('level')) { case 1: case 2: $('#iPeriodTable').dynamicTable('click', clickOnPeriodTable); break; case 3: $('#iPeriodTable').dynamicTable('click', 'clear'); break; } }, click: clickOnPeriodTable } ); // create graph - stat for all period properties.period.graph.axis=new CDAxis( { mode:'XY', display:{ color:properties.graph.axis.color, visible: { XY: { H:true, V:true } } }, XY:{ ticks:{ H:{ size:{ small:properties.graph.axis.ticksSize.small, big:properties.graph.axis.ticksSize.big }, visible:{ small:true, big:true }, minSpaceLast:properties.graph.axis.minSpaceLast, frequency:{ small:1, //properties.graph.axis.frequency.small, big:1 //properties.graph.axis.frequency.big }, value:{ rotate:properties.graph.axis.value.rotateH, visible:true, fontName:properties.graph.axis.value.fontName, fontSize:properties.graph.axis.value.fontSize }, offset0:true }, V:{ unit:'', size:{ small:properties.graph.axis.ticksSize.small, big:properties.graph.axis.ticksSize.big }, visible:{ small:true, big:true }, minSpaceLast:properties.graph.axis.minSpaceLast, steps:10000, frequency:{ small:250, big:1000 }, value:{ rotate:properties.graph.axis.value.rotateV, visible:true, fontName:properties.graph.axis.value.fontName, fontSize:properties.graph.axis.value.fontSize } } } }, values:{H:[]} } ); properties.period.graph.serieViewedPages=new CDSerie( { name:'viewedPages', order:10, values:[], options:new CDSerieOptionsBar( { backgroundColor:properties.graph.colors.gray[3], borderColor:properties.graph.colors.gray[7], borderWidth:0, width:1, offset:0 } ) } ); properties.period.graph.serieViewedAlbums=new CDSerie( { name:'viewedAlbums', order:2, values:[], options:new CDSerieOptionsLine( { color:properties.graph.colors.normal[0], width:1, offset:0 } ) } ); properties.period.graph.serieViewedImages=new CDSerie( { name:'viewedImages', order:3, values:[], options:new CDSerieOptionsLine( { color:properties.graph.colors.normal[1], width:1, offset:0 } ) } ); properties.period.graph.serieUniqueIP=new CDSerie( { name:'uniqueIP', order:4, values:[], options:new CDSerieOptionsLine( { color:properties.graph.colors.normal[2], width:1, offset:0 } ) } ); properties.period.graph.axis.serieAdd(properties.period.graph.serieViewedAlbums); properties.period.graph.axis.serieAdd(properties.period.graph.serieViewedImages); properties.period.graph.axis.serieAdd(properties.period.graph.serieViewedPages); properties.period.graph.axis.serieAdd(properties.period.graph.serieUniqueIP); $('#iPeriodGraph').drawingGraph( { display: { width:450, height:150 }, cursor: { verticalType:'line' }, margins:new CDMargins({top:5,bottom:45, left:50, right:1}), legend:new CDLegend({ width:0, visible:false, position:'right', // left or right backgroundColor:themeColor.background, borderColor:themeColor.border, borderWidth:0, fontName:'arial', fontSize:10 }), axis:{front:properties.period.graph.axis, back:null}, events:{ mouseEnter:function (event) { var geometry={ x:0, y:0, w:250, h:75 }; geometry.x=$('#iPeriodGraph').offset().left+($('#iPeriodGraph').width()-geometry.w)/2; geometry.y=$('#iPeriodGraph').offset().top-geometry.h-10; displayPopupInfo(true, geometry, getPeriodPopupContent()); }, mouseLeave:function (event) { displayPopupInfo(false); }, mousePositionChange:function (event, data) { var list=['viewedAlbums', 'viewedImages', 'uniqueIP', 'viewedPages']; for(i=0;i', '<', '>=', '<=', '=', '!=', 'between', 'not between'] }, sortable:'asc', width:'125px' }, { id:'IPadress', title:translateString.ip_user, filter: { title:translateString.filter.ipAdress, dataType:'string', data:{ regexp:'\d{1,3}(?:\.\d{1,3}){0,3}' }, defaultOperator:'like', filterOperators:['like', 'not like', 'between', 'not between'] }, sortable:'asc', width:'125px' }, { id:'catId', title:translateString.album, sortable:'no', width:'225px' }, { id:'imageId', title:translateString.image, sortable:'no', width:'200px' }, { id:'tags', title:translateString.tags, sortable:'no' }, { id:'section', title:translateString.section, filter: { title:translateString.filter.section, dataType:'dataset', data:{ serverUrl:'' }, defaultOperator:'in', filterOperators:['in'] }, sortable:'asc', width:'100px' }, { id:'uaBrowser', title:translateString.browser, filter: { title:translateString.filter.browser, dataType:'dataset-url', data:{ serverUrl:properties.url+'?ajaxfct=admin.fct.validValues&domain=uaBrowser&token='+properties.token }, defaultOperator:'in', filterOperators:['in'] }, sortable:'asc', width:'165px' }, { id:'uaEngine', title:translateString.engine, filter: { title:translateString.filter.engine, dataType:'dataset-url', data:{ serverUrl:properties.url+'?ajaxfct=admin.fct.validValues&domain=uaEngine&token='+properties.token }, defaultOperator:'in', filterOperators:['in'] }, sortable:'asc', width:'125px' }, { id:'uaOS', title:translateString.os, filter: { title:translateString.filter.os, dataType:'dataset-url', data:{ serverUrl:properties.url+'?ajaxfct=admin.fct.validValues&domain=uaOS&token='+properties.token }, defaultOperator:'in', filterOperators:['in'] }, sortable:'asc', width:'125px' }, { id:'uaType', title:translateString.type, filter: { title:translateString.filter.type, dataType:'dataset-url', data:{ serverUrl:properties.url+'?ajaxfct=admin.fct.validValues&domain=uaType&token='+properties.token }, defaultOperator:'in', filterOperators:['in'] }, sortable:'asc', width:'125px' } ], showSaveButton:true, autoLoad:false, postUrl:properties.url, postData: { ajaxfct:"admin.stat.history", token:properties.token, period:'' }, minHeight:150, maxHeight:350, sortBoxTitle:translateString.sortBy, footerString: { singular:translateString.item_nb, plural:translateString.items_nb, waitForDownload:translateString.waitForDownload }, dialogsButtons:{ ok:translateString.ok, cancel:translateString.cancel, erase:translateString.eraseFilter }, /* pageChanged: function (event, value) { }, contentLoading: function (event, value) { }, */ saveButtonClick: function (event, data) { $.dialogExport( { title:translateString.dataExport, buttons: { ok:translateString.ok, cancel:translateString.cancel }, name:'history', format:'csv', compression:'gz', formatList: [ {id:'csv', text:translateString.fileFormatCSV, infos:'(.csv)'}, {id:'ods', text:translateString.fileFormatODS, infos:'(.ods)'}, {id:'sqlite', text:translateString.fileFormatSQLite, infos:'(.db)'} ], compressionList: [ {id:'none', text:translateString.fileCompressionNone, infos:''}, {id:'zip', text:translateString.fileCompressionZIP, infos:'(.zip)'}, {id:'gz', text:translateString.fileCompressionGZ, infos:'(.gz)'}, {id:'bz2', text:translateString.fileCompressionBZ2, infos:'(.bz2)'} ], validExport: function (event, values) { $('#iHistoryTable').dynamicTable('waitForDownload', true); $.ajax( { type: "POST", url: properties.urlExport, data: { ajaxfct:'admin.export.history', name:values.name, format:values.format, compression:values.compression, token:properties.token, period:$('#iHistoryFilterPeriod').inputList('value'), additionalFilter:{catId:$('#iFilterCatId').categorySelector('value')}, sort:data.sort, filter:data.filter, group:data.group }, async: true, success: function(msg) { $('#iHistoryTable').dynamicTable('waitForDownload', false); if(msg.substr(0,3)=='OK:') { $.download(msg.substr(3)); } else { alert(translateString.downloadError); } }, error: function(msg) { $('#iHistoryTable').dynamicTable('waitForDownload', false); } } ); } } ); }, contentLoading: function (event, value) { $(this).find('tr[oid]').unbind('mouseenter mouseleave'); }, contentDisplayed: function (event, value) { for(var i=0;i 160 * 241 => 250 * 1247 => 1250 * 12478 => 12500 * * @param Integer value: the value to be rounded * @return Integer: rounded value * ----------------------------------------------------------------------- */ roundValue = function (value) { var divider=1; if(value<=1000) { divider=10; } else if(value<10000) { divider=100; } else { divider=1000; } return(Math.ceil(value/divider)*divider); }, /** * ----------------------------------------------------------------------- * calculate ticks values according to the current axis properties * (height in pixel and max value) * * @param CDAxis axis: axis * @return object: {small:(Integer), big:(Integer)} * ----------------------------------------------------------------------- */ calculateTicks = function (axis) { var divider=1, maxValue=axis.get().properties.XY.ticks.V.steps, returned={ small:0, big:0 }; if(maxValue<=10) { divider=1; } else if(maxValue<=100) { divider=10; } else if(maxValue<=1000) { divider=100; } else if(maxValue<10000) { divider=1000; } else { divider=10000; } returned.small=Math.ceil(maxValue/divider)*divider/20; returned.big=5*returned.small; return(returned); }, /** * ----------------------------------------------------------------------- * display the popup info box * * @param Boolean visible: display or hide the popup * @param object geometry: {x:(Integer), y:(Integer), w:(Integer), h:(Integer)} object to set the position * @param String content: content of the box * ----------------------------------------------------------------------- */ displayPopupInfo = function (visible, geometry, content) { if(content==null) content=''; if(geometry==null) geometry={x:-1, y:-1, w:0, h:0}; if(visible==null) visible=false; $('#iPopupInfo') .html(content) .css( { 'left':geometry.x+'px', 'top':geometry.y+'px', 'width':geometry.w+'px', 'height':geometry.h+'px', 'display':visible?'block':'none' } ); }, /** * ----------------------------------------------------------------------- * display the popup thumbnail image * * @param Boolean visible: display or hide the popup * @param object geometry: {x:(Integer), y:(Integer)} object to set the position * @param String url: url of the thumbnail * ----------------------------------------------------------------------- */ displayPopupThumb = function (visible, geometry, url) { if(geometry==null) geometry={x:-1, y:-1}; if(visible==null) visible=false; if(url==null) { visible=false; url=''; } if(visible) { $('#iPopupThumb') .bind('load', {geometry:geometry}, function (e) { $(this).css( { 'left':(e.data.geometry.x-e.target.width/2)+'px', 'top':(e.data.geometry.y-e.target.height-15)+'px', 'display':'block' } ); } ) .attr('src', url); } else { $('#iPopupThumb').css('display', 'none'); } }, /** * ----------------------------------------------------------------------- * return the html content for popup box on history graph * ----------------------------------------------------------------------- */ getHistoryPopupContent = function () { return( ""+translateString.events+"
"+ ""+translateString.ua_Computer+""+ "-
"+ ""+translateString.ua_Mobile+""+ "-
"+ ""+translateString.ua_Crawler+""+ "-
"+ ""+translateString.ua_Other+""+ "-
"+ ""+translateString.total+""+ "-" ); }, /** * ----------------------------------------------------------------------- * return the html content for popup box on period graph * ----------------------------------------------------------------------- */ getPeriodPopupContent = function () { return( ""+translateString.visits+"
"+ ""+translateString.viewedPages+""+ "-
"+ ""+translateString.viewedAlbums+""+ "-
"+ ""+translateString.viewedImages+""+ "-
"+ ""+translateString.uniqueIP+""+ "-
" ); } /** * ----------------------------------------------------------------------- * action done when user click on the period table * * this function is set has an event on $('#iPeriodTable') object * ----------------------------------------------------------------------- */ clickOnPeriodTable = function (event) { var oId=$(this).attr('oId'), data=$('#iPeriodTable').dynamicTable('loadedData', oId), period=''; switch($('#iPeriodPath').inputPath('level')) { case 1: // all years => years $('#iPeriodPath').inputPath('push', {id:'y-'+data[5], label:data[0]} ); break; case 2: // year => months period=$('#iPeriodPath').inputPath('itemLevel', $('#iPeriodPath').inputPath('level')).id.substr(2); $('#iPeriodPath').inputPath('push', {id:'ym-'+period+data[5], label:data[0]} ); break; case 3: // month => days break; } refreshGraphPeriod(); refreshPagePeriodContent(); }; /** * ---------------------------------------------------------------------------- * * MAIN OBJECT FUNCTION * * * ---------------------------------------------------------------------------- */ switch(fct) { case 'init': setProperties(values); init(); break; case 'changePage': setProperties(null); changePage(values); break; } }