infodosar.ro Open in urlscan Pro
84.239.8.77  Public Scan

URL: http://infodosar.ro/rulare/search/ui.js
Submission: On February 01 via api from ES — Scanned from ES

Form analysis 0 forms found in the DOM

Text Content

namespace("app");
function showmodal(title,data){
	$('.modalwindow, .modaloverlay').remove();

	$('body').prepend('<div class="modaloverlay"></div><div class="modalwindow"><div><div class="modaltitle">'+title+'<i class="glyphicon glyphicon-remove closemodal"></i></div>'+data+'</div></div>');
	attachPicker();
	$('.modalwindow .modaltitle i').click(function(){
		$('.modalwindow, .modaloverlay').remove();
		return false;
	});
}
app.ui = function () {
    var ajaxRequest = {
        url: '',
        dataParam: null,
        methodType: 'POST',
        successFunction: function () { },
        errorFunction: function () { },
        contentType: 'application/json',
        performRequest: function () {
            var _this = this;
			if(_this.methodType.toLowerCase()=='post'){
				_this.dataParam=JSON.parse(_this.dataParam);
			}
            return $.ajax({
                url: _this.url,
                type: _this.methodType,
                datatype: _this.contentType,
                data: _this.dataParam,
                success: _this.successFunction,
                error: _this.errorFunction
            });
        }
    };

    var accordion = function (multipleexpand, selector) {
        multipleexpand = multipleexpand || false;
        selector = selector || ".accordion-menu";
        $(selector).find('> li').click(function () {
            var $this = $(this);
            if ($this.hasClass('active')) {
                return false;
            }
            if (!multipleexpand) {
                $this.parent().find('> li.active').removeClass('active');
            }
			
            if ($this.parent().hasClass('accordion-menu')) {
                $this.find('> ul').slideDown(500, function () {
                    $(this).removeAttr('style');
                });				
				
				if($this.find('> ul >li').length>0){
					$this.parent().find('> li > ul >li').removeClass('active-item').unbind('click').click(function () {
						$(this).parent().find('li').removeClass('active-item');
						$(this).addClass('active-item');
						doAjax(this);
						return false;
					});
				}else{	
					 $this.addClass('active');
					doAjax(this);
					return false;
				}
            }
			function doAjax(elem){
				var href = $(elem).find('>a').attr('href');
						var request = app.ui().ajaxRequest;
						setProperties({
							url: href,
							successFunction: function (e) {
								$('#maincontainer').html(e);
								attachPicker();
							},
							methodType: 'GET'
						},
						request, '');
						request.performRequest();
			}
            $this.addClass('active');
            return false;
        });
    };

    var grid = {
        gridSelector: '',
        readInputValue: function (selector) {
            return $(selector).val();
        },
        pagination: {
            PageNumber: 0,
            PageSizeIndex: 2,
            OrderBy: '',
            SordDirection: 'asc'
        },
        searchParameters: {},
        pageSizes: [5, 10, 20, 50, 100],
        fields: {},
        primaryKey: '',
        datasource: {
            data: [],
            total: 0,
            serverPagination: true,
            url: '',
            read: function (parent) {
                var _this = parent;
                var dataParam = new Object();
                dataParam.SearchPaginated = {
                    PageNumber: _this.pagination.PageNumber,
                    RowsPerPage: _this.pageSizes[_this.pagination.PageSizeIndex],
                    OrderBy: _this.pagination.OrderBy == '' ? null : _this.pagination.OrderBy,
                    SordDirection: _this.pagination.SordDirection,
                }

                for (var property in _this.searchParameters) {
                    dataParam[property] = $(_this.searchParameters[property]).val();
                }

                var request = app.ui().ajaxRequest;
                setProperties({
                    url: this.url,
                    contentType: 'application/json',
                    successFunction: function (e) {
						setTimeout(function(){
							setTimeout(function(){
								$('body').removeClass('loadingrecords');
							},50);
						},500);
                        _this.datasource.data = e.Records;
                        _this.datasource.total = e.Total;
                        _this.datasource.displayData(_this);
						
                    },
					errorFunction:function(e){
						setTimeout(function(){
							$('body').removeClass('loadingrecords');
						},50);
						if(e.status==200 && e.readyState==4){
							e=JSON.parse(e);
							 _this.datasource.data = e.Records;
							_this.datasource.total = e.Total;
							_this.datasource.displayData(_this);
						}
					},
                    type: 'GET',
                    dataParam: JSON.stringify(dataParam)
                },
                request, '');				
				
                setTimeout(function(){
					$('body').addClass('loadingrecords');
				},50);
                var rez= request.performRequest();
				
				window['executecache']=function (){
					cachedata();
				}
				function cachedata(){					
					if(rez.readyState!=4){
						setTimeout('executecache();',100);
						return;
					}

					var request = app.ui().ajaxRequest;
					setProperties({
						url: "rulare/search/cachecrtdata.php",
						contentType: 'application/json',
						successFunction: function (e) {						
						},
						type: 'GET',
						dataParam: JSON.stringify(dataParam)
					},
					request, '');
					//request.performRequest();
				}
				setTimeout(function(){executecache();},250);
				return rez;
            },
            setData: function (dataObj, parentobj) {
                this.data = dataObj;
                this.total = data.length;
                this.displayData(parentobj);
            },
            displayData: function (parentobj) {
				setTimeout(function(){
					$('.modalwindow, .modaloverlay').remove();
				},2500);
                var d = this.data;
				
                var gridTable = $(parentobj.gridSelector).find('.data-grid');
                if (gridTable.length == 0) {
                    var h = '';
                    h += '<table class="data-grid">';
                    h += '<tr class="data-grid-header-row">';

                    for (var f in parentobj.fields) {
                        if (parentobj.fields[f].visible !== undefined && parentobj.fields[f].visible == false) {
                            continue;
                        }
                        var sortable = false;
                        if (parentobj.fields[f].sortable === undefined || parentobj.fields[f].sortable == true) {
                            sortable = true;
                        }
						var colwidth="";
						if (parentobj.fields[f].width) {
                            colwidth= 'style="width:'+parentobj.fields[f].width+'px;"';
                        } 
						
                        h += '<td field-name="' + parentobj.fields[f].name + '" '+colwidth+'>';
                        h += '<span class="' + (sortable ? "sotable-col" : "") + '"><span>';
                        if (!parentobj.fields[f].display) {
                            h += parentobj.fields[f].name;
                        } else {
                            h += parentobj.fields[f].display;
                        }
						
                        h += '</span>';
                        if (sortable == true) {
                            h += '<i class="sort-data notsorted"></i>';
                        }
                        h += '</span>';
                        h += '</td>';
                    }

                    h += '</tr>';
                    $(parentobj.gridSelector).append(h);
                    gridTable = $(parentobj.gridSelector).find('.data-grid');
                    if (parentobj.pagination.OrderBy !== undefined && parentobj.pagination.OrderBy != '') {
                        var sortCol = gridTable.find('.data-grid-header-row td[field-name="' + parentobj.pagination.OrderBy + '"');
                        sortCol.removeClass('notsorted').addClass('sortcol' + parentobj.pagination.OrderBy);
                    }
                }

                var colsCount = 0;
                for (var f in parentobj.fields) {
                    if (!parentobj.fields[f].visible || parentobj.fields[parentobj.primaryKey].visible == true) {// if not setted or setted to true
                        colsCount++;
                    }
                }
                gridTable.find('.data-grid-norecord').remove();
                if (d.length == 0) {/* no records found */
					gridTable.find('tr').not('.data-grid-header-row').remove();
                    gridTable.append('<tr class="data-grid-norecord"><td colspan="' + colsCount + '">' + parentobj.noRecordsMessage + '</td></tr>');
                    gridTable.find('.data-grid-pagination').remove();
                    return;
                }

                var index = 0;
                var content = '';
                var start = 1, end = d.length;
                var rowsPerPage = parentobj.pageSizes[parentobj.pagination.PageSizeIndex];
                if (this.data.length >= this.total) {// client paginate                    
                    start = parentobj.pagination.PageNumber * rowsPerPage + 1;
                    end = start + rowsPerPage - 1;
                }

                gridTable.find('.data-row, .data-row-odd').remove();
                for (var key in d) {
                    index++;
                    if (index < start || index > end) {
                        continue;
                    }

                    content += '<tr data-key="' + d[key][parentobj.primaryKey] + '" class="data-row' + (index % 2 == 0 ? '' : '-odd') + '" >';
                    for (var f in parentobj.fields) {
                        if (!parentobj.fields[f].template) {
							if (!parentobj.fields[f].boundTemplate) {
								content += '<td>' + d[key][parentobj.fields[f].name] + '</td>';
							}else{
								var cc=d[key][parentobj.fields[f].name];
								content += '<td>' + parentobj.fields[f].boundTemplate.replace(/####/g,d[key][parentobj.fields[f].name]) + '</td>';
							}
                        } else {
                            content += '<td>' + parentobj.fields[f].template + '</td>';
                        }
                    }
                    content += '</tr>';
                }

                gridTable.find('.data-grid-header-row').after(content);

                /* -----------------------------*/
                /* pagination container -------*/
                /* ----------------------------*/
                var totalPages = Math.ceil(this.total / rowsPerPage);
                var pagination = gridTable.find('.data-grid-pagination');
                if (pagination.length == 0) {
                    gridTable.append('<tr><td class="data-grid-pagination" colspan="' + colsCount + '"><div class="pages"></div><div class="totalrecords"><span></span></div></td></tr>');
                    pagination = gridTable.find('.data-grid-pagination');
                    var ul = '<ul class="gridpaginationlist">';
                    var liIndex = -1;
                    for (var p in parentobj.pageSizes) {
                        liIndex++;
                        ul += '<li page-index="' + liIndex + '">' + parentobj.pageSizes[p] + '</li>';
                    }
                    ul += '</ul>';
                    $('body').append(ul);

                    $('.data-grid-pagination > div.pages-size > span').click(function () {
                        $(this).parent().addClass('showlist');
                        var ul = $('ul.gridpaginationlist');
                        var e1 = this, e2 = this;
                        var x = 0, y = 0;
                        if (e1.offsetParent) {
                            do {
                                x += e1.offsetLeft;
                                y += e1.offsetTop;
                            } while (e1 = e1.offsetParent);
                        }
                        while ((e2 = e2.parentNode) && e2.nodeName.toUpperCase() !== 'BODY') {
                            x -= e2.scrollLeft;
                            y -= e2.scrollTop;
                        }
                        ul.css('top', (y + $(this).height()) + 'px').css('left', x + 'px').css('width', $(this).outerWidth()).show();
                        ul.find('li').unbind('click').bind('click', function () {
                            parentobj.pagination.PageNumber = 0;
							$('#lastclickedpage').val('0');
                            parentobj.pagination.PageSizeIndex = parseInt($(this).attr('page-index'));
                            $('.data-grid-pagination > div.pages-size > span').html(parentobj.pageSizes[parentobj.pagination.PageSizeIndex] + "<span/></span>");
                            ul.hide();
                            if (parentobj.datasource.serverPagination) {
                                parentobj.datasource.read(parentobj);
                            }
                        });
                        return false;
                    });

                    $('.data-grid .sotable-col').click(function () {
                        if (parentobj.pagination.OrderBy === undefined || parentobj.pagination.OrderBy == '') {
                            parentobj.pagination.SordDirection = 'asc';
                        } else if (parentobj.pagination.SordDirection == 'asc') {
                            parentobj.pagination.SordDirection = 'desc';
                        } else {
                            parentobj.pagination.SordDirection = 'asc';
                        }
                        parentobj.pagination.OrderBy = $(this).parent().attr('field-name');
                        $(this).parent().parent().find('.sort-data-sortasc,.sort-data-sortdesc').removeClass('not-sorted').removeClass('sort-data-sortasc').removeClass('sort-data-sortdesc');
                        $(this).parent().find('i').addClass('sort-data-sort' + parentobj.pagination.SordDirection);
                        if (parentobj.datasource.serverPagination) {
                            parentobj.datasource.read(parentobj);
                        }
                    });

                    $('body').not('.data-grid-pagination > div.pages-size > span, ul.gridpaginationlist').click(function () {
                        $('ul.gridpaginationlist').hide();
                    });
                }

                var _crtindex = parentobj.pagination.PageNumber;
                while (_crtindex > 0 && _crtindex % 10 != 0) {
                    _crtindex--;
                }

                var paginationHTML = '';
                paginationHTML += '<span class="first-page" page-nr="0">&lt;</span>';
                paginationHTML += '<span class="previous-page" page-nr="' + (parentobj.pagination.PageNumber - 1) + '">&lt;</span>';
                if (_crtindex > 0) {
                    paginationHTML += '<span class="previous-group-pages" page-nr="' + (_crtindex - 1) + '">...</span>';
                }


                for (var i = _crtindex; i < _crtindex + 10 && i < totalPages; i++) {
                    if (i != parentobj.pagination.PageNumber) {
                        paginationHTML += '<span page-nr="' + i + '">' + (i + 1) + '</span>';
                    } else {
                        paginationHTML += '<label>' + (i + 1) + '</label>';
                    }
                }

                var _crtindexAux = _crtindex;
                _crtindex = totalPages - 1;
                while (_crtindex > 0 && _crtindex % 10 != 0) {
                    _crtindex--;
                }

                if (_crtindexAux + 10 < totalPages) {
                    paginationHTML += '<span class="next-group-pages" page-nr="' + (_crtindexAux + 10) + '">...</span>';
                }

                paginationHTML += '<span class="next-page" page-nr="' + (parentobj.pagination.PageNumber + 1) + '">&gt;</span>';
                paginationHTML += '<span class="last-page" page-nr="' + (totalPages - 1) + '"> &gt;&gt;</span>';
                pagination.find('.pages').html(paginationHTML);

                if (parentobj.pagination.PageNumber == 0) {
                    pagination.find('.pages .first-page, .pages .previous-page').addClass('disabledpage');
                }
                if (parentobj.pagination.PageNumber == totalPages - 1) {
                    pagination.find('.pages .next-page, .pages .last-page').addClass('disabledpage');
                }
                pagination.find('.pages span[page-nr]').not('.disabledpage').click(function () {
                    parentobj.pagination.PageNumber = parseInt($(this).attr('page-nr'));
					$('#lastclickedpage').val(parentobj.pagination.PageNumber);
                    if (parentobj.datasource.serverPagination) {
                        parentobj.datasource.read(parentobj);
                    }
                });
				
				$('.totalrecords > span').html('&nbsp;&nbsp;&nbsp; Total inregistrari gasite:'+this.total);
            }
        },
        rowsPerPageMessage: 'Display {0} per page',
        totalRowsMessage: 'Displaying {0} of {1}',
        noRecordsMessage: 'No records found',
    };

    var dropdown = {
        data: [],
        Value: 0,
        val: function (value) {
            if (value !== undefined) {
                this.Value = value;
            }
            return this.Value;
        }
    };

    return {
        accordion: accordion,
        ajaxRequest: ajaxRequest,
        dropdown: dropdown,
        grid: grid
    }
};

$.fn.Grid = function (gridProps) {
    gridProps.gridSelector = $(this).selector;
    function getTypeOfVar(object) {
        if (object === null) {
            return "null";
        }
        else if (object === undefined) {
            return "undefined";
        }
        else if (object.constructor === "test".constructor) {
            return "String";
        }
        else if (object.constructor === [].constructor) {
            return "Array";
        }
        else if (object.constructor === {}.constructor) {
            return "Object";
        }
        else {
            return "";
        }
    }

    function iterateHierarchical(obj, prop) {
        if (prop.indexOf('.') != -1) {
            return iterateHierarchical(obj, p.substr(p.indexOf('.') + 1));
        } else
            return obj[p];
    }

    var grid = app.ui().grid;
    if (gridProps !== undefined) {
        setProperties(gridProps, grid, '');
    }

    return grid;
};

$.fn.DropDown = function (url) {
    var $this = $(this);
    var selector = $(this).selector;
    var dropdown = app.ui().dropdown;
    var d = [];
    var value = (this[0].tagName.toLowerCase() != "select" ? "" : $this.find('option:selected').text());
    var rdn = new Date().getTime();

    var h = '<span class="data-dropdown" data-id="' + rdn + '">' + value;
    h += '<span></span></span>';
    $this.replaceWith(h);
    if (url === undefined) {
        if (this[0].tagName.toLowerCase() == "select") {
            $this.find("option").each(function () {
                var $t = $(this);
                var item = {
                    Value: $t.val(),
                    Text: $t.text(),
                    Selected: ($t.val() == value)
                };
                d.push(item);
            });
        }
        createItems(d, rdn, $this);
    } else {
        var request = app.ui().ajaxRequest;
        setProperties({
            url: url,
            contentType: 'application/json',
            successFunction: function (e) {
                createItems(e, rdn, $this);
            },
            type: 'GET',
            dataParam: JSON.stringify(dataParam)
        },
        request, '');
        return request.performRequest();
    }

    function createItems(data, ddlUniqueId, ddl) {
        var dataVal = $('span[data-id="' + ddlUniqueId + '"] input').val();
        if ($('[dropdown-unique-id="' + rdn + '"]').length == 0) {
            var h = '<ul dropdown-unique-id="' + rdn + '">';
            $.each(data, function (index, value) {
                h += '<li data-val="' + value.Value + '" class="' + (value.Value == dataVal ? "selected-item" : "") + '">' + value.Text + '</li>';
            });
            h += '</ul>';
            $('body').prepend(h);
            $('span.data-dropdown').click(function () {
                var listToShow = $('ul[dropdown-unique-id="' + rdn + '"]');
                var t = $('span.data-dropdown[data-id="' + rdn + '"]')[0];
                var e1 = t, e2 = t;
                var x = 0, y = 0;
                if (e1.offsetParent) {
                    do {
                        x += e1.offsetLeft;
                        y += e1.offsetTop;
                    } while (e1 = e1.offsetParent);
                }
                while ((e2 = e2.parentNode) && e2.nodeName.toUpperCase() !== 'BODY') {
                    x -= e2.scrollLeft;
                    y -= e2.scrollTop;
                }
                listToShow.css('top', (y + $(this).height()) + 'px').css('left', x + 'px').css('width', $(this).outerWidth()).show();
                listToShow.show();
                return false;
            });

            $('ul[dropdown-unique-id] li').click(function () {

                return false;
            });
            $('body').not('span.data-dropdown[data-id="' + ddlUniqueId + '"], ul[dropdown-unique-id], ul[dropdown-unique-id] li').click(function () {
                $('ul[dropdown-unique-id="' + rdn + '"]').hide();
            });
        } else {
            var $list = $('dropdown-unique-id="' + rdn + '"');
            $list.find('.selected-item').removeClass('selected-item');
            $list.find('[data-val="' + dataVal + '"]').addClass('selected-item');
            $list.show();
        }

    }

    return dropdown;
};