Saturday, March 15, 2014


//(function (jQuery) {

//    jQuery.fn.ShowIDPDialog = function () {
//        return this.each(function () {
//            alert("i have added this method");
//        });
//    };

//})(jQuery);



var util = {};
var loadingCounter = 1;
util = {
    ErrorPlacement: function (error, element)
    {
        var container = $('<div />');
        container.addClass('Ntooltip');  // add a class to the wrapper
        error.insertAfter(element);
        var get_width = $(element).width() + parseInt($(element).css('paddingLeft')) + parseInt($(element).css('paddingRight')) + parseInt($(element).css('border-left-width')) + parseInt($(element).css('border-right-width')) + 'px';

        container.attr('style', 'width:' + get_width);
        error.wrap(container);
        $(element).addClass('on-error');
        var offset = $(element).offset();
        var heightOfElement = parseInt($(element).css('height'), 10);
        var top = offset.top - heightOfElement;// $(element).css('height').substring(0, 2);
        var left = offset.left;

        $(error).css('left', $(element).css('left'));
        $(error).css('top', $(element).css('top'));
        $(error).offsetLeft = left;
        $(error).offsetTop = top;
        $("<div class='errorImage'></div>").insertAfter(error);
    },
    HideAllChildActionButton:function()
    {
        if ($(".action-add") != undefined) {
            $(".action-add").toggle();
        }
        if ($(".action-edit") != undefined) {
            $(".action-edit").toggle();
        }
        if ($(".action-delete") != undefined) {
            $(".action-delete").toggle();
        }
        if ($(".action-reload") != undefined) {
            $(".action-reload").toggle();
        }
      
        if ($(".add-icon-for-con") != undefined) {
            $(".add-icon-for-con").parent().toggle();
        }
        if ($(".reload-icon-for-con") != undefined) {
            $(".reload-icon-for-con").parent().toggle();
        }
        if ($(".edit-icon-for-con") != undefined) {
            $(".edit-icon-for-con").parent().toggle();
        }
        if ($(".delete-icon-for-con") != undefined) {
            $(".delete-icon-for-con").parent().toggle();
        }
    },
    GetDataByAjax:function(url)
    {
        var res;
        url = util.FullURLByAction(url);
        $.ajax({
            url: url,
            type: 'GET',
            async: false,
            success: function (result) {

                res= result;
            }
        });
        return res;
    },
    GetEntityTypeForFileManagerName:function(entityId)
    {
       
        var entityTypeData = util.GetDataByAjax('api/ApiCommon/GetEntityDropDownListForFileManager');
        var kIndex = 0;
        for (kIndex; kIndex < entityTypeData.length; kIndex++) {
        
            if (entityTypeData[kIndex].Value == entityId) {
                return entityTypeData[kIndex].Text;
            }
        }
    },
    GenerateKendoAutoCompleteBox:function(element,data,optAuto)
    {
        var options = {
            dataSource: data,
            dataTextField: "Text",
            dataValueField:"Value",
            filter: "startswith",
            placeholder: "Please Select..."
        };
        options = $.extend({}, options, optAuto);
        $(element).kendoAutoComplete(options);
    },
    getSelectedSingleKendoNode:function(element)
    {
        var grid = $(element).data("kendoGrid");
        var selectedRows = grid.select();
        var selectedDataItems = [];
        for (var i = 0; i < selectedRows.length; i++) {
            var dataItem = grid.dataItem(selectedRows[i]);
            selectedDataItems.push(dataItem);
        }
        return selectedDataItems[0];
    },
    getSelectedKendoNodes:function(element)
    {
        var grid = $(element).data("kendoGrid");
        var selectedRows = grid.select("tr");
        var selectedDataItems = [];
        for (var i = 0; i < selectedRows.length; i++) {
            var dataItem = grid.dataItem(selectedRows[i]);
            selectedDataItems.push(dataItem);
        }
        return selectedDataItems;
    },
    getSelectedKendoNodeIds: function (element) {
        var grid = $(element).data("kendoGrid");
        var selectedRows = grid.select();
        var selectedDataItems = [];
        for (var i = 0; i < selectedRows.length; i++) {
            var dataItem = grid.dataItem(selectedRows[i]);
            selectedDataItems.push(dataItem);
        }
        return selectedDataItems;
    },
    getUrlVars: function () {
        var id = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
        return id;
    },
    GetParentFooterDiv:function(name)
    {
        var footerDiv = $(name, window.parent.document);
        if (footerDiv.length > 0) {
            return footerDiv;
        } else {
            return $(name);
        }
    },
    KendoNumericSetValue:function(element,value)
    {
        var numerictextbox = $(element).data("kendoNumericTextBox");
        numerictextbox.value(value);
    },
    DraggableAllIframe:function()
    {
     
        var iframes = $('.iframe-wrapper', top.window.document);
        for (var i = iframes.length; i-- > 0;) {
            var iframe = iframes[i];
            $(iframe).draggable({ handle: $(iframe+ ' .iframe-title')});
        }
    },
    getFrameElement: function () {
     
        if (window.parent == null)
            return null;
        var iframes = parent.document.getElementsByTagName('iframe');
        for (var i = iframes.length; i-- > 0;) {
            var iframe = iframes[i];
            try {
                var idoc = 'contentDocument' in iframe ? iframe.contentDocument : iframe.contentWindow.document;
            } catch (e) {
                continue;
            }
            if (idoc === document)
                return iframe;
        }
        return null;
    },
    GetElement_ById: function (id) {
        var currentFrame = util.getFrameElement();
        if (window.parent == null)
            return null;

        var iframes = $('iframe',top.document);//.getElementsByTagName('iframe');
        for (var i = iframes.length; i-- > 0;) {
            var iframe = iframes[i];
            if ($(iframe).attr("id") === $(currentFrame).attr("_parentId")) {
                var tempElement = $('#' + id, $(iframe).contents());
              //  $('#' + id, $(iframe).contents()).treegrid('reload');
                ///testing
             
                ///
                return $(tempElement);
            }
        }

    
    },
    CallParentFunction: function (f) {
        var currentFrame = util.getFrameElement();
        if (window.parent == null)
            return null;
       

        var iframes = parent.document.getElementsByTagName('iframe');
        for (var i = iframes.length; i-- > 0;) {
            var _iframe = iframes[i];
            if ($(_iframe).attr("id") === $(currentFrame).attr("_parentId")) {
             
                var sp=f.split('.');
                if(sp.length>1){
                    var tempObject = _iframe.contentWindow[sp[0]];
                    if (tempObject == undefined) {
                        return;
                    }
                    tempObject[sp[1]]();
                    return;
                }
                else
                {
                    _iframe.contentWindow[f]();
                    return;
                }
            }
        }
        if (window.parent == top.window) {
            var sp = f.split('.');
            if (sp.length > 1) {
                var tempObject = top.window[sp[0]];
                if (tempObject == undefined) {
                    return;
                }
                tempObject[sp[1]]();
                return;
            }
            else {
                if (top.window[f] == undefined)
                    return;
                top.window[f]();
                return;
            }


        }

      
    },
    SetParentFunction: function (f, id)
    {
        var currentFrame = util.getFrameElement();
        if (window.parent == null)
            return null;
        var iframes = parent.document.getElementsByTagName('iframe');
        for (var i = iframes.length; i-- > 0;) {
            var _iframe = iframes[i];
            if ($(_iframe).attr("id") === $(currentFrame).attr("_parentId")) {

                var sp = f.split('.');
                if (sp.length > 1) {
                    var tempObject = _iframe.contentWindow[sp[0]];
                    tempObject[sp[1]](id);
                    return;
                }
                else {
                    _iframe.contentWindow[f](id);
                    return;
                }
            }
        }
        if (window.parent == top.window) {
            var sp = f.split('.');
            if (sp.length > 1) {
                var tempObject = top.window[sp[0]];
                tempObject[sp[1]](id);
                return;
            }
            else {
                if (top.window[f] == undefined)
                    return;
                top.window[f](id) ;
                return;
            }


        }
     

      
    },
    DialogActions:function()
    {
    
    },
    ShowIFrameDialog:function(options)
    {
       var url = options.url;
       var width = options.Width;
       var title = options.Title;
       var _height = options.Height;
       var _parent = options.parent;
        if (window != top.window) {
            currentIFrame = util.getFrameElement();
            if (currentIFrame != null) {
                _parent = $(currentIFrame).attr('id');
            }
            else {
                _parent = '';
            }
            top.window.util.ShowIFrameDialog(options);
            return;
        }
        var dialogHeight, dialogParentHeight, _parent, framename, currentIFrame;
        if (_height == undefined || _height == 0 || _height == null) {
            dialogHeight = listOperation.heightOfBrowser() - 150;
            dialogParentHeight = window.parent.innerHeight - 150;
            if (dialogParentHeight > dialogHeight) {
                dialogHeight = dialogParentHeight;
            }
        }
        else {
            dialogHeight = _height;
        }
        framename = util.guid();
        var iframe = $("<iframe _parentId='" + _parent + "' name='" + framename + "' frameborder='0' marginwidth='0' src='about:blank' marginheight='0'  allowfullscreen></iframe>");
        iframe.attr("id", framename);
        iframe.attr("src", url);
        dialogHeight = dialogHeight - 10;
        $(iframe).css('height', dialogHeight);
        $(iframe).css('width', width);
        var iframeHolder = $('<div style="position:relative;" class="iframe-wrapper" id="drg' + framename + '" />');
        var iframeInside = $('<div class="iframe-inside" />');
        var iframeTitle = '<div class="iframe-title"><div class="title-line">' + title + '</div><div class="iframe-tools"><a href="javascript:void(0)"' +
            'class="iframe-min"></a><a href="javascript:void(0)" class="iframe-restore disabled"></a><a href="javascript:void(0)" class="iframe-max"></a>'
        + '<a href="javascript:void(0)" class="iframe-close"></a></div></div>' + "<div class='abc' style='display:none; z-index:555555555;width:" + width
        + ";top:35px;left:5px;position:absolute;height:500px;background-color:transparent;'></div>";
        iframeInside.prepend(iframeTitle);
        $(iframe).appendTo(iframeInside);
        iframeInside.appendTo(iframeHolder);
        var footer = $('#divRootFooter');
        if (footer.length > 0) {
            iframeHolder.appendTo(footer);
            $('#drg' + framename).draggable({
                iframeFix: true,
                hander: '#iframe-title',
                cursorAt: {
                    bottom: 33333333333400,
                    top: 400,
                    left: 0,
                    right: 0
                },
                drag: function (event, ui) { alert("dragiing"); },
                start: function (event, ui) {

                    alert("Start");
                    var iframeBlocks = this.document.find("iframe").map(function () {
                        var iframe = $(this);

                        return $("<div>")
                            .css({
                                position: "absolute",
                                width: iframe.outerWidth(),
                                height: iframe.outerHeight()
                            })
                            .appendTo(iframe.parent())
                            .offset(iframe.offset())[0];
                    });
                },
                stop: function (event, ui) {
                    alert("end");
                }
            });
            $('#' + framename, '#drg' + framename).on('load', function () {
                $("#iframeSectionUnique", $("#iframe1").contents()).mousedown(function (e) {
                    //$('#drg' + framename)
                    $('#drg' + framename).draggable().data('draggable')._mouseDown(moveEvent);
                    return false;
                });
            });
            $('#drg' + framename + ' .iframe-title').each(function () {

                $(this).mousedown(function () {
                    $(".abc").css('display', 'inline-block');
                    $(".abc").css('width', width);
                    $(this).children('iframe').hide();
                });
                $(this).mouseup(function () {
                    $(".abc").css('display', 'none');
                    $(".abc").css('width', 0);
                    $(this).children('iframe').hide();
                });
            });

            //util.DialogActions();


        }

        //   util.DraggableAllIframe();
        return framename;
    },

    heightOfBrowser: function () {
        return $(window).height();
    },

    ShowIDPDialog: function (url, width, title, idWidth, Id, _height, _parent) {
       
        if (window != top.window) {
            currentIFrame = util.getFrameElement();
            if (currentIFrame != null) {
                _parent = $(currentIFrame).attr('id');
            }
            else {
                _parent = '';
            }
            top.window.util.ShowIDPDialog(url, width, title, '', Id, _height, _parent);
            return;
        }



        var dialogHeight, dialogParentHeight, _parent, framename, currentIFrame;

        if (_height == undefined || _height == 0 || _height==null) {
            dialogHeight = util.heightOfBrowser() - 150;
            dialogParentHeight = window.parent.innerHeight - 150;
            if (dialogParentHeight > dialogHeight) {
                dialogHeight = dialogParentHeight;
            }
        }
        else {
            dialogHeight = _height;
        }

        framename = util.guid();
      

      
        var iframe = $("<iframe _parentId='" + _parent + "' name='" + framename + "' frameborder='0' marginwidth='0' src='about:blank' marginheight='0'  allowfullscreen></iframe>");
        iframe.attr("id", framename);
        iframe.attr("src", url);
        dialogHeight = dialogHeight - 10;
        $(iframe).css('height', dialogHeight);
        $(iframe).css('width', width);
        var iframeHolder = $('<div style="position:relative;" class="iframe-wrapper" id="drg' + framename + '" />');
        var iframeInside = $('<div class="iframe-inside" />');
        var iframeTitle = '<div class="iframe-title"><div class="title-line">' + title + '</div><div class="iframe-tools"><a href="javascript:void(0)"' +
            'class="iframe-min"></a><a href="javascript:void(0)" class="iframe-restore disabled"></a><a href="javascript:void(0)" class="iframe-max"></a>'
        + '<a href="javascript:void(0)" class="iframe-close"></a></div></div>' + "<div class='abc' style='display:none; z-index:555555555;width:" + width
        + ";top:35px;left:5px;position:absolute;height:500px;background-color:transparent;'></div>";
        iframeInside.prepend(iframeTitle);


        $(iframe).appendTo(iframeInside);
        iframeInside.appendTo(iframeHolder);
     
   
        var footer = $('#divRootFooter');
        if (footer.length > 0) {
            iframeHolder.appendTo(footer);
         
         
        
            $('#drg' + framename).draggable({
                iframeFix: true,
                hander: '#iframe-title',
                cursorAt: {
                    bottom: 33333333333400,
                    top: 400,
                    left: 0,
                    right:0
                },
                drag: function (event, ui) { alert("dragiing"); },
                start: function (event, ui) {
                
                    alert("Start");
                    var iframeBlocks = this.document.find("iframe").map(function () {
                        var iframe = $(this);

                        return $("<div>")
                            .css({
                                position: "absolute",
                                width: iframe.outerWidth(),
                                height: iframe.outerHeight()
                            })
                            .appendTo(iframe.parent())
                            .offset(iframe.offset())[0];
                    });
                },
                stop: function (event, ui) {
                
                    alert("end");
                }
            });
            $('#' + framename, '#drg' + framename).on('load', function () {


                $("#iframeSectionUnique", $("#iframe1").contents()).mousedown(function (e) {
                    //$('#drg' + framename)
                    $('#drg' + framename).draggable().data('draggable')._mouseDown(moveEvent);
                    return false;
                });
            });
            $('#drg' + framename + ' .iframe-title').each(function () {
             
                $(this).mousedown(function () {
                    $(".abc").css('display', 'inline-block');
                    $(".abc").css('width', width);
                    $(this).children('iframe').hide();
                });
                $(this).mouseup(function () {
                    $(".abc").css('display', 'none');
                    $(".abc").css('width', 0);
                    $(this).children('iframe').hide();
                });
            });
           
            $('#drg' + framename).on("remove", function () {
               // top.window.util.ReloadRecentActivity();
            })
          
         
        }
         
       
     //   util.DraggableAllIframe();
        return framename;
    },
    ReloadRecentActivity:function(){
        $('#tblActivityList').data('kendoGrid').dataSource.read();
    },
    //ShowInnerIFrame: function (url) {
    //    // dialogObject.core.CheckSession();
    //    var dialogHeight = listOperation.heightOfBrowser() - 150;
    //    var name = util.guid();
    //    var iframe = $('<iframe  name=' + name + ' frameborder="0" marginwidth="0" src="about:blank" marginheight="0" allowfullscreen></iframe>');
    //    iframe.attr("id", name);
    //    iframe.attr("src", url);
    //    $(iframe).css('height', dialogHeight);
    //    $(iframe).css('width', width);
    //    var uniqueId = util.GetUniqueId('a', 'aa');

    //    var iframeHolder = $('<div class="iframe-wrapper" />');
    //    var iframeInside = $('<div class="iframe-inside" />');

    //    // Set Header

    //    var iframeTitle = '<div class="iframe-title"><div class="title-line">' + title + '</div><div class="iframe-tools"><a href="javascript:void(0)"' +
    //        'class="iframe-min"></a><a href="javascript:void(0)" class="iframe-restore disabled"></a><a href="javascript:void(0)" class="iframe-max"></a>'
    //    + '<a href="javascript:void(0)" class="iframe-close"></a></div></div>';

    //    iframeInside.prepend(iframeTitle);
       
       
    //    $(iframe).appendTo(iframeInside);
    //    iframeInside.appendTo(iframeHolder);
     
    //    var footer = $('iframe').parent().find('footer');
    //    if (footer == undefined) {
    //        iframeHolder.appendTo('footer');
    //    } else {
    //        iframeHolder.appendTo(footer);
    //    }
    //    //  $('body', $(iframe).document).append(projectId);

    //    //$(iframe).appendTo(uniqueId);
    //},
    GetUniqueId: function (divIdprefix,className)
    {
        var objGuid = divIdprefix + util.guid();
        var divGuid = "div#" + objGuid;
        var div = $("<div class='" + className + "' id=" + objGuid + "></div>");
        var li = $("<li></li>").append(div);
        li.appendTo($("#ulMinimizeBar"));
        return divGuid;
    },
    GetParentWindowUniqueId: function (className) {
        var listOfWindow = $(".panel.window");
        var wrapDivId = "";
        var highestZIndex = 0;
        $.each(listOfWindow, function (index, elem) {
            if (highestZIndex < $(elem).css('z-index')) {
                if (className != "undefined" || className != "") {
                    if ($(elem).find('.panel-body.panel-body-noborder.window-body').hasClass(className)) {
                        wrapDivId = $(elem).find('.panel-body.panel-body-noborder.window-body').attr('id');
                    }
                }
                else {
                    wrapDivId = $(elem).find('.panel-body.panel-body-noborder.window-body').attr('id');
                }
            }
        });
        if (wrapDivId != "") {
            wrapDivId = 'div#' + wrapDivId + ' ';
        }
        return wrapDivId;
    },
    GetURLParameter: function (sParam) {
        var sPageURL = window.location.search.substring(1);
        var sURLVariables = sPageURL.split('&');
        for (var i = 0; i < sURLVariables.length; i++) {
            var sParameterName = sURLVariables[i].split('=');
            if (sParameterName[0] == sParam) {
                return sParameterName[1];
            }
        }
    },
    GetRemoteData: function (url) {
        var htmlData;
       
        if (url.indexOf("http") < 0) {
            var baseUrl = util.GetBaseUrl();
            url = "http://" + baseUrl + "/" + url;
        }
        $.ajax({
            url: url,
            type: 'GET',
            dataType: 'html',
            context: document.body,
            processData :false,
            async: false,
            success: function (result) {
               // var result = $.parseHTML(result,document,true);
                htmlData = result;
            }
        });

        return htmlData;
    },
    FormateJSDate: function (dt) {
      
        if (dt === undefined)
            return;
        var numDate = new Date(parseInt(dt.substr(6)));
        var val = (numDate.getMonth() + 1) + "/" + numDate.getDate() + "/"  +numDate.getFullYear();
        return val;

     
    },
    formatStatus: function (val, row) {
        if (val == true) {
            return 'Active';
        } else {
            return 'Inactive';
        }

    },
    FormateDate: function (dt) {
        numDate = new Date(dt);
        var formatedDate =  (numDate.getMonth() + 1)  + "/" + numDate.getDate()  +  "/" + numDate.getFullYear();
        return formatedDate;
    },
    FormateDateForQuery: function (dt) {
      
        numDate = new Date(dt);
        var formatedDate = (numDate.getMonth() + 1) + "/" + numDate.getDate() + "/" + numDate.getFullYear();
        return formatedDate;
    },
    //Active?
    convertTrueFalse: function (val, row) {

        if (val == 'true') {
            return 'Yes';
        } else {

            return 'No';
        }

    },
    FormateDates: function (val, row) {

        if (val == null) {
            val = "";
            return val;
        }
        var numDate = eval("new " + val.slice(1, -1));
        var val = numDate.getDate() + "/" + (numDate.getMonth() + 1) + "/" + numDate.getFullYear();
        return val;
    },
    OnlyDate: function (val, row) {

        if (!val) {
            val = "";
            return val;
        }
        if (val == null) {
            val = "";
            return val;
        }
        var numDate = new Date(val);

        var val = numDate.getDate() + "/" + (numDate.getMonth() + 1) + "/" + numDate.getFullYear();
        return val;
    },
    FormateAmount: function (val, row) {
        if (val == 0) {
            return '0.00';
        }
        val = "$" + val;
        return val;
    },
    SetKendoComboByData: function (element, asyncBool, optsKendoDdl) {
        var asBoolData = false;
        if (asyncBool == undefined || asyncBool === null) {
            asBoolData = false;
        } else {
            asBoolData = asyncBool;
        }
   
        var baseUrl = util.GetBaseUrl();
  
        optsKendoDdl.url = "http://" + baseUrl + "/" + optsKendoDdl.url;
        $.ajax({
            url: optsKendoDdl.url,
            type: 'GET',
            async: asBoolData,
            success: function (result) {
              
                util.SetEasyComboByArrayData_ByOptions(element, result, optsKendoDdl);
            }
        });
    },
    SetComboByData: function (action, element, asyncBool, placeholder) {
        var asBoolData = false;
        if (asyncBool == undefined || asyncBool === null) {
            asBoolData = false;
        } else {
            asBoolData = asyncBool;
        }
     
        var baseUrl = util.GetBaseUrl();
        baseUrl = "http://" + baseUrl + "/" + action;
        $.ajax({
            url: baseUrl,
            type: 'GET',
            async: asBoolData,
            success: function (result) {
              
                util.SetEasyComboByArrayData(element, result, placeholder);
            }
        });
    },
    SetComboByDataTemplate: function (action, element, asyncBool, placeholder, template, dataField) {
    
        var asBoolData = false;
        if (asyncBool == undefined || asyncBool === null) {
            asBoolData = false;
        } else {
            asBoolData = asyncBool;
        }
     
        var baseUrl = util.GetBaseUrl();
        baseUrl = "http://" + baseUrl + "/" + action;
        $.ajax({
            url: baseUrl,
            type: 'GET',
            async: asBoolData,
            success: function (result) {
                util.GenerateKendoGridWithTemplate(element, result, placeholder, template, dataField);
            }
        });
    },
    GenerateKendoGridWithTemplate: function (element, arr, _placeholder, _template, dataField) {
      
        if (_placeholder == undefined)
            _placeholder = '';

        $(element).kendoDropDownList({
            dataTextField: dataField,
            dataValueField: "Value",
            dataSource: arr,
            filter: "contains",
            suggest: true,
            placeHolder: _placeholder,
            template: _template
        });

        return $(element).data("kendoDropDownList");
    },
    GenerateFullURL: function (baseUrl,action)
    {
        baseUrl = "http://" + baseUrl + "/" + action;
        return baseUrl;
    },
    FullURLByAction: function (action)
    {
    
        if (action.indexOf("http") > -1)
            return action;
        else {
            var baseUrl = util.GetBaseUrl();
            baseUrl = "http://" + baseUrl + "/" + action;
            return baseUrl;
        }
    },

    SetEasyComboByArrayData: function (element, arr, _placeholder) {
        if (_placeholder == undefined)
            _placeholder = '';
        $(element).kendoDropDownList({
            dataTextField: "Text",
            dataValueField: "Value",
            dataSource:arr,
            filter: "contains",
            suggest: true,
            placeHolder:_placeholder
        });
        return $(element).data("kendoDropDownList");
    },
    SetEasyComboByArrayData_ByOptions: function (element, arr, opts) {
     
        var checkElement = $(element).data("kendoDropDownList");
        if (checkElement != undefined || checkElement != null) {
           
            $(element).data("kendoDropDownList").setDataSource(arr);
        }
        else {
            var options = {
                dataTextField: "Text",
                dataValueField: "Value",
                dataSource: arr,
                filter: "contains",
                suggest: true

            };
            options = $.extend({}, options, opts);
            $(element).kendoDropDownList(options);
            return $(element).data("kendoDropDownList");
        }
    },
    SetKendoCombo: function (element, arr, opts) {
     
        var options = {
            dataTextField: "Text",
            dataValueField: "Value",
            dataSource: arr,
            filter: "contains",
            suggest: true
          
        };
        options = $.extend({}, options, opts);
        $(element).kendoComboBox(options);
        return $(element).data("kendoComboBox");
    },
    SetKendoValue:function(element,val)
    {
        var elementKendo = $(element).data("kendoDropDownList");
        if (elementKendo != null) {
            elementKendo.value(val);
        }
    },
    SetKendoComboValue: function (element, val) {
        var elementKendo = $(element).data("kendoComboBox");
        if (elementKendo != null) {
            elementKendo.value(val);
        }
    },
    RefreshKendoComboBox:function(form)
    {
        $(form).find('input').each(function()
        {
            if ($(this).data("kendoDropDownList")) {
                $(this).data("kendoDropDownList").value('Please Select...');
            }
        });
    },
    RefreshTextBox: function (form) {

        $(form).find('input').each(function () {
            if ($(this).data("text")) {
              
                $(this).value('');

            }

        });
    },
    SetUrgencyData: function (element) {
       var arr = [
                { Value: 'Normal', Text: 'Normal' },
                { Value: 'Urgent', Text: 'Urgent' }

        ];

        util.SetEasyComboByArrayData(element, arr);
    },
    SetAssignTypeData: function (element,place) {
       var arr = [
            { Value: 'Please Select...', Text: 'Please Select...' },
               { Value: 'Person', Text: 'Person' },
               { Value: 'Role', Text: 'Role' },
                { Value: 'Queue', Text: 'Queue' }

        ];
        util.SetEasyComboByArrayData(element, arr, place);
    },
    SetContactRoleCategory: function (element, place) {
      
       var arr = [
               { Value: 'Client', Text: 'Client' },
               { Value: 'Internal', Text: 'Internal' },
               { Value: 'Third Party', Text: 'Third Party' },
               { Value: 'Other', Text: 'Other' }
        ];
        util.SetEasyComboByArrayData(element, arr, place);
    },
    SetDefaultStatus: function (element, place) {
       var arr = [
            { Value: 'Please Select...', Text: 'Please Select...' },
            { Value: 'Not Started', Text: 'Not Started' },
            { Value: 'Assigned To Person', Text: 'Assigned To Person' },
            { Value: 'Hold', Text: 'Hold' },
            { Value: 'Completed', Text: 'Completed' },
            { Value: 'Cancelled', Text: 'Cancelled' },
            { Value: 'Ready to Start', Text: 'Ready to Start' },
             { Value: 'Not Ready', Text: 'Not Ready' }];

           
        util.SetEasyComboByArrayData(element, arr, place);
    },
    SetElaspsedDay: function (element, place) {
       var arr = [
               { Value: 'Please Select...', Text: 'Please Select...' },
               { Value: 'Business Day', Text: 'Business Day' },
               { Value: 'Elapsed Day', Text: 'Elapsed Day' }

        ];
        util.SetEasyComboByArrayData(element, arr, place);
    },
   
    SetFrequencyMethodData: function (element) {
        arr = [
             { Value: 'Please Select...', Text: 'Please Select...' },
               { Value: 'Weekly', Text: 'Weekly' },
               { Value: 'Bi-Weekly', Text: 'Bi-Weekly' },
                { Value: 'Bi-Weessskly', Text: 'Bi-Weekly' }

        ];
        util.SetEasyComboByArrayData(element, arr);
    },

    SetClientRankingData: function (element) {
       var arr = [
               { Value: 'Platinum', Text: 'Platinum' },
               { Value: 'Gold', Text: 'Gold' },
                { Value: 'Silver', Text: 'Silver' }

        ];
        util.SetEasyComboByArrayData(element, arr);
    }, SetServiceAlertData: function (element) {
       var arr = [
               { Value: 'Green', Text: 'Green' },
               { Value: 'Yello', Text: 'Yello' },
                { Value: 'Red', Text: 'Red' }

        ];
        util.SetEasyComboByArrayData(element, arr);

    },
    buildTreeGrid: function ($el, opts) {

        var options = {
            idField: 'Id',
            height: 350,
            // treeField: 'Units',
            rownumbers: true,
            animate: true,
            fitColumns: true,
            //striped: true,
            loadMsg: "Loading data...",
            //loadFilter: util.pagerFilter,

            displayMsg: "",

            onBeforeLoad: function (row, param) {
                if (!row) { // load top level rows 
                    param.id = 0;   // set id=0, indicate to load new page rows 
                }
            }

        };


        options = $.extend({}, options, opts);

        $el.treegrid(options);
    },
    buildDataGrid: function ($el, opts) {

        var options = {
            idField: 'Id',
            height: 350,



            fitColumns: true,
            striped: true,

            striped: true,
            method: "get"



            //onBeforeLoad: function (row, param) {
            //    if (!row) { // load top level rows 
            //        param.id = 0;   // set id=0, indicate to load new page rows 
            //    }
            //}

        };


        options = $.extend({}, options, opts);

        $el.datagrid(options);
    },
    pagerFilter: function (data) {
        if ($.isArray(data)) {
            data = {
                total: data.length,
                rows: data
            }
        }
        var dg = $(this);
        var state = dg.data('treegrid');
        var opts = dg.treegrid('options');
        var pager = dg.treegrid('getPager');
        pager.pagination({
            displayMsg: "",
            onSelectPage: function (pageNum, pageSize) {
                opts.pageNumber = pageNum;
                opts.pageSize = pageSize;
                pager.pagination('refresh', {
                    pageNumber: pageNum,
                    pageSize: pageSize,
                    displayMsg: ""
                });
                dg.treegrid('loadData', data);
            }
        });
        if (!data.topRows) {
            data.topRows = [];
            data.childRows = [];
            for (var i = 0; i < data.rows.length; i++) {
                var row = data.rows[i];
                row._parentId ? data.childRows.push(row) : data.topRows.push(row);
            }
            data.total = (data.topRows.length);
        }
        var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
        var end = start + parseInt(opts.pageSize);
        data.rows = $.extend(true, [], data.topRows.slice(start, end).concat(data.childRows));
        return data;
    },
    formatDollar: function (value, row) {

        if (value) {
            return '$' + value;
        } else {
            return '';
        }
    }, OpenModal: function (elementId) {

   
        $(elementId).window({
            collapsible: false,
            title: 'Portal Configuration',
            width: 450,
            height: 260,
            closed: false,
            cache: false,
            modal: true,
            onLoad: function () {
                // AccountDialog.RefreshPage();
            }


        });
    },
    s4: function () {
        return Math.floor((1 + Math.random()) * 0x10000)
                   .toString(16)
                   .substring(1);
    },

    guid: function () {
        return util.s4() + util.s4();
    },
    ShowErrorMessage: function (title,msg) {
      
      
    },
    CloseIFrame: function () {
      
        var currIframe = util.getFrameElement();
        $(currIframe).closest('.iframe-wrapper').remove();
    },
    GetBaseUrl: function () {
        try {
            var url = location.href;

            var start = url.indexOf('//');
            if (start < 0)
                start = 0
            else
                start = start + 2;

            var end = url.indexOf('/', start);
            if (end < 0) end = url.length - start;

            var baseURL = url.substring(start, end);
            return baseURL;
        }
        catch (arg) {
            return null;
        }
    }



}

No comments:

Post a Comment