﻿//declaration of perfunkt core type
$.pf = $.pf || { data: {}, jsonRepeater: {}, videoItem: {}, videoDetailPage: {}, floatingMenu: {}, dialogs: {} };

data = {
    dataType: null,
    method: null,
    url: null,
    responseData: null,
    callbackEvent: null,
    payload: null,

    handle: function() {
    if (arguments[0].d.ResponseStatus === 200) {               
            $(window).trigger(this.callback, [arguments[0].d.Response]);
        } else {
            $.pf.data.handleError(arguments[0].d.ResponseStatus + ' => ' + arguments[0].d.ResponseMessage);
        }
    },

    reset: function() {
        this.dataType = null;
        this.method = null;
        this.url = null;
        this.payload = null;
        this.responseData = null;
        this.callbackEvent = null;
    },

    doJsonGet: function(callbackEvent) {
        $.ajax({
            url: '/ui/scripts/services/service.aspx',
            type: 'get',
            dataType: 'json',
            callback: callbackEvent,
            success: $.pf.data.handle
        });
    },

    doJsonPost: function(callbackEvent, payload) {
        $.ajax({
            url: '/Additions/services/ClientDataTransferService.asmx/GetData',
            type: 'post',
            dataType: 'json',
            contentType: 'application/json',
            data: $.toJSON({ complexCommands: $.toJSON(payload), languageId: $("#_hidden-language").val() }),
            callback: callbackEvent,
            success: $.pf.data.handle
        });
    },

    handleError: function(err) {
        throw new Error(err);
    }
};

$.extend(true, $.pf.data, data);


