Monday, 8 February 2016

returnjson

var Type;
var Url;
var Data;
var ContentType;
var DataType;
var ProcessData;
var UserLoginID;
var QuestionTitle;
var QuestionDesc;
var ExamID;
var TagID;
var Examname;
var PageIndex = 1, pageSize = 10, pageCount = 5;
var pages;

$(document).ready(function () {
    $(".pagination").hide();
    GetRecentQues();
    GetAllTags();
    GetExamForSelection();
    getautocompletetag();
    getArtists(PageIndex);
    //$("#fileupload").hide();
    if (getUrlVars()["title"]) {
        document.getElementById("txtTitle").value = getUrlVars()["title"];
    }
    if (getUrlVars()["ques"]) {
        document.getElementById("txtDesc").value = getUrlVars()["ques"];
    }
});

function getArtists(index) {
    $(".pagination").show();
    GetAllQuestion(index);
}

function AddQuesMaster(examId) {
    if (document.getElementById("fileslist")) {
        var questionid = document.getElementById("fileslist").value;
    }
    var UserLoginID = 1;
    ExamID = document.getElementById("txtExams").value;
    QuestionTitle = document.getElementById("txtTitle").value;
    QuestionDesc = document.getElementById("txtDesc").value;
    TagID = document.getElementById("txtTag").value;
 //   console.log(TagID);
    var parms = '{"userId":"' + UserLoginID + '","examId":"' + ExamID + '","questionTitle":"' + QuestionTitle + '","questionDesc":"' + QuestionDesc + '","tagId":"' + TagID + '","questionId":"' + questionid + '"}';
    //console.log(abc);
    Type = "POST";
    Url = questionanswersservicepath + "/AddQuestionMaster";
    Data = parms;
    ContentType = "application/json; charset=utf-8";
    DataType = "json"; ProcessData = false;
    // GetInsprofile();
    $.ajax({
        type: Type, //GET or POST or PUT or DELETE verb
        url: Url, // Location of the service
        data: Data, //Data sent to server
        contentType: ContentType, // content type sent to server
        dataType: DataType, //Expected data format from server
        processdata: ProcessData, //True or False
        success: function (msg) {
            $("#txtExams").tokenInput("clear");
            $("#txtTag").tokenInput("clear");
            document.getElementById("txtTitle").value = "";
            document.getElementById("txtDesc").value = "";
            alert('Question Submitted');
        },
        error: function ()
        { console.log('there is some error'); } // When Service call fails
    });
}
function InsertQuesMaster(loginId, questionTitle, questionDesc) {
    var UserLoginID = loginId;
    ExamID = 0;
    QuestionTitle = questionTitle;
    QuestionDesc = questionDesc;
    TagID = 0;
    var parms = '{"userId":"' + UserLoginID + '","examId":"' + ExamID + '","questionTitle":"' + QuestionTitle + '","questionDesc":"' + QuestionDesc + '","tagId":"' + TagID + '","questionId":"' + questionid + '"}';

    //var parms = '{"userID":"' + UserLoginID + '","ExamID":"' + ExamID + '","QuestionTitle":"' + QuestionTitle + '","QuestionDesc":"' + QuestionDesc + '","TagID":"' + TagID + '","QuestionID":"' + questionid + '"}';
    //console.log(abc);
    Type = "POST";
    Url = questionanswersservicepath + "/AddQuestionMaster";
    Data = parms;
    ContentType = "application/json; charset=utf-8";
    DataType = "json"; ProcessData = false;
    // GetInsprofile();
    $.ajax({
        type: Type, //GET or POST or PUT or DELETE verb
        url: Url, // Location of the service
        data: Data, //Data sent to server
        contentType: ContentType, // content type sent to server
        dataType: DataType, //Expected data format from server
        processdata: ProcessData, //True or False
        success: function (msg) {
            alert('Question Submitted');
        },
        error: function ()
        { console.log('there is some error'); } // When Service call fails
    });
}
function GetInsprofile() {
    $.ajax({
        type: Type, //GET or POST or PUT or DELETE verb
        url: Url, // Location of the service
        data: Data, //Data sent to server
        contentType: ContentType, // content type sent to server
        dataType: DataType, //Expected data format from server
        processdata: ProcessData, //True or False
        success: function (msg) {//On Successfull service call
            var dats = eval(msg.SelectInstituteAboutusDetailsResult);
            //  console.log(dats);
            $.each(dats, function (i, dat) {
                //console.log(dat.About);
                document.getElementById('About').innerHTML = dat.About;
                document.getElementById('Value').innerHTML = dat.Value;
                document.getElementById('Mission').innerHTML = dat.Mission;
                document.getElementById('centers').setAttribute("src", dat.ImgCenters);
                document.getElementById('winners').setAttribute("src", dat.ImgWinners);
                document.getElementById('learning').setAttribute("src", dat.ImgLearning);
            });
        },
        error: function ()
        { console.log('there is some error'); } // When Service call fails
    });
}


function GetExam() {
    $.ajax({
        type: Type, //GET or POST or PUT or DELETE verb
        url: Url, // Location of the service
        data: Data, //Data sent to server
        contentType: ContentType, // content type sent to server
        dataType: DataType, //Expected data format from server
        processdata: ProcessData, //True or False
        success: function (msg) {//On Successfull service call
            var dats = eval(msg.GetExamsForSelectResult);
            console.log(dats);
            $("#txtExams").tokenInput(dats, {
                theme: "facebook"
            });
        },
        error: function ()
        { console.log('there is some error'); } // When Service call fails
    });
}

