Skip to content

Commit

Permalink
Merge branch 'develop' into unit-testing-support
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeTschudi committed Aug 14, 2015
1 parent d554b94 commit c311d2c
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 16 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h2 class="screenreaderInfo">Social media sign-in</h2>
<div class="row fillHeight">

<h2 class="screenreaderInfo">Photo gallery</h2>
<article class="mainContent fillHeight col-sm-9 col-md-9 repad">
<article id="mainContent" class="mainContent fillHeight col-sm-9 col-md-9 repad">
<div id="carousel" class="carousel slide" data-ride="carousel" data-interval="false">
<!-- Wrapper for slides -->
<div id="carouselSlidesHolder" class="carousel-inner" role="listbox"></div>
Expand Down Expand Up @@ -102,7 +102,7 @@ <h2 class="screenreaderInfo">Survey</h2>
<div id="remainingToNextLevel" class="profileRankToGo"></div>
</div>
</div>
<div class="action-bar">
<div id="profileActionBar" class="action-bar">
<button id="closeProfileBtn" type="button" class="btn skip-button">&lt; Back to survey</button>
</div>
</article>
Expand Down
72 changes: 58 additions & 14 deletions js/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ define(['lib/i18n.min!nls/resources.js', 'prepareAppConfigInfo', 'handleUserSign
var user = handleUserSignin.getUser();
//diag.clearCode(); //???

// Make sure that the main content is available
showMainContent();

// Heading on survey/profile page
$("#name")[0].innerHTML = user.name;
$("#name2")[0].innerHTML = user.name;
Expand Down Expand Up @@ -263,7 +266,18 @@ define(['lib/i18n.min!nls/resources.js', 'prepareAppConfigInfo', 'handleUserSign
handleUserSignin.signOut();
});

$(document).on('show:noSurveys', function (e) {
// No more surveys available either due to error or completion
// Hide the main content
hideMainContent();

// Show the profile view & help window
$(document).triggerHandler('show:profile');
$('#additionalInfoPanel').modal('show');
});

$(document).on('show:newSurvey', function (e) {
var isReadOnly = !(prepareAppConfigInfo.featureSvcParams.canBeUpdated && handleUserSignin.getUser().canSubmit);
$("#submitBtn")[0].blur();

// Provide some visual feedback for the switch to a new survey
Expand All @@ -273,10 +287,12 @@ define(['lib/i18n.min!nls/resources.js', 'prepareAppConfigInfo', 'handleUserSign
dataAccess.getCandidate(prepareAppConfigInfo.appParams.randomizeSelection).then(function (candidate) {
// obj:feature{}
// attachments:[{id,url},...]
var showThumbnails = (prepareAppConfigInfo.appParams.thumbnailLimit < 0) ||
(candidate.attachments.length <= prepareAppConfigInfo.appParams.thumbnailLimit);

that.numPhotos = candidate.attachments.length;
if (!candidate.obj) {
$(document).triggerHandler('show:newSurvey');
$(document).triggerHandler('show:noSurveys');
return;
} else if (that.numPhotos === 0) {
diag.appendWithLF("no photos for property <i>" + JSON.stringify(candidate.obj.attributes) + "</i>"); //???
Expand All @@ -303,29 +319,34 @@ define(['lib/i18n.min!nls/resources.js', 'prepareAppConfigInfo', 'handleUserSign

$.each(candidate.attachments, function (indexInArray, attachment) {
addPhoto(carouselSlidesHolder, indexInArray, (initiallyActiveItem === indexInArray), attachment.url);
addPhotoIndicator(carouselIndicatorsHolder, indexInArray, (initiallyActiveItem === indexInArray),
"carousel", attachment.url);
if (showThumbnails) {
addPhotoIndicator(carouselIndicatorsHolder, indexInArray, (initiallyActiveItem === indexInArray),
"carousel", attachment.url);
}
});
$("#carousel").trigger('create');

updatePhotoSelectionDisplay();

// Provide some visual feedback for the switch to a new survey
$("#surveyContainer").fadeTo(1000, 1.0);
$("#surveyContainer").fadeTo(1000, (isReadOnly ? 0.75 : 1.0));

}).fail(function (error) {
});

// Survey
var surveyContainer = $("#surveyContainer")[0];
$(surveyContainer).children().remove(); // remove children and their events
$.each(prepareAppConfigInfo.survey, function (indexInArray, questionInfo) {
addQuestion(surveyContainer, indexInArray, questionInfo);
addQuestion(surveyContainer, indexInArray, questionInfo, isReadOnly);
});
$(".btn-group").trigger('create');

// Can submit?
$("#submitBtn").attr("disabled",
!(prepareAppConfigInfo.featureSvcParams.canBeUpdated && handleUserSignin.getUser().canSubmit));
$("#submitBtn").css("display",
isReadOnly
? "none"
: "inline-block");

// Show the content
$("#contentPage").fadeIn("fast");
Expand Down Expand Up @@ -524,7 +545,7 @@ diag.appendWithLF("block slide to " + data.direction); //???
return start;
}

function createButtonChoice(surveyContainer, iQuestion, questionInfo) {
function createButtonChoice(surveyContainer, iQuestion, questionInfo, isReadOnly) {
// <div id='q1' class='btn-group'>
// <button type='button' class='btn'>Yes</button>
// <button type='button' class='btn'>No</button>
Expand All @@ -533,13 +554,13 @@ diag.appendWithLF("block slide to " + data.direction); //???
var buttons = "<div id='q" + iQuestion + "' class='btn-group'>";
var domain = questionInfo.domain.split('|');
$.each(domain, function (i, choice) {
buttons += "<button type='button' class='btn' value='" + i + "'>" + choice + "</button>";
buttons += "<button type='button' class='btn' value='" + i + "' " + (isReadOnly ? "disabled" : "") + ">" + choice + "</button>";
});
buttons += "</div>";
return buttons;
}

function createListChoice(surveyContainer, iQuestion, questionInfo) {
function createListChoice(surveyContainer, iQuestion, questionInfo, isReadOnly) {
// <div class='radio'><label><input type='radio' name='q1' id='optionFound1' value='0'>Crawlspace</label></div>
// <div class='radio'><label><input type='radio' name='q1' id='optionFound2' value='1'>Raised</label></div>
// <div class='radio'><label><input type='radio' name='q1' id='optionFound3' value='2'>Elevated</label></div>
Expand All @@ -548,7 +569,7 @@ diag.appendWithLF("block slide to " + data.direction); //???
var list = "";
var domain = questionInfo.domain.split('|');
$.each(domain, function (i, choice) {
list += "<div class='radio'><label><input type='radio' name='q" + iQuestion + "' value='" + i + "'>" + choice + "</label></div>";
list += "<div class='radio'><label><input type='radio' name='q" + iQuestion + "' value='" + i + "' " + (isReadOnly ? "disabled" : "") + ">" + choice + "</label></div>";
});
return list;
}
Expand All @@ -560,12 +581,12 @@ diag.appendWithLF("block slide to " + data.direction); //???
return wrap;
}

function addQuestion(surveyContainer, iQuestion, questionInfo) {
function addQuestion(surveyContainer, iQuestion, questionInfo, isReadOnly) {
var question = startQuestion(surveyContainer, iQuestion, questionInfo);
if (questionInfo.style === "button") {
question += createButtonChoice(surveyContainer, iQuestion, questionInfo);
question += createButtonChoice(surveyContainer, iQuestion, questionInfo, isReadOnly);
} else {
question += createListChoice(surveyContainer, iQuestion, questionInfo);
question += createListChoice(surveyContainer, iQuestion, questionInfo, isReadOnly);
}
question += wrapupQuestion(surveyContainer, iQuestion, questionInfo);
$(surveyContainer).append(question);
Expand Down Expand Up @@ -605,6 +626,29 @@ diag.appendWithLF("block slide to " + data.direction); //???

//------------------------------------------------------------------------------------------------------------------------//


function showMainContent() {
// Hide the main content
$("#mainContent").css("visibility", "visible");

// Hide the profile's action bar
$("#profileActionBar").css("display", "block");

// Switch out the help display
$("#helpBody")[0].innerHTML = prepareAppConfigInfo.appParams.helpText;
}

function hideMainContent() {
// Hide the main content
$("#mainContent").css("visibility", "hidden");

// Hide the profile's action bar
$("#profileActionBar").css("display", "none");

// Switch out the help display
$("#helpBody")[0].innerHTML = i18n.signin.noMoreSurveys;
}

function testURL(url, callback) {
$.ajax( {
type: 'HEAD',
Expand Down
38 changes: 38 additions & 0 deletions js/app/prepareAppConfigInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ define(['parseConfigInfo', 'fetchConfigInfo'], function (parseConfigInfo, fetchC
twitterUserUrl: "",
twitterCallbackUrl: "",
allowGuestSubmissions: false,
thumbnailLimit: "10",

surveyorNameField: "",
bestPhotoField: "",
Expand Down Expand Up @@ -156,6 +157,7 @@ define(['parseConfigInfo', 'fetchConfigInfo'], function (parseConfigInfo, fetchC
prepareAppConfigInfo.appParams.googleplusClientId !== null && prepareAppConfigInfo.appParams.googleplusClientId.length > 0;
prepareAppConfigInfo.appParams.showTwitter = prepareAppConfigInfo.toBoolean(prepareAppConfigInfo.appParams.showTwitter);
prepareAppConfigInfo.appParams.allowGuestSubmissions = prepareAppConfigInfo.toBoolean(prepareAppConfigInfo.appParams.allowGuestSubmissions, false);
that.appParams.thumbnailLimit = prepareAppConfigInfo.toNumber(that.appParams.thumbnailLimit, -1);

parametersReady.resolve(true);
}).fail(function () {
Expand Down Expand Up @@ -214,6 +216,42 @@ define(['parseConfigInfo', 'fetchConfigInfo'], function (parseConfigInfo, fetchC
return screenedObject;
},

/**
* Insures that a supplied value is a number.
* @param {number|string} numValue Item to check
* @param {number} [defaultValue] Value to use if numValue is not a number or convertable
* to a number from a string; if omitted, zero is used
* @return {number} Supplied number, supplied string converted to a number, the
* default value, or zero
*/
toNumber: function (numValue, defaultValue) {
var parsedNumValue;

// Fall back to default
if (defaultValue === undefined) {
defaultValue = 0;
}

if (typeof numValue === "number") {
return numValue;
}

if (typeof numValue === "string") {
try {
parsedNumValue = parseInt(numValue, 10);
if (isNaN(parsedNumValue)) {
parsedNumValue = defaultValue;
}
} catch (ignore) {
parsedNumValue = defaultValue;
}
} else {
parsedNumValue = defaultValue;
}

return parsedNumValue;
},

/** Normalizes a boolean value to true or false.
* @param {boolean|string} boolValue A true or false value that is returned directly or a string "true" or "false"
* (case-insensitive) that is interpreted and returned; if neither a a boolean or a usable string, falls back to
Expand Down
1 change: 1 addition & 0 deletions js/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

"randomizeSelection": true,
"allowGuestSubmissions": false,
"thumbnailLimit": "10",

"showGuest": "true",
"facebookAppId": "",
Expand Down

0 comments on commit c311d2c

Please sign in to comment.