add-on category checkbox defaults (bug 624922)
This commit is contained in:
Родитель
104c179086
Коммит
9fc3c39ecb
|
@ -909,16 +909,21 @@ function initCatFields() {
|
|||
$main = $(this).find(".addon-categories"),
|
||||
$misc = $(this).find(".addon-misc-category"),
|
||||
maxCats = parseInt($parent.attr("data-max-categories"));
|
||||
var checkMain = function() {
|
||||
var checkMainDefault = function() {
|
||||
var checkedLength = $("input:checked", $main).length,
|
||||
disabled = checkedLength >= maxCats;
|
||||
$("input", $misc).attr("checked", checkedLength <= 0);
|
||||
$("input:not(:checked)", $main).attr("disabled", disabled);
|
||||
return checkedLength;
|
||||
};
|
||||
var checkMain = function() {
|
||||
var checkedLength = checkMainDefault();
|
||||
$("input", $misc).attr("checked", checkedLength <= 0);
|
||||
};
|
||||
var checkOther = function() {
|
||||
$("input", $main).attr("checked", false).attr("disabled", false);
|
||||
};
|
||||
$("input", $main).live("change", checkMain).trigger("change");
|
||||
checkMainDefault();
|
||||
$("input", $main).live("change", checkMain);
|
||||
$("input", $misc).live("change", checkOther);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,37 @@
|
|||
$(document).ready(function(){
|
||||
|
||||
var catFixture = {
|
||||
setup: function() {
|
||||
this.sandbox = tests.createSandbox('#addon-cats');
|
||||
initCatFields();
|
||||
},
|
||||
teardown: function() {
|
||||
this.sandbox.remove();
|
||||
}
|
||||
};
|
||||
|
||||
module('initCatFields', catFixture);
|
||||
|
||||
test('Default with initial categories', function() {
|
||||
var scope = $("#addon-cats-fx", self.sandbox);
|
||||
var checkedChoices = $("input:checked", scope);
|
||||
equals(checkedChoices.length, 2);
|
||||
equals(checkedChoices[0].id, "id_form-0-categories_1");
|
||||
equals(checkedChoices[1].id, "id_form-0-categories_2");
|
||||
|
||||
// 2 categories are selected, the other category should be disabled.
|
||||
var max = scope.parent("div").attr("data-max-categories");
|
||||
equals(parseInt(max), 2);
|
||||
var disabledChoices = $("input:disabled", scope);
|
||||
equals(disabledChoices.length, 1);
|
||||
equals(disabledChoices[0].id, "id_form-0-categories_0");
|
||||
});
|
||||
|
||||
test('Default without initial categories', function() {
|
||||
equals($("#addon-cats-tb input:checked", self.sandbox).length, 0);
|
||||
});
|
||||
|
||||
|
||||
function pushTiersAndResults($suite, tiers, results) {
|
||||
$.each(['1','2','3','4'], function(i, val) {
|
||||
tiers.push($('[class~="test-tier"][data-tier="' + val + '"]',
|
||||
|
|
|
@ -117,6 +117,32 @@
|
|||
<a id="edit_slug" href="#">{{ _('Edit') }}</a>
|
||||
</span>
|
||||
</div>
|
||||
<div id="addon-cats" data-max-categories="2">
|
||||
<div data-max-categories="2">
|
||||
<div id="addon-cats-fx" class="select-addon-cats">
|
||||
<label>Select <b>up to 2</b> Firefox categories for this add-on:</label>
|
||||
<ul class="addon-categories">
|
||||
<li><label for="id_form-0-categories_0"><input type="checkbox" name="form-0-categories" value="72" id="id_form-0-categories_0" /> Alerts & Updates</label></li>
|
||||
<li><label for="id_form-0-categories_1"><input checked="checked" type="checkbox" name="form-0-categories" value="14" id="id_form-0-categories_1" /> Appearance</label></li>
|
||||
<li><label for="id_form-0-categories_2"><input checked="checked" type="checkbox" name="form-0-categories" value="22" id="id_form-0-categories_2" /> Bookmarks</label></li>
|
||||
</ul>
|
||||
<ul class="addon-misc-category">
|
||||
<li><label for="id_form-0-categories_13"><input type="checkbox" name="form-0-categories" value="73" id="id_form-0-categories_13" /> My add-on doesn't fit into any of the categories</label></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="addon-cats-tb" class="select-addon-cats">
|
||||
<label>Select <b>up to 2</b> Thunderbird categories for this add-on:</label>
|
||||
<ul class="addon-categories">
|
||||
<li><label for="id_form-1-categories_0"><input type="checkbox" name="form-1-categories" value="23" id="id_form-1-categories_0" /> Contacts</label></li>
|
||||
<li><label for="id_form-1-categories_1"><input type="checkbox" name="form-1-categories" value="69" id="id_form-1-categories_1" /> Language Support</label></li>
|
||||
</ul>
|
||||
<ul class="addon-misc-category">
|
||||
<li><label for="id_form-1-categories_4"><input type="checkbox" name="form-1-categories" value="50" id="id_form-1-categories_4" /> My add-on doesn't fit into any of the categories</label></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="{{ url('jsi18n') }}/build:{{ BUILD_ID_JS }}"></script>
|
||||
{{ js('common') }}
|
||||
|
|
Загрузка…
Ссылка в новой задаче