##// END OF EJS Templates
js: reuse parent/child navigation code - avoid duplication...
domruf -
r6868:c504e3af default
parent child Browse files
Show More
@@ -1497,64 +1497,27 b' var updateRowCountCallback = function up'
1497 1497 * activate changeset parent/child navigation links
1498 1498 */
1499 1499 var activate_parent_child_links = function(){
1500 //next links
1501 $('#child_link').on('click', function(e){
1500
1501 $('.parent-child-link').on('click', function(e){
1502 var $this = $(this);
1502 1503 //fetch via ajax what is going to be the next link, if we have
1503 1504 //>1 links show them to user to choose
1504 if(!$('#child_link').hasClass('disabled')){
1505 if(!$this.hasClass('disabled')){
1505 1506 $.ajax({
1506 url: $('#child_link').data('ajax-url'),
1507 url: $this.data('ajax-url'),
1507 1508 success: function(data) {
1508 var repo_name = $('#child_link').data('reponame');
1509 var repo_name = $this.data('reponame');
1509 1510 if(data.results.length === 0){
1510 $('#child_link').addClass('disabled');
1511 $('#child_link').text(_TM['No revisions']);
1511 $this.addClass('disabled');
1512 $this.text(_TM['No revisions']);
1512 1513 }
1513 1514 if(data.results.length === 1){
1514 1515 var commit = data.results[0];
1515 1516 window.location = pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': commit.raw_id});
1516 1517 }
1517 1518 else if(data.results.length === 2){
1518 $('#child_link').addClass('disabled');
1519 $('#child_link').addClass('double');
1520 var _html = '';
1521 _html +='<a title="__title__" href="__url__">__rev__</a> <i class="icon-right-open"></i>'
1522 .replace('__rev__','r{0}:{1}'.format(data.results[0].revision, data.results[0].raw_id.substr(0,6)))
1523 .replace('__title__', data.results[0].message)
1524 .replace('__url__', pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': data.results[0].raw_id}));
1525 _html +='<br/>'
1526 _html +='<a title="__title__" href="__url__">__rev__</a> <i class="icon-right-open"></i>'
1527 .replace('__rev__','r{0}:{1}'.format(data.results[1].revision, data.results[1].raw_id.substr(0,6)))
1528 .replace('__title__', data.results[1].message)
1529 .replace('__url__', pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': data.results[1].raw_id}));
1530 $('#child_link').html(_html);
1531 }
1532 }
1533 });
1534 e.preventDefault();
1535 }
1536 });
1537
1538 //prev links
1539 $('#parent_link').on('click', function(e){
1540 //fetch via ajax what is going to be the next link, if we have
1541 //>1 links show them to user to choose
1542 if(!$('#parent_link').hasClass('disabled')){
1543 $.ajax({
1544 url: $('#parent_link').data('ajax-url'),
1545 success: function(data) {
1546 var repo_name = $('#parent_link').data('reponame');
1547 if(data.results.length === 0){
1548 $('#parent_link').addClass('disabled');
1549 $('#parent_link').text(_TM['No revisions']);
1550 }
1551 if(data.results.length === 1){
1552 var commit = data.results[0];
1553 window.location = pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': commit.raw_id});
1554 }
1555 else if(data.results.length === 2){
1556 $('#parent_link').addClass('disabled');
1557 $('#parent_link').addClass('double');
1519 $this.addClass('disabled');
1520 $this.addClass('double');
1558 1521 var _html = '';
1559 1522 _html +='<i class="icon-left-open"></i> <a title="__title__" href="__url__">__rev__</a>'
1560 1523 .replace('__rev__','r{0}:{1}'.format(data.results[0].revision, data.results[0].raw_id.substr(0,6)))
@@ -1565,7 +1528,7 b' var activate_parent_child_links = functi'
1565 1528 .replace('__rev__','r{0}:{1}'.format(data.results[1].revision, data.results[1].raw_id.substr(0,6)))
1566 1529 .replace('__title__', data.results[1].message)
1567 1530 .replace('__url__', pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': data.results[1].raw_id}));
1568 $('#parent_link').html(_html);
1531 $this.html(_html);
1569 1532 }
1570 1533 }
1571 1534 });
@@ -530,16 +530,16 b''
530 530 </%def>
531 531
532 532 <%def name="parent_child_navigation()">
533 <div class="parents pull-left">
534 <div class="parent_link"
533 <div class="pull-left">
534 <div class="parent-child-link"
535 535 data-ajax-url="${h.url('changeset_parents',repo_name=c.repo_name, revision=c.changeset.raw_id)}"
536 536 data-reponame="${c.repo_name}">
537 537 <i class="icon-left-open"></i> <a href="#">${_('Parent rev.')}</a>
538 538 </div>
539 539 </div>
540 540
541 <div class="children pull-right">
542 <div class="child_link"
541 <div class="pull-right">
542 <div class="parent-child-link"
543 543 data-ajax-url="${h.url('changeset_children',repo_name=c.repo_name, revision=c.changeset.raw_id)}"
544 544 data-reponame="${c.repo_name}">
545 545 <a href="#">${_('Child rev.')}</a> <i class="icon-right-open"></i>
General Comments 0
You need to be logged in to leave comments. Login now