function getautocompletetag() {
    $.ajax({
        type: "POST", //GET or POST or PUT or DELETE verb
        url: questionanswersservicepath + "/GetTagsForSelect", // Location of the service
        data: '{}', //Data sent to server
        contentType: "application/json; charset=utf-8", // content type sent to server
        dataType: "json", //Expected data format from server
        processdata: false, //True or False  
        success: function (msg) {//On Successfull service call
            var dats = eval(msg.GetTagsForSelectResult);
            $("#txtTag").tokenInput(dats, {
                theme: "facebook"
            });
        },
        error: function ()
        { console.log('there is some error'); } // When Service call fails
    });
}

function GetExamForSelection() {
    var Examname = document.getElementById("txtExams").value;
    // alert(Examname);
    var abc = '{"examName":"' + Examname + '"}';
    //console.log(abc);
    Type = "POST";
    Url = questionanswersservicepath + "/GetExamsForSelect";
    Data = abc;
    ContentType = "application/json; charset=utf-8";
    DataType = "json"; ProcessData = false;
    GetExam();
}


function GetRecentQues() {
    Type = "POST";
    Data = '{}';
    Url = questionanswersservicepath + "/GetQuestions";
    ContentType = "application/json; charset=utf-8";
    DataType = "json"; ProcessData = false;
    GetQues();
}


function GetQues() {
    $.ajax({
        type: Type, //GET or POST or PUT or DELETE verb
        url: Url, // Location of the service
        data: Data, //Data sent to server
        contentType: ContentType, // content type sent to server
        dataType: DataType, //Expected data format from server
        processdata: ProcessData, //True or False
        success: function (msg) {//On Successfull service call
            // console.log(msg);
            var result = eval(msg.GetQuestionsResult);
        //    console.log(result);
            $.each(result, function (i, dat) {
                $('#output').append('<li><a>"' + dat.QuestionTitle + '"</a></li>');
            });
        },
        error: function ()
        { console.log('there is some error'); } // When Service call fails
    });
}


function GetAllQuestion(index) {
    pageIndex = index;
    Type = "POST";
    Data = '{"pageIndex":"' + PageIndex + '","pageSize":"' + pageSize + '"}';
    Url = questionanswersservicepath + "/GetAllQuestions";
    ContentType = "application/json; charset=utf-8";
    DataType = "json"; ProcessData = false;
    GetAllQues();
}


function GetAllQues() {
    $.ajax({
        type: Type, //GET or POST or PUT or DELETE verb
        url: Url, // Location of the service
        data: Data, //Data sent to server
        contentType: ContentType, // content type sent to server
        dataType: DataType, //Expected data format from server
        processdata: ProcessData, //True or False
        success: function (msg) {//On Successfull service call
         //   console.log(msg);
            var result1 = eval(msg.GetAllQuestionsResult);
            //            console.log(JSON.stringify(msg));
            //            console.log(JSON.stringify(result1));
            //          
            //            console.log(result1);
            //$.each(result1, function (i, dat) {

            $('#outputall').html('');
            $('#paging').html('');
         
            for (var i = 0; i < result1.length - 1; i++) {
                $('#outputall').append(
                        '<div class="question-box">' +
                            '<div class="qus-user">' +
                                '<img src="' + result1[i].Image + '"></div>' +
                                    '<a href="QuestionAnswerDetails.aspx?quesid=qs-' + result1[i].questionid + '">' + result1[i].questionTitle + '</a></div>' +
                                        '<hr style="margin-bottom: 10px; margin-top: 10px;">');
                pages = result1[i + 1].NoOfPages;
            } if (PageIndex != 1) {
                $('#paging').append('<li><a href="#" onclick="previous();">Prev</a></li>');
            }
            $('#paging').append('<li><a href="#" onclick="pagecall(' + PageIndex + ');">' + PageIndex + '</a></li>');
            //                for (var j = PageIndex; j <= pages; j++) {
            //                  
            //                    $('#paging').append('<li><a href="#" onclick="pagecall(' + j + ');">' + j + '</a></li>');
            //                }
            $('#paging').append('<li><a> of </a></li>');
            $('#paging').append('<li><a>' + pages + '</a></li>');
            if (PageIndex != pages) {
                $('#paging').append('<li><a href="#" onclick="next();">Next</a></li>');
            }
        },
        error: function ()
        { console.log('there is some error'); } // When Service call fails
    });
}

function previous() {
    if (PageIndex != 1) {
        PageIndex = PageIndex - 1;
    }
    GetAllQuestion(PageIndex);
}

function pagecall(index) {
    PageIndex = index;
    GetAllQuestion(index);
}

function next() {
    PageIndex = PageIndex + 1;
    //    if (pageSize = (pageIndex - 5)) {
    //        pageCount = pageIndex - 5;
    //    }
    GetAllQuestion(PageIndex);
}

function GetAllTags() {

    Type = "POST";
    Data = '{}';
    Url = questionanswersservicepath + "/GetTags";
    ContentType = "application/json; charset=utf-8";
    DataType = "json"; ProcessData = false;
    GetTags();
}

function GetTags() {
    $.ajax({
        type: Type, //GET or POST or PUT or DELETE verb
        url: Url, // Location of the service
        data: Data, //Data sent to server
        contentType: ContentType, // content type sent to server
        dataType: DataType, //Expected data format from server
        processdata: ProcessData, //True or False
        success: function (msg) {//On Successfull service call
         //   console.log(msg);
            var resultTag = eval(msg.GetTagsResult);

            $.each(resultTag, function (i, dat) {
                $('#outputTag').append('<li><a href="#">' + dat.Tag_Name + '</a></li>'
                );

            });
        },
        error: function ()
        { console.log('there is some error'); } // When Service call fails
    });
}

function attachfile() {
    $("#fileupload").show();
}

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

No comments:

Post a Comment