Skip to content

Commit

Permalink
Refactoring of js (restructuring, full eradication of jsLint hints, c…
Browse files Browse the repository at this point in the history
…omments - some based on javascript.crockford.com). Assembly info files supplemented.
  • Loading branch information
jwaliszko committed Jul 8, 2014
1 parent 000f7d2 commit ff4a94f
Show file tree
Hide file tree
Showing 8 changed files with 542 additions and 542 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// associated with an assembly.
[assembly: AssemblyTitle("ExpressiveAnnotations.MvcUnobtrusiveValidatorProvider")]
[assembly: AssemblyCopyright("Copyright © Jaroslaw Waliszko 2014")]
[assembly: AssemblyProduct("ExpressiveAnnotations.MvcUnobtrusiveValidatorProvider")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// associated with an assembly.
[assembly: AssemblyTitle("ExpressiveAnnotations.MvcWebSample")]
[assembly: AssemblyCopyright("Copyright © Jaroslaw Waliszko 2014")]
[assembly: AssemblyProduct("ExpressiveAnnotations.MvcWebSample")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
* copyright (c) 2014 Jaroslaw Waliszko - https://github.com/JaroslawWaliszko
* licensed MIT: http://www.opensource.org/licenses/mit-license.php */

(function($, analyser) {

(function($, analyser, helper) {
'use strict';

var modelPrefix, miscHelper, attributeInternals, expressionAttributeInternals;

var
modelPrefix = {
append: function(value, prefix) {
return prefix + value;
},
get: function(fieldName) {
return fieldName.substr(0, fieldName.lastIndexOf('.') + 1);
}
};
},

miscHelper = {
extractValue: function(form, name, prefix, type) {
Expand All @@ -37,31 +34,31 @@
name = modelPrefix.append(name, prefix);
field = $(form).find(':input[name="' + name + '"]');
if (field.length === 0) {
throw analyser.typeHelper.String.format('DOM field {0} not found.', name);
throw helper.string.format('DOM field {0} not found.', name);
}

fieldValue = getFieldValue(field);
if (fieldValue === undefined || fieldValue === null || fieldValue === '') { // field value not set
return null;
}

parsedValue = analyser.typeHelper.tryParse(fieldValue, type); // convert to required type
parsedValue = helper.tryParse(fieldValue, type); // convert to required type
if (parsedValue.error) {
throw 'Data extraction fatal error. DOM value conversion to reflect required type failed.';
}

return parsedValue;
},
tryExtractName: function(targetValue) {
if (analyser.typeHelper.isString(targetValue)) {
if (helper.isString(targetValue)) {
var patt = new RegExp('\\[(.+)\\]');
if (patt.test(targetValue)) {
return targetValue.substring(1, targetValue.length - 1);
}
}
return { error: true };
}
};
},

attributeInternals = {
verify: function(params) {
Expand All @@ -78,7 +75,7 @@
comparer = new analyser.Comparer();
return comparer.compute(dependentValue, targetValue, params.relationaloperator, params.sensitivecomparisons);
}
};
},

expressionAttributeInternals = {
verify: function(params) {
Expand All @@ -101,7 +98,7 @@
tokens.push(result.toString());
}

composedExpression = analyser.typeHelper.String.format(params.expression, tokens);
composedExpression = helper.string.format(params.expression, tokens);
evaluator = new analyser.Evaluator();
return evaluator.compute(composedExpression);
}
Expand Down Expand Up @@ -138,7 +135,7 @@
}
});

$.validator.unobtrusive.adapters.add('requiredif', ['dependentproperty', 'relationaloperator', 'targetvalue', 'type', 'sensitivecomparisons', 'allowemptyorfalse', 'callertype'], function (options) {
$.validator.unobtrusive.adapters.add('requiredif', ['dependentproperty', 'relationaloperator', 'targetvalue', 'type', 'sensitivecomparisons', 'allowemptyorfalse', 'callertype'], function(options) {
options.rules.requiredif = {
prefix: modelPrefix.get(options.element.name),
form: options.form,
Expand All @@ -156,7 +153,7 @@
}
});

$.validator.unobtrusive.adapters.add('requiredifexpression', ['dependentproperties', 'relationaloperators', 'targetvalues', 'types', 'expression', 'sensitivecomparisons', 'allowemptyorfalse', 'callertype'], function (options) {
$.validator.unobtrusive.adapters.add('requiredifexpression', ['dependentproperties', 'relationaloperators', 'targetvalues', 'types', 'expression', 'sensitivecomparisons', 'allowemptyorfalse', 'callertype'], function(options) {
options.rules.requiredifexpression = {
prefix: modelPrefix.get(options.element.name),
form: options.form,
Expand All @@ -174,7 +171,7 @@
}
});

$.validator.addMethod('assertthat', function (value, element, params) {
$.validator.addMethod('assertthat', function(value, element, params) {
value = $(element).attr('type') === 'checkbox' ? $(element).is(':checked') : value; // special treatment for checkbox, because when unchecked, false value should be retrieved instead of undefined
if (!(value === undefined || value === null || value === '')) { // check if the field value is set (continue if so, otherwise skip condition verification)
if (!attributeInternals.verify(params)) { // check if the assertion condition is not satisfied
Expand All @@ -184,7 +181,7 @@
return true;
}, '');

$.validator.addMethod('assertthatexpression', function (value, element, params) {
$.validator.addMethod('assertthatexpression', function(value, element, params) {
value = $(element).attr('type') === 'checkbox' ? $(element).is(':checked') : value;
if (!(value === undefined || value === null || value === '')) {
if (!expressionAttributeInternals.verify(params)) {
Expand All @@ -194,10 +191,10 @@
return true;
}, '');

$.validator.addMethod('requiredif', function (value, element, params) {
$.validator.addMethod('requiredif', function(value, element, params) {
value = $(element).attr('type') === 'checkbox' ? $(element).is(':checked') : value;
if (params.callertype === 'bool') {
var boolValue = analyser.typeHelper.Bool.tryParse(value);
var boolValue = helper.bool.tryParse(value);
if (boolValue.error /* conversion fail indicates that field value is not set - required */ || (!boolValue && !params.allowemptyorfalse)) {
if (attributeInternals.verify(params)) { // check if the requirement condition is satisfied
return false; // requirement confirmed => notify
Expand All @@ -213,10 +210,10 @@
return true;
}, '');

$.validator.addMethod('requiredifexpression', function (value, element, params) {
$.validator.addMethod('requiredifexpression', function(value, element, params) {
value = $(element).attr('type') === 'checkbox' ? $(element).is(':checked') : value;
if (params.callertype === 'bool') {
var boolValue = analyser.typeHelper.Bool.tryParse(value);
var boolValue = helper.bool.tryParse(value);
if (boolValue.error || (!boolValue && !params.allowemptyorfalse)) {
if (expressionAttributeInternals.verify(params)) {
return false;
Expand All @@ -232,4 +229,4 @@
return true;
}, '');

}(jQuery, logicalExpressionsAnalyser));
}(jQuery, ea.analyser, ea.helper));
1 change: 1 addition & 0 deletions src/ExpressiveAnnotations.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// associated with an assembly.
[assembly: AssemblyTitle("ExpressiveAnnotations.Tests")]
[assembly: AssemblyCopyright("Copyright © Jaroslaw Waliszko 2014")]
[assembly: AssemblyProduct("ExpressiveAnnotations.Tests")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand Down
5 changes: 3 additions & 2 deletions src/ExpressiveAnnotations/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// associated with an assembly.
[assembly: AssemblyTitle("ExpressiveAnnotations")]
[assembly: AssemblyCopyright("Copyright © Jaroslaw Waliszko 2014")]
[assembly: AssemblyProduct("ExpressiveAnnotations")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand All @@ -28,5 +29,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyVersion("1.4.2.0")]
[assembly: AssemblyFileVersion("1.4.2.0")]
Loading

0 comments on commit ff4a94f

Please sign in to comment.