Edgewall Software

Ticket #2647: disable-or-ticket-2647-r8661.patch

File disable-or-ticket-2647-r8661.patch, 2.5 KB (added by ebray, 3 years ago)

One possible, JS-only, approach to handling empty clauses. It prevents the user from having any more than one empty clause at a time. While it does nothing to facilitate removing clauses, it's less of an issue since only one can be created at a time. Updated to fix a small bug where the 'Or' button wasn't displayed when no filters are selected.

  • trac/ticket/templates/query.html

     
    122122                    </tr> 
    123123                  </tbody> 
    124124 
    125                   <tbody py:with="last_clause = clause_num == len(clauses) - 1"> 
     125                  <tbody py:with="last_clause = clause_num == (len(clauses) or 1) - 1"> 
    126126                    <tr class="actions"> 
    127127                      <td class="and" colspan="2"> 
    128128                        &nbsp;<label for="add_filter_${clause_num}">And</label>&nbsp; 
  • trac/htdocs/js/query.js

     
    3333        var ctbody = table.closest("tbody"); 
    3434        if (table.children().length > 2 || !ctbody.siblings().length) { 
    3535          tbody.remove(); 
     36          if (!ctbody.siblings().length && table.children().length == 1) { 
     37            $("#add_clause").attr("disabled", true); 
     38          } 
    3639        } else { 
    3740          var add_clause = $("#add_clause", ctbody); 
    3841          if (add_clause.length) 
     
    219222        this.options[this.selectedIndex].disabled = true; 
    220223       
    221224      this.selectedIndex = 0; 
     225 
     226      // Enable the Or... button if it's been disabled 
     227      $("#add_clause").attr("disabled", false); 
    222228    }).next("div.inlinebuttons").remove(); 
    223229     
    224230    // Add a new empty clause at the end by cloning the current last clause 
     
    229235      tbody = tbody.parents("tbody").eq(0); 
    230236      var copy = tbody.clone(true); 
    231237      $(button).closest("td").next().attr("colSpan", 4).end().remove(); 
    232       $("td.trac-clause-sep", copy).parent().removeAttr("style"); 
     238      $("tr:first", copy).removeAttr("style"); 
    233239      $("tr tbody:not(:last)", copy).remove(); 
    234240      var newId = "add_filter_" + clauseNum; 
    235241      $("select", copy).attr("id", newId).attr("name", newId) 
    236242        .children().enable().end() 
    237243        .prev().attr("for", newId); 
    238244      tbody.after(copy); 
     245      $("#add_clause").attr("disabled", true); 
    239246    } 
    240247     
    241248    // Make the button for adding a clause a client-side trigger 
     
    246253      addClause(this); 
    247254      return false; 
    248255    })); 
     256    if (!add_clause.closest("tbody").siblings().length) { 
     257      // That is, if there are no filters added to this clause 
     258      add_clause.attr("disabled", true); 
     259    } 
    249260  } 
    250261 
    251262})(jQuery);