Ero sivun ”Widget:Levätaulukko” versioiden välillä
Järvi-meriwikistä
(Ak: Sivun sisältö korvattiin sisällöllä ”<includeonly><div id="<!--{$id|default:JwAlgalTable|escape:'html'}-->_container"><p>Ladataan tietoja, odota...</p></div> </includeonly>”) Merkkaus: Korvattu |
p (Tekstin korvaus – ”|limit=1000” muotoon ”|limit=2000”) |
||
(32 välissä olevaa versiota samalta käyttäjältä ei näytetä) | |||
Rivi 1: | Rivi 1: | ||
− | <includeonly><div id="<!--{$id|default:JwAlgalTable|escape:'html'}-->_container"><p>Ladataan tietoja, odota...</p></div> | + | <includeonly> |
+ | <div id="<!--{$id|default:JwAlgalTable|escape:'html'}-->_container"><p class="ingressi">Ladataan tietoja, odota...</p></div> | ||
+ | <script type="text/javascript"> | ||
+ | |||
+ | function <!--{$id|default:JwAlgalTable|escape:'html'}-->_jQueryTest() { | ||
+ | if ( typeof window.jQuery == 'undefined' ) { | ||
+ | setTimeout( function(){ <!--{$id|default:JwAlgalTable|escape:'html'}-->_jQueryTest() }, 300); | ||
+ | } else { | ||
+ | <!--{$id|default:JwAlgalTable|escape:'html'}-->_func(); | ||
+ | } | ||
+ | } | ||
+ | setTimeout( function(){ <!--{$id|default:JwAlgalTable|escape:'html'}-->_jQueryTest() }, 300); | ||
+ | |||
+ | function <!--{$id|default:JwAlgalTable|escape:'html'}-->_func() { | ||
+ | |||
+ | var vuosi = "<!--{$vuosi|default:1998|escape:'html'}-->"; | ||
+ | var alue = "<!--{$alue|escape:'html'}-->"; | ||
+ | var ely, meri; | ||
+ | |||
+ | if ( alue == 'Sisävedet' ) { | ||
+ | ely = 'ei'; | ||
+ | meri = 0; | ||
+ | } else if ( alue == 'Merialue' ) { | ||
+ | ely = 'ei'; | ||
+ | meri = 1; | ||
+ | } else { | ||
+ | ely = alue.replace( 'ELY', 'elinkeino-, liikenne- ja ympäristökeskus' ); | ||
+ | meri = 2; | ||
+ | } | ||
+ | |||
+ | var kunta = "<!--{$kunta|default:ei|escape:'html'}-->"; | ||
+ | |||
+ | var qtId = "<!--{$id|default:algalTable|escape:'html'}-->"; | ||
+ | |||
+ | var reqSuccess = false; | ||
+ | |||
+ | var meripaikkoja = false; | ||
+ | var numberOfRows = 0; | ||
+ | var maxRows = 0; | ||
+ | |||
+ | var exportCsv = ""; | ||
+ | var dataArr = new Array(); | ||
+ | |||
+ | var searchStr = "action=ask&query=[[Havainto::>0]]"; | ||
+ | searchStr += encodeURI("[[Tyyppi::Levätilanne]]"); | ||
+ | searchStr += encodeURI("[[Seuranta::Valtakunnallinen leväseuranta]]"); | ||
+ | searchStr += "[[Vuosi::" + vuosi + "]]"; | ||
+ | searchStr += "[[Viikko::>23]][[Viikko::<39]]"; | ||
+ | if (ely != "ei") { searchStr += "[[ELY-keskus::" + encodeURI(ely) + "]]"; } | ||
+ | if (kunta != "ei") { searchStr += "[[Kunta::" + encodeURI(kunta) + "]]"; } | ||
+ | if (meri == "0") { searchStr += encodeURI("[[Vesistö::Järvi||Joki]]"); } | ||
+ | else if (meri == "1") { searchStr += encodeURI("[[Vesistö::Meri]]"); } | ||
+ | |||
+ | searchStr += encodeURI("|?SiteID|?SiteName|?Vesistö|?Alue|?Järvi|?Vesistöalue|?Kunta|?Viikko|?Levätilanne|limit=20000"); | ||
+ | searchStr += '&format=json'; | ||
+ | |||
+ | jQuery.ajax({ | ||
+ | type: 'GET', | ||
+ | url: queryApi, | ||
+ | data: searchStr, | ||
+ | success: success, | ||
+ | dataType: 'jsonp' | ||
+ | }); | ||
+ | |||
+ | function progressIndicator(d) { | ||
+ | jQuery('#<!--{$id|default:JwAlgalTable|escape:'html'}-->_container').html('Ladataan tietoja (' + (maxRows-d) + '/' + maxRows + ')'); | ||
+ | } | ||
+ | |||
+ | function success(request) { | ||
+ | console.log(request); | ||
+ | reqSuccess = true; | ||
+ | |||
+ | if ( request.query.meta.count > 0 ) { | ||
+ | |||
+ | var output = ""; | ||
+ | var lastSite = ""; | ||
+ | var lastWeek = 0; | ||
+ | output += '<div class="mw-content-ltr">' | ||
+ | output += '<table width="100%" class="tablesorter sortable jquery-tablesorter wikitable smwtable Xsmalltable2 tablecompact" id="<!--{$id|default:JwAlgalTable|escape:'html'}-->" >'; | ||
+ | output += '<thead><tr>'; | ||
+ | output += '<th class="headerSort " style="text-align: left;"></th>'; | ||
+ | output += '<th class="headerSort" style="text-align: left;">Vesistö</th>'; | ||
+ | output += '<th class="headerSort" style="text-align: left;">Nimi</th>'; | ||
+ | output += '<th class="headerSort" style="text-align: left;">Kunta</th>'; | ||
+ | output += '<th class="headerSort headerSortSmall" style="text-align: center;">23</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">24</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">25</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">26</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">27</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">28</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">29</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">30</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">31</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">32</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">33</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">34</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">35</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">36</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">37</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">38</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">39</th>'; | ||
+ | output += '</tr></thead><tbody>'; | ||
+ | |||
+ | maxRows = request.query.results.length; | ||
+ | |||
+ | var siteIDs = new Object(); | ||
+ | |||
+ | for (var i in request.query.results) { | ||
+ | |||
+ | numberOfRows++; | ||
+ | progressIndicator(numberOfRows); | ||
+ | |||
+ | resultItem = request.query.results[i].printouts; | ||
+ | resultPage = resultItem.SiteID[0]; | ||
+ | |||
+ | if (dataArr[resultPage] == undefined) { | ||
+ | |||
+ | dataArr[resultPage] = new Object(); | ||
+ | dataArr[resultPage].url = "//www.jarviwiki.fi/wiki/index.php?curid=" + resultPage; | ||
+ | dataArr[resultPage].SiteName = resultItem.SiteName[0].fulltext; | ||
+ | if (resultItem.Vesistö[0] == 'Meri') { | ||
+ | dataArr[resultPage].sea = true; | ||
+ | } else { | ||
+ | dataArr[resultPage].sea = false; | ||
+ | } | ||
+ | if (resultItem.Alue.length > 0) { | ||
+ | dataArr[resultPage].wBody = resultItem.Alue[0].fulltext; | ||
+ | dataArr[resultPage].wBodyUrl = resultItem.Alue[0].fullurl; | ||
+ | } else { | ||
+ | if (resultItem.Vesistö[0] == 'Järvi') { | ||
+ | dataArr[resultPage].wBody = resultItem.Järvi[0].fulltext; | ||
+ | dataArr[resultPage].wBodyUrl = resultItem.Järvi[0].fullurl; | ||
+ | } else { | ||
+ | dataArr[resultPage].wBody = resultItem.Vesistöalue[0].fulltext; | ||
+ | dataArr[resultPage].wBodyUrl = resultItem.Vesistöalue[0].fullurl; | ||
+ | } | ||
+ | } | ||
+ | dataArr[resultPage].mun = resultItem.Kunta[0].fulltext; | ||
+ | dataArr[resultPage].munUrl = resultItem.Kunta[0].fullurl; | ||
+ | dataArr[resultPage].weeks = new Array(); | ||
+ | } | ||
+ | |||
+ | resultWeek = resultItem.Viikko[0]; | ||
+ | |||
+ | dataArr[resultPage].weeks[resultWeek] = resultItem.Levätilanne[0]; | ||
+ | |||
+ | } | ||
+ | |||
+ | function doRows() { | ||
+ | |||
+ | for (var s in dataArr) { | ||
+ | |||
+ | site = dataArr[s]; | ||
+ | |||
+ | output += '<tr>'; | ||
+ | |||
+ | if (site.sea) { | ||
+ | meripaikkoja = true; | ||
+ | output += '<td data-sort-value="1" valign="middle" class="smwtype_qty">'; | ||
+ | output += '<a href="' + site.url + '" title="' + site.title + '">'; | ||
+ | output += '<img alt="Merialue" src="//www.jarviwiki.fi/w/images/a/ac/Pm_hp_asiantuntija_1_27x27.png" width="27" height="27" style="vertical-align: middle" />'; | ||
+ | output += '</a></td>'; | ||
+ | } else { | ||
+ | output += '<td data-sort-value="0" valign="middle" class="smwtype_qty">'; | ||
+ | output += '<a href="' + site.url + '" title="' + site.title + '">'; | ||
+ | output += '<img alt="Sisävesi" src="//www.jarviwiki.fi/w/images/f/f3/Pm_hp_asiantuntija_2_27x27.png" width="27" height="27" style="vertical-align: middle" />'; | ||
+ | output += '</a></td>'; | ||
+ | } | ||
+ | output += '<td class="smwtype_wpg"><a href="' + site.wBodyUrl + '">' + site.wBody + '</a></td>'; | ||
+ | |||
+ | nimi = site.SiteName.substr(site.SiteName.lastIndexOf('/')); //site.title.substr(site.title.lastIndexOf('/')); | ||
+ | |||
+ | if (nimi.indexOf('(') != -1) { | ||
+ | nimi = nimi.substr(nimi.indexOf('(')); | ||
+ | nimi = nimi.substr(1); | ||
+ | nimi = nimi.substr(0, nimi.length-1); | ||
+ | } else { | ||
+ | nimi = ""; | ||
+ | } | ||
+ | output += '<td class="smwtype_wpg">' + nimi + '</td>'; | ||
+ | output += '<td class="smwtype_wpg"><a href="' + site.munUrl + '">' + site.mun + '</a></td>'; | ||
+ | |||
+ | for (x = 23; x < 40; x++) { | ||
+ | |||
+ | if (site.weeks[x] != undefined) { | ||
+ | resultAlgalVal = site.weeks[x]; | ||
+ | if (resultAlgalVal == 0) { | ||
+ | exportCsv += ";0"; | ||
+ | output += '<td data-sort-value="0" class="smwtype_qty" style="text-align: center; vertical-align: middle; background-color:none">0</td>'; | ||
+ | } else if (resultAlgalVal == 1) { | ||
+ | exportCsv += ";1"; | ||
+ | output += '<td data-sort-value="1" class="smwtype_qty" style="text-align: center; vertical-align: middle; background-color:#6a9d38">1</td>'; | ||
+ | } else if (resultAlgalVal == 2) { | ||
+ | exportCsv += ";2"; | ||
+ | output += '<td data-sort-value="2" class="smwtype_qty" style="text-align: center; vertical-align: middle; background-color:#fd9f00">2</td>'; | ||
+ | } else { | ||
+ | exportCsv += ";3"; | ||
+ | output += '<td data-sort-value="3" class="smwtype_qty" style="text-align: center; vertical-align: middle; background-color:#c80000">3</td>'; | ||
+ | } | ||
+ | } else { | ||
+ | output += '<td data-sort-value="-1" class="smwtype_qty" style="text-align: center; vertical-align: middle; background-color:none">-</td>'; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | output += '</tr>'; | ||
+ | } | ||
+ | |||
+ | output += '</tbody><tfoot></tfoot></table></div>'; | ||
+ | if (meripaikkoja) { | ||
+ | //output += '<div style="border: 0; float: left; margin-left: 13px;"><p class="kuvateksti"><a href="/w/images/a/ac/Pm_hp_asiantuntija_1_27x27.png"><img alt="Merialue" src="/w/images/thumb/a/ac/Pm_hp_asiantuntija_1_27x27.png/21px-Pm_hp_asiantuntija_1_27x27.png" width="21" height="21" /></a> = Merialueen havaintopaikka</p></div>'; | ||
+ | } | ||
+ | output += '</div>'; | ||
+ | |||
+ | jQuery("#<!--{$id|default:JwAlgalTable|escape:'html'}-->_container").html(output); | ||
+ | jQuery("#<!--{$id|default:JwAlgalTable|escape:'html'}-->").tablesorter(); | ||
+ | } | ||
+ | |||
+ | doRows(); | ||
+ | |||
+ | } else { | ||
+ | |||
+ | jQuery("#<!--{$id|default:JwAlgalTable|escape:'html'}-->_container").html( '<p class="ingressi">Hakuehtojen mukaisia tietoja ei löytynyt.</p>' ); | ||
+ | |||
+ | } | ||
+ | //alert(exportCsv); | ||
+ | } | ||
+ | |||
+ | function lataaTiedot() { | ||
+ | var newWindow = window.open("","Lataa","width=300,height=300,scrollbars=1,resizable=1"); | ||
+ | |||
+ | newWindow.document.open(); | ||
+ | newWindow.document.write(exportCsv); | ||
+ | newWindow.document.close(); | ||
+ | |||
+ | //window.open('data:text/csv;charset=utf-8,' + escape(exportCsv)); | ||
+ | } | ||
+ | |||
+ | |||
+ | } | ||
+ | </script> | ||
</includeonly> | </includeonly> |