Changeset - 62fb395a459d
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 13 years ago 2013-04-22 16:40:24
marcin@python-works.com
make sure we hide the spans
1 file changed with 7 insertions and 6 deletions:
0 comments (0 inline, 0 general)
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -1825,688 +1825,689 @@ var PullRequestAutoComplete = function (
 
                    displaynname = nname ? "(" + nname + ")" : "";
 
                }
 

	
 
                return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk);
 
            } else {
 
                return '';
 
            }
 
        };
 

	
 
    //members cache to catch duplicates
 
    reviewerAC.dataSource.cache = [];
 
    // hack into select event
 
    if(reviewerAC.itemSelectEvent){
 
        reviewerAC.itemSelectEvent.subscribe(function (sType, aArgs) {
 

	
 
            var myAC = aArgs[0]; // reference back to the AC instance
 
            var elLI = aArgs[1]; // reference to the selected LI element
 
            var oData = aArgs[2]; // object literal of selected item's result data
 

	
 
            //fill the autocomplete with value
 

	
 
            if (oData.nname != undefined) {
 
                addReviewMember(oData.id, oData.fname, oData.lname, oData.nname,
 
                                oData.gravatar_lnk);
 
                myAC.dataSource.cache.push(oData.id);
 
                YUD.get('user').value = ''
 
            }
 
        });
 
    }
 
    return {
 
        ownerDS: ownerDS,
 
        reviewerAC: reviewerAC,
 
    };
 
}
 

	
 
/**
 
 * QUICK REPO MENU
 
 */
 
var quick_repo_menu = function(){
 
    YUE.on(YUQ('.quick_repo_menu'),'mouseenter',function(e){
 
            var menu = e.currentTarget.firstElementChild.firstElementChild;
 
            if(YUD.hasClass(menu,'hidden')){
 
                YUD.replaceClass(e.currentTarget,'hidden', 'active');
 
                YUD.replaceClass(menu, 'hidden', 'active');
 
            }
 
        })
 
    YUE.on(YUQ('.quick_repo_menu'),'mouseleave',function(e){
 
            var menu = e.currentTarget.firstElementChild.firstElementChild;
 
            if(YUD.hasClass(menu,'active')){
 
                YUD.replaceClass(e.currentTarget, 'active', 'hidden');
 
                YUD.replaceClass(menu, 'active', 'hidden');
 
            }
 
        })
 
};
 

	
 

	
 
/**
 
 * TABLE SORTING
 
 */
 

	
 
// returns a node from given html;
 
var fromHTML = function(html){
 
      var _html = document.createElement('element');
 
      _html.innerHTML = html;
 
      return _html;
 
}
 
var get_rev = function(node){
 
    var n = node.firstElementChild.firstElementChild;
 

	
 
    if (n===null){
 
        return -1
 
    }
 
    else{
 
        out = n.firstElementChild.innerHTML.split(':')[0].replace('r','');
 
        return parseInt(out);
 
    }
 
}
 

	
 
var get_name = function(node){
 
     var name = node.firstElementChild.children[2].innerHTML;
 
     return name
 
}
 
var get_group_name = function(node){
 
    var name = node.firstElementChild.children[1].innerHTML;
 
    return name
 
}
 
var get_date = function(node){
 
    var date_ = YUD.getAttribute(node.firstElementChild,'date');
 
    return date_
 
}
 

	
 
var get_age = function(node){
 
    return node
 
}
 

	
 
var get_link = function(node){
 
    return node.firstElementChild.text;
 
}
 

	
 
var revisionSort = function(a, b, desc, field) {
 

	
 
      var a_ = fromHTML(a.getData(field));
 
      var b_ = fromHTML(b.getData(field));
 

	
 
      // extract revisions from string nodes
 
      a_ = get_rev(a_)
 
      b_ = get_rev(b_)
 

	
 
      var comp = YAHOO.util.Sort.compare;
 
      var compState = comp(a_, b_, desc);
 
      return compState;
 
};
 
