Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/w3c/wai-axsdb-web
Browse files Browse the repository at this point in the history
# By Evangelos Vlachogiannis
# Via Evangelos Vlachogiannis
* 'master' of https://github.com/w3c/wai-axsdb-web:
  Change test ID to be more brief, could also be not first in reading order #59
  lib add
  tests-run page: Showing 51 of ... test cases, #64
  tests-run page: Showing 51 of ... test cases, #64
  • Loading branch information
Eric Eggert committed Aug 12, 2014
2 parents 1ebcd42 + 7a09c30 commit 73b6fef
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 9 deletions.
197 changes: 197 additions & 0 deletions js/lib/jquery.multiFieldExtender-2.0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
jQuery plugin to add functionality to your forms to add multiple records on single click on the fly using client side javascript
author: Vipul Limbachiya
http://vipulilmbachiya.com
*/

/*
* This program is free software. It comes without any warranty, to the extent permitted by applicable law.
* You can redistribute it and/or modify it without any terms.
* Save developers, use Firefox http://firefox.com
*/

(function ($) {
$.fn.EnableMultiField = function (options) {
options = $.extend({
linkText: 'Add more',
linkClass: 'addMoreFields',
enableRemove: true,
removeLinkText: 'Remove',
removeLinkClass: 'removeFields',
confirmOnRemove: true,
confirmationMsgOnRemove: 'Are you sure you wish to remove selected field(s)?',
beforeAddEventCallback: null,
addEventCallback: null,
removeEventCallback: null,
maxItemsAllowedToAdd: null,
maxItemReachedCallback: null,
data: []
},
options);

return this.each(function () {
var self = $(this);

$(self).attr("TotalFieldsAdded", "0");

$(self).attr("maxCountReached", "false");

$(self).attr("FieldCount", "0");

$(self).attr("uniqueId", options.linkClass + Math.random());

$(self).find("." + options.linkClass).remove();

$(self).find("." + options.removeLinkClass).remove();

$(self).append(" <a href='#' class='" + options.linkClass + "'>" + options.linkText + "</a>");

$(self).find("." + options.linkClass).unbind("click").click(function () {
return handleAdd($(this));
});

var myClone = $(self).clone();

if (options.data.length > 0) {
var $curElem = $(self);
for (var i = 0; i < options.data.length; i++) {
$curElem.find("input,select,textarea").each(function () {
var itemName = $(this).attr("recName");
$(this).val(options.data[i][itemName]);
});
$curElem.find("." + options.linkClass).trigger("click");
$curElem = $curElem.next();
}
}

function handleAdd(elem) {
if (options.beforeAddEventCallback !== null) {
if (!options.beforeAddEventCallback(self)) {
return false;
}
}
var totalCount = parseInt($(self).attr("TotalFieldsAdded"), 10);
var fieldCount = parseInt($(self).attr("FieldCount"), 10);
if (options.maxItemsAllowedToAdd === null || totalCount < options.maxItemsAllowedToAdd) {
var newElem = myClone.clone();

$(newElem).find("*[id!=''][name!='']").each(function () {
if ($(this).attr("id")) {
var strid = $(this).attr("id");
var strname = "";

if ($(this).attr("name")) {
strname = $(this).attr("name");
}

$(this).attr("id", strid + "_" + fieldCount);
$(this).attr("name", strname + "$" + fieldCount);
}
});

totalCount++;
fieldCount++;

$(self).attr("TotalFieldsAdded", totalCount);
$(self).attr("FieldCount", fieldCount);

$(newElem).removeAttr("uniqueId");

if (options.enableRemove && $(self).attr("uniqueId") != $(elem).parent().attr("uniqueId")) {
if ($(elem).parent().find("." + options.removeLinkClass).length === 0) {
$(elem).parent().append(" <a href='#' class='" + options.removeLinkClass + "'>" + options.removeLinkText + "</a>");
}
$(elem).parent().find("." + options.removeLinkClass).unbind("click").click(function () {
return handleRemove($(this));
});
}

$(newElem).attr("uniqueId", options.linkClass + Math.random());

$(elem).parent().after(newElem);

$(elem).parent().find("." + options.linkClass).remove();

$(newElem).find("." + options.linkClass).remove();
$(newElem).find("." + options.removeLinkClass).remove();

if (options.enableRemove) {
if ($(newElem).find("." + options.removeLinkClass).length === 0) {
$(newElem).append(" <a href='#' class='" + options.removeLinkClass + "'>" + options.removeLinkText + "</a>");
}
$(newElem).find("." + options.removeLinkClass).unbind("click").click(function () {
return handleRemove($(this));
});
}

$(self).attr("maxCountReached", "false");

$(newElem).append(" <a href='#' class='" + options.linkClass + "'>" + options.linkText + "</a>");

newElem.find("." + options.linkClass).unbind("click").click(function () {
return handleAdd($(this));
});

if (options.addEventCallback !== null) {
options.addEventCallback($(newElem), self);
}
}

if (options.maxItemsAllowedToAdd !== null && totalCount >= options.maxItemsAllowedToAdd) {
newElem.find("." + options.linkClass).hide();

if (options.maxItemReachedCallback !== null) {
options.maxItemReachedCallback($(newElem), self);
}
}

return false;
}

function handleRemove(elem) {
var cnt = true;

if (options.confirmOnRemove) {
cnt = confirm(options.confirmationMsgOnRemove);
}
if (cnt) {
var prevParent = $(elem).parent().prev();

var totalCount = parseInt($(self).attr("TotalFieldsAdded"), 10);
totalCount--;

$(self).attr("TotalFieldsAdded", totalCount);

if ($(elem).parent().find("." + options.linkClass).length > 0) {
if (options.enableRemove && $(self).attr("uniqueId") != $(prevParent).attr("uniqueId")) {
if ($(prevParent).find("." + options.removeLinkClass).length === 0) {
$(prevParent).append(" <a href='#' class='" + options.removeLinkClass + "'>" + options.removeLinkText + "</a>");
}

$(prevParent).find("." + options.removeLinkClass).unbind("click").click(function () {
return handleRemove($(this));
});
}

$(prevParent).append(" <a href='#' class='" + options.linkClass + "'>" + options.linkText + "</a>");

prevParent.find("." + options.linkClass).unbind("click").click(function () {
return handleAdd($(this));
});
}

if (options.maxItemsAllowedToAdd !== null && totalCount < options.maxItemsAllowedToAdd) {
$(self).siblings().find("." + options.linkClass).show();
}

$(elem).parent().remove();

if (options.removeEventCallback !== null) {
options.removeEventCallback($(prevParent), self);
}
}
return false;
}
});
};
})(jQuery);
2 changes: 1 addition & 1 deletion js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ window.accessdb.appRouter.on('route:results-technique', function (id) {
});
window.accessdb.appRouter.on('route:results-test', function (id) {
TestUnit.prototype.loadById(id, function(test){
$(".results-test-id").html(test.testUnitId);
$(".results-test-id").html(Utils.stripTestID(test.testUnitId));
$(".results-test-title").html(test.title);
});
this.params.testUnitId = id;
Expand Down
16 changes: 8 additions & 8 deletions templates.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script type="text/template" id="test-details-template">
<h1><span class="id"><%= t.testUnitId %></span>: <%= t.title %></h1>
<h1><span class="id"><%= Utils.stripTestID(t.testUnitId) %></span>: <%= t.title %></h1>
<div class="column-second">
<div class="roleExpertsOnly admin">
<a class="btn" href="#test-submit.html/<%= t.testUnitId %>"><span class="icon-pencil"></span> Edit Test</a>
Expand Down Expand Up @@ -35,7 +35,7 @@ <h2>More Information</h2>
</span>
</span>
</button>
<span id="<%= test.testUnitId %>"><%= test.title %> (<%= test.testUnitId %>)</span>
<span id="<%= test.testUnitId %>"><%= test.title %> (<%= Utils.stripTestID(test.testUnitId) %>)</span>
</li>
</script>
<script type="text/template" id="user-profile-template">
Expand Down Expand Up @@ -99,11 +99,11 @@ <h2>Submit test results</h2>
</script>
<script type="text/template" id="test-run-template">
<header>
<h2><span class="subheading">Test : <%= test.testUnitId %></span> <%= test.title %></h2>
<h2><span class="subheading">Test : <%= Utils.stripTestID(test.testUnitId) %></span> <%= test.title %></h2>
</header>
<section>
<h3>Test Description</h3>
<p><%= test.testUnitId %></p>
<p><%= Utils.stripTestID(test.testUnitId) %></p>
</section>

<section>
Expand Down Expand Up @@ -278,7 +278,7 @@ <h3>Test Results</h3>
<% first = false %>
<% } %>
<th scope="row">
<%= r.testUnitId %>: <a role="button" href="#/test.html/<%= r.testUnitId %>"> <%= r.testTitle %></a> <!-- Link to test case -->
<%= Utils.stripTestID(r.testUnitId) %>: <a role="button" href="#/test.html/<%= r.testUnitId %>"> <%= r.testTitle %></a> <!-- Link to test case -->
</th>
<td class="result">
<a role="button" href="#/results-test.html/<%= r.testUnitId %>" class="btn btn-small">
Expand All @@ -296,7 +296,7 @@ <h3>Test Results</h3>
<ul id="RelatedTestCases">
<% _.each(results, function(r) { %>
<li>
<strong><%= r.testUnitId %>:</strong> <a role="button" href="#/results-test.html/<%= r.testUnitId %>"> <%= r.testTitle %></a>
<strong><%= Utils.stripTestID(r.testUnitId) %>:</strong> <a role="button" href="#/results-test.html/<%= r.testUnitId %>"> <%= r.testTitle %></a>
<a role="button" href="#/results-test.html/<%= r.testUnitId %>" class="btn btn-small">
<span class="chart" style="display:none"><%= r.noOfPass %>/<%= r.noOfAll %></span>
<%= r.noOfPass %>/<%= r.noOfAll %>
Expand All @@ -309,15 +309,15 @@ <h3>Test Results</h3>
</ul>
</script>
<script type="text/template" id="Results_template">
<h1>Test Results for <%=params.type%> <%=params.typeValue%>, <%=params.ua%> <%=params.uaVer%> with <%=params.at%> <%=params.atVer%></h1>
<h1>Test Results for <%=params.type%> <%=Utils.stripTestID(params.typeValue)%>, <%=params.ua%> <%=params.uaVer%> with <%=params.at%> <%=params.atVer%></h1>
<div class="">
<div class="column-second">
<div id="Results"><!-- Template: Results_template --></div>
</div>
</div>
<% _.each(results, function(r) { %>
<table class="testcase-details">
<caption><strong>Testcase:</strong> <a href="#/results-test.html/<%= r.testUnitId %>"><%= r.testUnitId %></a>: <%=r.testTitle%></caption>
<caption><strong>Testcase:</strong> <a href="#/results-test.html/<%= r.testUnitId %>"><%= Utils.stripTestID(r.testUnitId) %></a>: <%=r.testTitle%></caption>
<col class="col1"> <col class="col2"> <col class="col3"> <col class="col4"> <col class="col5"> <col class="col6 admin roleAdminOnly">
<thead>
<tr>
Expand Down

0 comments on commit 73b6fef

Please sign in to comment.