view src/main/webapp/resources/js/general.js @ 105:16a0796e3871 default tip

remove "console.log" from general.js
author Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
date Fri, 29 Sep 2017 16:18:02 +0200
parents b27a99201cbe
children
line wrap: on
line source

function getChromeVersion(){

    var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);

    return raw ? parseInt(raw[2], 10) : false;
}

function branchInExtractionInterface(
		branchId, fileId,
		sectionId,
		sectionName,
		bookId,
		bookName,
		userId, extractionInterfaceUrl){

	// the input parameters contain fileId, since a branch means a text/many version of the text, of a section

	var form = document.createElement("form");
	form.setAttribute("method", "post");
	form.setAttribute("action", extractionInterfaceUrl + "/Extractapp/TaggingText");  // hand to controller
	form.setAttribute("target", "_blank");


	var hiddenField0 = document.createElement("input");
	hiddenField0.setAttribute("name", "branchId");
	hiddenField0.setAttribute("value", branchId);
	form.appendChild(hiddenField0);

	var hiddenField1 = document.createElement("input");
	hiddenField1.setAttribute("name", "fileId");
	hiddenField1.setAttribute("value", fileId);
	form.appendChild(hiddenField1);

	var hiddenField2 = document.createElement("input");
	hiddenField2.setAttribute("name", "userId");
	hiddenField2.setAttribute("value", userId);
	form.appendChild(hiddenField2);

	var hiddenField3 = document.createElement("input");
	hiddenField3.setAttribute("name", "sectionId");
	hiddenField3.setAttribute("value", sectionId);
	form.appendChild(hiddenField3);


	var hiddenField4 = document.createElement("input");
	hiddenField4.setAttribute("name", "sectionName");
	hiddenField4.setAttribute("value", sectionName);
	form.appendChild(hiddenField4);

	var hiddenField5 = document.createElement("input");
	hiddenField5.setAttribute("name", "bookId");
	hiddenField5.setAttribute("value", bookId);
	form.appendChild(hiddenField5);

	var hiddenField6 = document.createElement("input");
	hiddenField6.setAttribute("name", "bookName");
	hiddenField6.setAttribute("value", bookName);
	form.appendChild(hiddenField6);

	if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1 || getChromeVersion() > 55) {
	       document.body.appendChild(form);
	       form.submit();
	       document.body.removeChild(form);
	   } else {

	       form.submit(); // works under IE, neither FF nor Chrome
	   }
}

function sectionInExtractionInterface(sectionId, sectionName, bookId, bookName, topicId, userId, extractionInterfaceUrl){

	// the input parameters contain no fileId, since it's from searching result and haven't assigned topic Or saved

	var form = document.createElement("form");
	form.setAttribute("method", "post");
	form.setAttribute("action", extractionInterfaceUrl + "/Extractapp/TaggingText");  // hand to controller
	form.setAttribute("target", "_blank");

	var hiddenField2 = document.createElement("input");
	hiddenField2.setAttribute("name", "userId");
	hiddenField2.setAttribute("value", userId);
	form.appendChild(hiddenField2);

	var hiddenField3 = document.createElement("input");
	hiddenField3.setAttribute("name", "sectionId");
	hiddenField3.setAttribute("value", sectionId);
	form.appendChild(hiddenField3);

	var hiddenField4 = document.createElement("input");
	hiddenField4.setAttribute("name", "sectionName");
	hiddenField4.setAttribute("value", sectionName);
	form.appendChild(hiddenField4);

	var hiddenField5 = document.createElement("input");
	hiddenField5.setAttribute("name", "bookId");
	hiddenField5.setAttribute("value", bookId);
	form.appendChild(hiddenField5);

	var hiddenField6 = document.createElement("input");
	hiddenField6.setAttribute("name", "bookName");
	hiddenField6.setAttribute("value", bookName);
	form.appendChild(hiddenField6);

	var hiddenField7 = document.createElement("input");
	hiddenField7.setAttribute("name", "topic");
	hiddenField7.setAttribute("value", topicId);
	form.appendChild(hiddenField7);

	if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1  || getChromeVersion() > 55) {
	       document.body.appendChild(form);
	       form.submit();
	       document.body.removeChild(form);
	   } else {
	       form.submit(); // works under IE, neither FF nor Chrome
	   }
}

function onLoginClick(){

    var loginId = $("#loginForm input[name=userName]").val(),
        password = $("#loginForm input[name=password]").val();

    if(loginId.trim() == '' || password.trim() == ""){
        return;
    }
    $.ajax({
      method: "POST",
      url: "https://localgazetteers-test.mpiwg-berlin.mpg.de/lg-api/auth/login",
      data: JSON.stringify({loginId: loginId, password: password}),
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      cache: false,
      headers:{'Cache-Control': 'no-cache'}
    })
    .done(function( data ) {
        window.localStorage.setItem("LG-Token", data.token);
        setAction('login', 'loginForm');
        document.forms['loginForm'].submit();
    })
    .fail(function(obj) {
       alert(obj.responseJSON.message);
      });
}

$(document).ready(function() {
	$('.double-scroll').doubleScroll();

});