var ageSort = function(a, b, desc, field) {
 
    var a_ = fromHTML(a.getData(field));
 
    var b_ = fromHTML(b.getData(field));
 

	
 
    // extract name from table
 
    a_ = get_date(a_)
 
    b_ = get_date(b_)
 

	
 
    var comp = YAHOO.util.Sort.compare;
 
    var compState = comp(a_, b_, desc);
 
    return compState;
 
};
 

	
 
var lastLoginSort = function(a, b, desc, field) {
 
    var a_ = a.getData('last_login_raw') || 0;
 
    var b_ = b.getData('last_login_raw') || 0;
 

	
 
    var comp = YAHOO.util.Sort.compare;
 
    var compState = comp(a_, b_, desc);
 
    return compState;
 
};
 

	
 
var nameSort = function(a, b, desc, field) {
 
    var a_ = fromHTML(a.getData(field));
 
    var b_ = fromHTML(b.getData(field));
 

	
 
    // extract name from table
 
    a_ = get_name(a_)
 
    b_ = get_name(b_)
 

	
 
    var comp = YAHOO.util.Sort.compare;
 
    var compState = comp(a_, b_, desc);
 
    return compState;
 
};
 

	
 
var permNameSort = function(a, b, desc, field) {
 
    var a_ = fromHTML(a.getData(field));
 
    var b_ = fromHTML(b.getData(field));
 
    // extract name from table
 

	
 
    a_ = a_.children[0].innerHTML;
 
    b_ = b_.children[0].innerHTML;
 

	
 
    var comp = YAHOO.util.Sort.compare;
 
    var compState = comp(a_, b_, desc);
 
    return compState;
 
};
 

	
 
var groupNameSort = function(a, b, desc, field) {
 
    var a_ = fromHTML(a.getData(field));
 
    var b_ = fromHTML(b.getData(field));
 

	
 
    // extract name from table
 
    a_ = get_group_name(a_)
 
    b_ = get_group_name(b_)
 

	
 
    var comp = YAHOO.util.Sort.compare;
 
    var compState = comp(a_, b_, desc);
 
    return compState;
 
};
 
var dateSort = function(a, b, desc, field) {
 
    var a_ = fromHTML(a.getData(field));
 
    var b_ = fromHTML(b.getData(field));
 

	
 
    // extract name from table
 
    a_ = get_date(a_)
 
    b_ = get_date(b_)
 

	
 
    var comp = YAHOO.util.Sort.compare;
 
    var compState = comp(a_, b_, desc);
 
    return compState;
 
};
 

	
 
var usernamelinkSort = function(a, b, desc, field) {
 
      var a_ = fromHTML(a.getData(field));
 
      var b_ = fromHTML(b.getData(field));
 

	
 
      // extract url text from string nodes
 
      a_ = get_link(a_)
 
      b_ = get_link(b_)
 
      var comp = YAHOO.util.Sort.compare;
 
      var compState = comp(a_, b_, desc);
 
      return compState;
 
}
 

	
 
var addPermAction = function(_html, users_list, groups_list){
 
    var elmts = YUD.getElementsByClassName('last_new_member');
 
    var last_node = elmts[elmts.length-1];
 
    if (last_node){
 
       var next_id = (YUD.getElementsByClassName('new_members')).length;
 
       _html = _html.format(next_id);
 
       last_node.innerHTML = _html;
 
       YUD.setStyle(last_node, 'display', '');
 
       YUD.removeClass(last_node, 'last_new_member');
 
       MembersAutoComplete("perm_new_member_name_"+next_id,
 
               "perm_container_"+next_id, users_list, groups_list);
 
       //create new last NODE
 
       var el = document.createElement('tr');
 
       el.id = 'add_perm_input';
 
       YUD.addClass(el,'last_new_member');
 
       YUD.addClass(el,'new_members');
 
       YUD.insertAfter(el, last_node);
 
    }
 
}
 
