Skip to content

Commit

Permalink
All major UI components done
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJaredWilcurt committed Aug 7, 2017
1 parent 39bd392 commit 43495da
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 57 deletions.
95 changes: 42 additions & 53 deletions _scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,28 @@ var updateDonutChart = window.updateDonutChart;
var appData = nw.App.dataPath;
var temp = path.join(appData, 'temp');

if (ugui.args.badgeError.value == 'false') {
$('#button-badges .btn-danger').addClass('disabled');
}
if (ugui.args.badgeWarning.value == 'false') {
$('#button-badges .btn-warning').addClass('disabled');
}
if (ugui.args.badgeNotice.value == 'false') {
$('#button-badges .btn-primary').addClass('disabled');
}

$('#button-badges .btn-danger, #button-badges .btn-warning, #button-badges .btn-primary').click(function () {
app.reset();

if ($(this).hasClass('disabled')) {
$(this).removeClass('disabled');
$(this).val('true');
} else {
$(this).addClass('disabled');
$(this).val('false');
}

ugui.helpers.buildUGUIArgObject();
app.saveSettings();
app.unlockRun();
});

var app = new Vue({
el: '#pa11y',
data: {
version: '2.0.0',

url: '',
outputFileName: '',
outputType: '',
standard: '',
folderPicker: '',
imageAlts: '',

errorsButton: true,
warningsButton: true,
noticesButton: true,
badges: {
errors: 0,
wargings: 0,
warnings: 0,
notices: 0
}
},

submitAllowed: false
},
methods: {
// Settings and defaults
Expand Down Expand Up @@ -168,26 +146,38 @@ var updateDonutChart = window.updateDonutChart;
this.badges.notices = 0;
},
unlockRun: function () {
ugui.helpers.buildUGUIArgObject();

var url = this.url;
var dest = this.folderPicker;
var destination = this.folderPicker;
var file = this.outputFileName;
var errorsButton = (ugui.args.badgeError.value === 'true');
var warningsButton = (ugui.args.badgeWarning.value === 'true');
var noticesButton = (ugui.args.badgeNotice.value === 'true');
var imgAltsVal = this.imageAlts;

var anyButtonEnabled = (this.errorsButton || this.warningsButton || this.noticesButton);

var imgAltsParsed = '';
if (imgAltsVal) {
imgAltsParsed = tryParseJSON(imgAltsVal);
if (this.imageAlts) {
imgAltsParsed = this.tryParseJSON(this.imageAlts);
}
var imageAltsInUse = !!this.imageAlts && (imgAltsParsed.length > 0) && (typeof(imgAltsParsed) === 'object');

// To unlock you need a URL/Destination/Filename and at least one button pressed (err/warn/notic), or some valid JSON in the imageAlts box
if (url && dest && file && ((errorsButton || warningsButton || noticesButton) || (!!imgAltsVal && (imgAltsParsed.length > 0) && (typeof(imgAltsParsed) == 'object')))) {
$('#run').prop('disabled', false);
if (url && destination && file && (anyButtonEnabled || imageAltsInUse)) {
this.submitAllowed = false;
} else {
$('#run').prop('disabled', true);
this.submitAllowed = true;
}
},
tryParseJSON: function (jsonString) {
try {
var obj = JSON.parse(jsonString);
if (obj && typeof(obj) === 'object') {
return obj;
}
} catch (err) {
// eslint-disable-line no-empty
// If we log the err here it will spam the console anytime the user pastes non-json or types in the box
}

return false;
},

// URL Stuff
urlKeyup: function () {
Expand Down Expand Up @@ -243,6 +233,17 @@ var updateDonutChart = window.updateDonutChart;
showHideImageAltsBox();
},

// Error/Warning/Notice Buttons
toggleButton: function (button) {
event.preventDefault();
this.reset();

this[button] = !this[button];

app.saveSettings();
this.unlockRun();
},

clipboard: function (evt) {
evt.preventDefault();
var data = fs.readFileSync('_scripts/imgalts5.min.js', 'binary');
Expand Down Expand Up @@ -280,19 +281,7 @@ var updateDonutChart = window.updateDonutChart;
nw.Window.get().showDevTools();
});

function tryParseJSON (jsonString) {
try {
var obj = JSON.parse(jsonString);
if (obj && typeof obj === 'object') {
return obj;
}
} catch (err) {
// eslint-disable-line no-empty
// If we log the err here it will spam the console anytime the user pastes non-json or types in the box
}

return false;
}



Expand Down Expand Up @@ -599,7 +588,7 @@ var updateDonutChart = window.updateDonutChart;
// If there is text in the textarea and we aren't on CSV which doesn't support image stats output
if (imgAltsVal && app.outputType === 'csv') {
// This will output an error if JSON is invalid, or if there is no text
window.imgAltsParsed = tryParseJSON(imgAltsVal);
window.imgAltsParsed = app.tryParseJSON(imgAltsVal);
// If the text is valid JSON
if (window.imgAltsParsed.length > 0 && typeof(window.imgAltsParsed) == 'object') {
$('#imageAltsModal').fadeIn('slow');
Expand Down
8 changes: 4 additions & 4 deletions index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,17 @@ <h3>
<div class="row" id="button-row">
<div class="col-xs-12 col-s-12 col-md-12 col-l-12 text-left" style="vertical-align: middle">
<span id="button-badges">
<button class="btn btn-sm btn-danger" type="button" value="true" data-argName="badgeError">
<button class="btn btn-sm btn-danger" :class="{'disabled': !errorsButton}" @click="toggleButton('errorsButton')">
Errors <span class="badge">{{ badges.errors }}</span>
</button>
<button class="btn btn-sm btn-warning" type="button" value="true" data-argName="badgeWarning">
<button class="btn btn-sm btn-warning" :class="{'disabled': !warningsButton}" @click="toggleButton('warningsButton')">
Warnings <span class="badge">{{ badges.warnings }}</span>
</button>
<button class="btn btn-sm btn-primary" type="button" value="true" data-argName="badgeNotice">
<button class="btn btn-sm btn-primary" :class="{'disabled': !noticesButton}" @click="toggleButton('noticesButton')">
Notices <span class="badge">{{ badges.notices }}</span>
</button>
</span>
<button type="submit" id="run" class="btn btn-primary pull-right">Run!</button>
<button type="submit" id="run" class="btn btn-primary pull-right" :disabled="submitAllowed">Run!</button>
</div>
</div>

Expand Down

0 comments on commit 43495da

Please sign in to comment.