Changeset - 77a88040a262
[Not reviewed]
default
0 1 0
domruf - 8 years ago 2017-10-23 22:52:50
dominikruf@gmail.com
js: fix parent/child navigation with more than 2 parents/children

Before, it would only work with 0-2 parents/children.
1 file changed with 12 insertions and 12 deletions:
0 comments (0 inline, 0 general)
kallithea/public/js/base.js
Show inline comments
 
@@ -1470,73 +1470,73 @@ var prefixFirstSort = function(results, 
 
            }
 

	
 
            // Default sorting
 
            if (a.text > b.text) {
 
                return 1;
 
            }
 
            if (a.text < b.text) {
 
                return -1;
 
            }
 
            return 0;
 
        });
 
    }
 
    return results;
 
};
 

	
 
/* Helper for jQuery DataTables */
 

	
 
var updateRowCountCallback = function updateRowCountCallback($elem, onlyDisplayed) {
 
    return function drawCallback() {
 
        var info = this.api().page.info(),
 
            count = onlyDisplayed === true ? info.recordsDisplay : info.recordsTotal;
 
        $elem.html(count);
 
    }
 
};
 

	
 

	
 
/**
 
 * activate changeset parent/child navigation links
 
 */
 
var activate_parent_child_links = function(){
 

	
 
    $('.parent-child-link').on('click', function(e){
 
        var $this = $(this);
 
        //fetch via ajax what is going to be the next link, if we have
 
        //>1 links show them to user to choose
 
        if(!$this.hasClass('disabled')){
 
            $.ajax({
 
                url: $this.data('ajax-url'),
 
                success: function(data) {
 
                    var repo_name = $this.data('reponame');
 
                    if(data.results.length === 0){
 
                        $this.addClass('disabled');
 
                        $this.text(_TM['No revisions']);
 
                    }
 
                    if(data.results.length === 1){
 
                        var commit = data.results[0];
 
                        window.location = pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': commit.raw_id});
 
                    }
 
                    else if(data.results.length === 2){
 
                    else if(data.results.length > 1){
 
                        $this.addClass('disabled');
 
                        $this.addClass('double');
 
                        var template =
 
                            ($this.data('linktype') == 'parent' ? '<i class="icon-left-open"/> ' : '') +
 
                            '<a title="__title__" href="__url__">__rev__</a>' +
 
                            ($this.data('linktype') == 'child' ? ' <i class="icon-right-open"/>' : '');
 
                        var _html = '';
 
                        _html += template
 
                                .replace('__rev__','r{0}:{1}'.format(data.results[0].revision, data.results[0].raw_id.substr(0,6)))
 
                                .replace('__title__', data.results[0].message)
 
                                .replace('__url__', pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': data.results[0].raw_id}));
 
                        _html +='<br/>'
 
                        _html += template
 
                                .replace('__rev__','r{0}:{1}'.format(data.results[1].revision, data.results[1].raw_id.substr(0,6)))
 
                                .replace('__title__', data.results[1].message)
 
                                .replace('__url__', pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': data.results[1].raw_id}));
 
                        $this.html(_html);
 
                        var _html = [];
 
                        for(var i = 0; i < data.results.length; i++){
 
                            _html.push(template
 
                                .replace('__rev__', 'r{0}:{1}'.format(data.results[i].revision, data.results[i].raw_id.substr(0, 6)))
 
                                .replace('__title__', data.results[i].message)
 
                                .replace('__url__', pyroutes.url('changeset_home', {
 
                                    'repo_name': repo_name,
 
                                    'revision': data.results[i].raw_id}))
 
                                );
 
                        }
 
                        $this.html(_html.join('<br/>'));
 
                    }
 
                }
 
            });
 
        e.preventDefault();
 
        }
 
    });
 
}
0 comments (0 inline, 0 general)