function ajaxActionRevokePermission(url, obj_id, obj_type, field_id, extra_data) {
 
    var callback = {
 
        success: function (o) {
 
            var tr = YUD.get(String(field_id));
 
            tr.parentNode.removeChild(tr);
 
        },
 
        failure: function (o) {
 
            alert(_TM['Failed to remoke permission'] + ": " + o.status);
 
        },
 
    };
 
    query_params = {
 
        '_method': 'delete'
 
    }
 
    // put extra data into POST
 
    if (extra_data !== undefined && (typeof extra_data === 'object')){
 
        for(k in extra_data){
 
            query_params[k] = extra_data[k];
 
        }
 
    }
 

	
 
    if (obj_type=='user'){
 
        query_params['user_id'] = obj_id;
 
        query_params['obj_type'] = 'user';
 
    }
 
    else if (obj_type=='user_group'){
 
        query_params['user_group_id'] = obj_id;
 
        query_params['obj_type'] = 'user_group';
 
    }
 

	
 
    var request = YAHOO.util.Connect.asyncRequest('POST', url, callback,
 
            toQueryString(query_params));
 
};
 
/* Multi selectors */
 

	
 
var MultiSelectWidget = function(selected_id, available_id, form_id){
 

	
 

	
 
    //definition of containers ID's
 
    var selected_container = selected_id;
 
    var available_container = available_id;
 

	
 
    //temp container for selected storage.
 
    var cache = new Array();
 
    var av_cache = new Array();
 
    var c =  YUD.get(selected_container);
 
    var ac = YUD.get(available_container);
 

	
 
    //get only selected options for further fullfilment
 
    for(var i = 0;node =c.options[i];i++){
 
        if(node.selected){
 
            //push selected to my temp storage left overs :)
 
            cache.push(node);
 
        }
 
    }
 

	
 
    //get all available options to cache
 
    for(var i = 0;node =ac.options[i];i++){
 
            //push selected to my temp storage left overs :)
 
            av_cache.push(node);
 
    }
 

	
 
    //fill available only with those not in chosen
 
    ac.options.length=0;
 
    tmp_cache = new Array();
 

	
 
    for(var i = 0;node = av_cache[i];i++){
 
        var add = true;
 
        for(var i2 = 0;node_2 = cache[i2];i2++){
 
            if(node.value == node_2.value){
 
                add=false;
 
                break;
 
            }
 
        }
 
        if(add){
 
            tmp_cache.push(new Option(node.text, node.value, false, false));
 
        }
 
    }
 

	
 
    for(var i = 0;node = tmp_cache[i];i++){
 
        ac.options[i] = node;
 
    }
 

	
 
    function prompts_action_callback(e){
 

	
 
        var chosen = YUD.get(selected_container);
 
        var available = YUD.get(available_container);
 

	
 
        //get checked and unchecked options from field
 
        function get_checked(from_field){
 
            //temp container for storage.
 
            var sel_cache = new Array();
 
            var oth_cache = new Array();
 

	
 
            for(var i = 0;node = from_field.options[i];i++){
 
                if(node.selected){
 
                    //push selected fields :)
 
                    sel_cache.push(node);
 
                }
 
                else{
 
                    oth_cache.push(node)
 
                }
 
            }
 

	
 
            return [sel_cache,oth_cache]
 
        }
 

	
 
        //fill the field with given options
 
        function fill_with(field,options){
 
            //clear firtst
 
            field.options.length=0;
 
            for(var i = 0;node = options[i];i++){
 
                    field.options[i]=new Option(node.text, node.value,
 
                            false, false);
 
            }
 

	
 
        }
 
        //adds to current field
 
        function add_to(field,options){
 
            for(var i = 0;node = options[i];i++){
 
                    field.appendChild(new Option(node.text, node.value,
 
                            false, false));
 
            }
 
        }
 

	
 
        // add action
 
        if (this.id=='add_element'){
 
            var c = get_checked(available);
 
            add_to(chosen,c[0]);
 
            fill_with(available,c[1]);
 
        }
 
        // remove action
 
        if (this.id=='remove_element'){
 
            var c = get_checked(chosen);
 
            add_to(available,c[0]);
 
            fill_with(chosen,c[1]);
 
        }
 
        // add all elements
 
        if(this.id=='add_all_elements'){
 
            for(var i=0; node = available.options[i];i++){
 
                    chosen.appendChild(new Option(node.text,
 
                            node.value, false, false));
 
            }
 
            available.options.length = 0;
 
        }
 
        //remove all elements
 
        if(this.id=='remove_all_elements'){
 
            for(var i=0; node = chosen.options[i];i++){
 
                available.appendChild(new Option(node.text,
 
                        node.value, false, false));
 
            }
 
            chosen.options.length = 0;
 
        }
 

	
 
    }
 

	
 
    YUE.addListener(['add_element','remove_element',
 
                   'add_all_elements','remove_all_elements'],'click',
 
                   prompts_action_callback)
 
    if (form_id !== undefined) {
 
        YUE.addListener(form_id,'submit',function(){
 
            var chosen = YUD.get(selected_container);
 
            for (var i = 0; i < chosen.options.length; i++) {
 
                chosen.options[i].selected = 'selected';
 
            }
 
        });
 
    }
 
}
 

	
 

	
 

	
 
// custom paginator
 
var YUI_paginator = function(links_per_page, containers){
 

	
 
var YUI_paginator = function(links_per_page, containers){
 
    // my custom paginator
 
    (function () {
 

	
 
        var Paginator = YAHOO.widget.Paginator,
 
            l         = YAHOO.lang,
 
            setId     = YAHOO.util.Dom.generateId;
 

	
 
        Paginator.ui.MyFirstPageLink = function (p) {
 
            this.paginator = p;
 

	
 
            p.subscribe('recordOffsetChange',this.update,this,true);
 
            p.subscribe('rowsPerPageChange',this.update,this,true);
 
            p.subscribe('totalRecordsChange',this.update,this,true);
 
            p.subscribe('destroy',this.destroy,this,true);
 

	
 
            // TODO: make this work
 
            p.subscribe('firstPageLinkLabelChange',this.update,this,true);
 
            p.subscribe('firstPageLinkClassChange',this.update,this,true);
 
        };
 

	
 
        Paginator.ui.MyFirstPageLink.init = function (p) {
 
            p.setAttributeConfig('firstPageLinkLabel', {
 
                value : 1,
 
                validator : l.isString
 
            });
 
            p.setAttributeConfig('firstPageLinkClass', {
 
                value : 'yui-pg-first',
 
                validator : l.isString
 
            });
 
            p.setAttributeConfig('firstPageLinkTitle', {
 
                value : 'First Page',
 
                validator : l.isString
 
            });
 
        };
 

	
 
        // Instance members and methods
 
        Paginator.ui.MyFirstPageLink.prototype = {
 
            current   : null,
 
            leftmost_page: null,
 
            rightmost_page: null,
 
            link      : null,
 
            span      : null,
 
            dotdot    : null,
 
            getPos    : function(cur_page, max_page, items){
 
                var edge = parseInt(items / 2) + 1;
 
                if (cur_page <= edge){
 
                    var radius = Math.max(parseInt(items / 2), items - cur_page);
 
                }
 
                else if ((max_page - cur_page) < edge) {
 
                    var radius = (items - 1) - (max_page - cur_page);
 
                }
 
                else{
 
                    var radius = parseInt(items / 2);
 
                }
 

	
 
                var left = Math.max(1, (cur_page - (radius)))
 
                var right = Math.min(max_page, cur_page + (radius))
 
                return [left, cur_page, right]
 
            },
 
            render : function (id_base) {
 
                var p      = this.paginator,
 
                    c      = p.get('firstPageLinkClass'),
 
                    label  = p.get('firstPageLinkLabel'),
 
                    title  = p.get('firstPageLinkTitle');
 

	
 
                this.link     = document.createElement('a');
 
                this.span     = document.createElement();
 
                this.span     = document.createElement('span');
 
                YUD.setStyle(this.span, 'display', 'none');
 

	
 
                var _pos = this.getPos(p.getCurrentPage(), p.getTotalPages(), 5);
 
                this.leftmost_page = _pos[0];
 
                this.rightmost_page = _pos[2];
 

	
 
                setId(this.link, id_base + '-first-link');
 
                this.link.href      = '#';
 
                this.link.className = c;
 
                this.link.innerHTML = label;
 
                this.link.title     = title;
 
                YAHOO.util.Event.on(this.link,'click',this.onClick,this,true);
 

	
 
                setId(this.span, id_base + '-first-span');
 
                this.span.className = c;
 
                this.span.innerHTML = label;
 

	
 
                this.current = p.getCurrentPage() > 1 ? this.link : this.span;
 
                return this.current;
 
            },
 
            update : function (e) {
 
                var p      = this.paginator;
 
                var _pos   = this.getPos(p.getCurrentPage(), p.getTotalPages(), 5);
 
                this.leftmost_page = _pos[0];
 
                this.rightmost_page = _pos[2];
 

	
 
                if (e && e.prevValue === e.newValue) {
 
                    return;
 
                }
 

	
 
                var par = this.current ? this.current.parentNode : null;
 
                if (this.leftmost_page > 1) {
 
                    if (par && this.current === this.span) {
 
                        par.replaceChild(this.link,this.current);
 
                        this.current = this.link;
 
                    }
 
                } else {
 
                    if (par && this.current === this.link) {
 
                        par.replaceChild(this.span,this.current);
 
                        this.current = this.span;
 
                    }
 
                }
 
            },
 
            destroy : function () {
 
                YAHOO.util.Event.purgeElement(this.link);
 
                this.current.parentNode.removeChild(this.current);
 
                this.link = this.span = null;
 
            },
 
            onClick : function (e) {
 
                YAHOO.util.Event.stopEvent(e);
 
                this.paginator.setPage(1);
 
            }
 
        };
 

	
 
        })();
 
    (function () {
 

	
 
        var Paginator = YAHOO.widget.Paginator,
 
            l         = YAHOO.lang,
 
            setId     = YAHOO.util.Dom.generateId;
 

	
 
        Paginator.ui.MyLastPageLink = function (p) {
 
            this.paginator = p;
 

	
 
            p.subscribe('recordOffsetChange',this.update,this,true);
 
            p.subscribe('rowsPerPageChange',this.update,this,true);
 
            p.subscribe('totalRecordsChange',this.update,this,true);
 
            p.subscribe('destroy',this.destroy,this,true);
 

	
 
            // TODO: make this work
 
            p.subscribe('lastPageLinkLabelChange',this.update,this,true);
 
            p.subscribe('lastPageLinkClassChange', this.update,this,true);
 
        };
 

	
 
        Paginator.ui.MyLastPageLink.init = function (p) {
 
            p.setAttributeConfig('lastPageLinkLabel', {
 
                value : -1,
 
                validator : l.isString
 
            });
 
            p.setAttributeConfig('lastPageLinkClass', {
 
                value : 'yui-pg-last',
 
                validator : l.isString
 
            });
 
            p.setAttributeConfig('lastPageLinkTitle', {
 
                value : 'Last Page',
 
                validator : l.isString
 
            });
 

	
 
        };
 

	
 
        Paginator.ui.MyLastPageLink.prototype = {
 

	
 
            current   : null,
 
            leftmost_page: null,
 
            rightmost_page: null,
 
            link      : null,
 
            span      : null,
 
            dotdot    : null,
 
            na        : null,
 
            getPos    : function(cur_page, max_page, items){
 
                var edge = parseInt(items / 2) + 1;
 
                if (cur_page <= edge){
 
                    var radius = Math.max(parseInt(items / 2), items - cur_page);
 
                }
 
                else if ((max_page - cur_page) < edge) {
 
                    var radius = (items - 1) - (max_page - cur_page);
 
                }
 
                else{
 
                    var radius = parseInt(items / 2);
 
                }
 

	
 
                var left = Math.max(1, (cur_page - (radius)))
 
                var right = Math.min(max_page, cur_page + (radius))
 
                return [left, cur_page, right]
 
            },
 
            render : function (id_base) {
 
                var p      = this.paginator,
 
                    c      = p.get('lastPageLinkClass'),
 
                    label  = p.get('lastPageLinkLabel'),
 
                    last   = p.getTotalPages(),
 
                    title  = p.get('lastPageLinkTitle');
 

	
 
                var _pos = this.getPos(p.getCurrentPage(), p.getTotalPages(), 5);
 
                this.leftmost_page = _pos[0];
 
                this.rightmost_page = _pos[2];
 

	
 
                this.link = document.createElement('a');
 
                this.span = document.createElement();
 
                this.span = document.createElement('span');
 
                YUD.setStyle(this.span, 'display', 'none');
 

	
 
                this.na   = this.span.cloneNode(false);
 

	
 
                setId(this.link, id_base + '-last-link');
 
                this.link.href      = '#';
 
                this.link.className = c;
 
                this.link.innerHTML = label;
 
                this.link.title     = title;
 
                YAHOO.util.Event.on(this.link,'click',this.onClick,this,true);
 

	
 
                setId(this.span, id_base + '-last-span');
 
                this.span.className = c;
 
                this.span.innerHTML = label;
 

	
 
                setId(this.na, id_base + '-last-na');
 

	
 
                if (this.rightmost_page < p.getTotalPages()){
 
                    this.current = this.link;
 
                }
 
                else{
 
                    this.current = this.span;
 
                }
 

	
 
                this.current.innerHTML = p.getTotalPages();
 
                return this.current;
 
            },
 

	
 
            update : function (e) {
 
                var p      = this.paginator;
 

	
 
                var _pos = this.getPos(p.getCurrentPage(), p.getTotalPages(), 5);
 
                this.leftmost_page = _pos[0];
 
                this.rightmost_page = _pos[2];
 

	
 
                if (e && e.prevValue === e.newValue) {
 
                    return;
 
                }
 

	
 
                var par   = this.current ? this.current.parentNode : null,
 
                    after = this.link;
 
                if (par) {
 

	
 
                    // only show the last page if the rightmost one is
 
                    // lower, so we don't have doubled entries at the end
 
                    if (!(this.rightmost_page < p.getTotalPages())){
 
                        after = this.span
 
                    }
 

	
 
                    if (this.current !== after) {
 
                        par.replaceChild(after,this.current);
 
                        this.current = after;
 
                    }
 
                }
 
                this.current.innerHTML = this.paginator.getTotalPages();
 

	
 
            },
 
            destroy : function () {
 
                YAHOO.util.Event.purgeElement(this.link);
 
                this.current.parentNode.removeChild(this.current);
 
                this.link = this.span = null;
 
            },
 
            onClick : function (e) {
 
                YAHOO.util.Event.stopEvent(e);
 
                this.paginator.setPage(this.paginator.getTotalPages());
 
            }
 
        };
 

	
 
        })();
 

	
 
    var pagi = new YAHOO.widget.Paginator({
 
        rowsPerPage: links_per_page,
 
        alwaysVisible: false,
 
        template : "{PreviousPageLink} {MyFirstPageLink} {PageLinks} {MyLastPageLink} {NextPageLink}",
 
        pageLinks: 5,
 
        containerClass: 'pagination-wh',
 
        currentPageClass: 'pager_curpage',
 
        pageLinkClass: 'pager_link',
 
        nextPageLinkLabel: '&gt;',
 
        previousPageLinkLabel: '&lt;',
 
        containers:containers
 
    })
 

	
 
    return pagi
 
}
 

	
 

	
 

	
 
// global hooks after DOM is loaded
 

	
 
YUE.onDOMReady(function(){
 
    YUE.on(YUQ('.diff-collapse-button'), 'click', function(e){
 
        var button = e.currentTarget;
 
        var t = YUD.get(button).getAttribute('target');
 
        console.log(t);
 
        if(YUD.hasClass(t, 'hidden')){
 
            YUD.removeClass(t, 'hidden');
 
            YUD.get(button).innerHTML = "&uarr; {0} &uarr;".format(_TM['Collapse diff']);
 
        }
 
        else if(!YUD.hasClass(t, 'hidden')){
 
            YUD.addClass(t, 'hidden');
 
            YUD.get(button).innerHTML = "&darr; {0} &darr;".format(_TM['Expand diff']);
 
        }
 
    });
 

	
 

	
 

	
 
});
0 comments (0 inline, 0 general)