Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

upgrade to VS2010

  • Loading branch information...
commit ab2c8d3bdb780e100f6f50ee9dc52f93927142a1 1 parent b070bf4
Mark Borcherding MarkBorcherding authored

Showing 20 changed files with 23,331 additions and 5,259 deletions. Show diff stats Hide diff stats

  1. +7 3 Nustache.Core.Tests/Nustache.Core.Tests.csproj
  2. +5 1 Nustache.Core/Nustache.Core.csproj
  3. +22 6 Nustache.Mvc.Example/Nustache.Mvc.Example.csproj
  4. +5,366 5,099 Nustache.Mvc.Example/Scripts/MicrosoftAjax.debug.js
  5. +2 3 Nustache.Mvc.Example/Scripts/MicrosoftAjax.js
  6. +73 2 Nustache.Mvc.Example/Scripts/MicrosoftMvcAjax.debug.js
  7. +9 7 Nustache.Mvc.Example/Scripts/MicrosoftMvcAjax.js
  8. +881 0 Nustache.Mvc.Example/Scripts/MicrosoftMvcValidation.debug.js
  9. +55 0 Nustache.Mvc.Example/Scripts/MicrosoftMvcValidation.js
  10. +8,061 0 Nustache.Mvc.Example/Scripts/jquery-1.4.1-vsdoc.js
  11. +6,111 0 Nustache.Mvc.Example/Scripts/jquery-1.4.1.js
  12. +167 0 Nustache.Mvc.Example/Scripts/jquery-1.4.1.min.js
  13. +1,292 0 Nustache.Mvc.Example/Scripts/jquery.validate-vsdoc.js
  14. +1,155 0 Nustache.Mvc.Example/Scripts/jquery.validate.js
  15. +31 0 Nustache.Mvc.Example/Scripts/jquery.validate.min.js
  16. +7 12 Nustache.Mvc.Example/Views/Web.config
  17. +73 120 Nustache.Mvc.Example/Web.config
  18. +5 1 Nustache.Mvc/Nustache.Mvc.csproj
  19. +4 4 Nustache.sln
  20. +5 1 nustache/nustache.csproj
10 Nustache.Core.Tests/Nustache.Core.Tests.csproj
... ... @@ -1,5 +1,5 @@
1   -<?xml version="1.0" encoding="utf-8"?>
2   -<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3 <PropertyGroup>
4 4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -12,6 +12,10 @@
12 12 <AssemblyName>Nustache.Core.Tests</AssemblyName>
13 13 <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14 14 <FileAlignment>512</FileAlignment>
  15 + <FileUpgradeFlags>
  16 + </FileUpgradeFlags>
  17 + <OldToolsVersion>3.5</OldToolsVersion>
  18 + <UpgradeBackupLocation />
15 19 </PropertyGroup>
16 20 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17 21 <DebugSymbols>true</DebugSymbols>
@@ -88,4 +92,4 @@
88 92 <Target Name="AfterBuild">
89 93 </Target>
90 94 -->
91   -</Project>
  95 +</Project>
6 Nustache.Core/Nustache.Core.csproj
... ... @@ -1,5 +1,5 @@
1 1 <?xml version="1.0" encoding="utf-8"?>
2   -<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  2 +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3 <PropertyGroup>
4 4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -12,6 +12,10 @@
12 12 <AssemblyName>Nustache.Core</AssemblyName>
13 13 <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
14 14 <FileAlignment>512</FileAlignment>
  15 + <FileUpgradeFlags>
  16 + </FileUpgradeFlags>
  17 + <OldToolsVersion>3.5</OldToolsVersion>
  18 + <UpgradeBackupLocation />
15 19 </PropertyGroup>
16 20 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17 21 <DebugSymbols>true</DebugSymbols>
28 Nustache.Mvc.Example/Nustache.Mvc.Example.csproj
... ... @@ -1,17 +1,24 @@
1   -<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 3 <PropertyGroup>
3 4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4 5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
5 6 <ProductVersion>9.0.30729</ProductVersion>
6 7 <SchemaVersion>2.0</SchemaVersion>
7 8 <ProjectGuid>{07E2AC37-08D6-46D4-A9DD-13F6A70E1427}</ProjectGuid>
8   - <ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
  9 + <ProjectTypeGuids>{F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
9 10 <OutputType>Library</OutputType>
10 11 <AppDesignerFolder>Properties</AppDesignerFolder>
11 12 <RootNamespace>Nustache.Mvc.Example</RootNamespace>
12 13 <AssemblyName>Nustache.Mvc.Example</AssemblyName>
13   - <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
  14 + <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14 15 <MvcBuildViews>false</MvcBuildViews>
  16 + <FileUpgradeFlags>
  17 + </FileUpgradeFlags>
  18 + <OldToolsVersion>3.5</OldToolsVersion>
  19 + <UpgradeBackupLocation />
  20 + <UseIISExpress>false</UseIISExpress>
  21 + <TargetFrameworkProfile />
15 22 </PropertyGroup>
16 23 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17 24 <DebugSymbols>true</DebugSymbols>
@@ -32,6 +39,7 @@
32 39 </PropertyGroup>
33 40 <ItemGroup>
34 41 <Reference Include="System" />
  42 + <Reference Include="System.ComponentModel.DataAnnotations" />
35 43 <Reference Include="System.Data" />
36 44 <Reference Include="System.Core">
37 45 <RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -39,13 +47,13 @@
39 47 <Reference Include="System.Data.DataSetExtensions">
40 48 <RequiredTargetFramework>3.5</RequiredTargetFramework>
41 49 </Reference>
42   - <Reference Include="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
  50 + <Reference Include="System.Web.Extensions" />
  51 + <Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
43 52 <Reference Include="System.Xml.Linq">
44 53 <RequiredTargetFramework>3.5</RequiredTargetFramework>
45 54 </Reference>
46 55 <Reference Include="System.Drawing" />
47 56 <Reference Include="System.Web" />
48   - <Reference Include="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
49 57 <Reference Include="System.Web.Abstractions" />
50 58 <Reference Include="System.Web.Routing" />
51 59 <Reference Include="System.Xml" />
@@ -70,6 +78,14 @@
70 78 <Content Include="Default.aspx" />
71 79 <Content Include="Global.asax" />
72 80 <None Include="Views\Home\Index.nustache" />
  81 + <Content Include="Scripts\jquery-1.4.1-vsdoc.js" />
  82 + <Content Include="Scripts\jquery-1.4.1.js" />
  83 + <Content Include="Scripts\jquery-1.4.1.min.js" />
  84 + <Content Include="Scripts\jquery.validate-vsdoc.js" />
  85 + <Content Include="Scripts\jquery.validate.js" />
  86 + <Content Include="Scripts\jquery.validate.min.js" />
  87 + <Content Include="Scripts\MicrosoftMvcValidation.debug.js" />
  88 + <Content Include="Scripts\MicrosoftMvcValidation.js" />
73 89 <Content Include="Web.config" />
74 90 <Content Include="Content\Site.css" />
75 91 <Content Include="Scripts\jquery-1.3.2.js" />
@@ -101,7 +117,7 @@
101 117 <Folder Include="Models\" />
102 118 </ItemGroup>
103 119 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
104   - <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
  120 + <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
105 121 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
106 122 Other similar extension points exist, see Microsoft.Common.targets.
107 123 <Target Name="BeforeBuild">
10,465 Nustache.Mvc.Example/Scripts/MicrosoftAjax.debug.js
5,366 additions, 5,099 deletions not shown
5 Nustache.Mvc.Example/Scripts/MicrosoftAjax.js
2 additions, 3 deletions not shown
75 Nustache.Mvc.Example/Scripts/MicrosoftMvcAjax.debug.js
@@ -84,6 +84,12 @@ Sys.Mvc.AjaxContext.prototype = {
84 84 return this._loadingElement;
85 85 },
86 86
  87 + get_object: function Sys_Mvc_AjaxContext$get_object() {
  88 + /// <value type="Object"></value>
  89 + var executor = this.get_response();
  90 + return (executor) ? executor.get_object() : null;
  91 + },
  92 +
87 93 get_response: function Sys_Mvc_AjaxContext$get_response() {
88 94 /// <value type="Sys.Net.WebRequestExecutor"></value>
89 95 return this._response;
@@ -128,6 +134,37 @@ Sys.Mvc.AsyncHyperlink.handleClick = function Sys_Mvc_AsyncHyperlink$handleClick
128 134
129 135 Sys.Mvc.MvcHelpers = function Sys_Mvc_MvcHelpers() {
130 136 }
  137 +Sys.Mvc.MvcHelpers._serializeSubmitButton = function Sys_Mvc_MvcHelpers$_serializeSubmitButton(element, offsetX, offsetY) {
  138 + /// <param name="element" type="Object" domElement="true">
  139 + /// </param>
  140 + /// <param name="offsetX" type="Number" integer="true">
  141 + /// </param>
  142 + /// <param name="offsetY" type="Number" integer="true">
  143 + /// </param>
  144 + /// <returns type="String"></returns>
  145 + if (element.disabled) {
  146 + return null;
  147 + }
  148 + var name = element.name;
  149 + if (name) {
  150 + var tagName = element.tagName.toUpperCase();
  151 + var encodedName = encodeURIComponent(name);
  152 + var inputElement = element;
  153 + if (tagName === 'INPUT') {
  154 + var type = inputElement.type;
  155 + if (type === 'submit') {
  156 + return encodedName + '=' + encodeURIComponent(inputElement.value);
  157 + }
  158 + else if (type === 'image') {
  159 + return encodedName + '.x=' + offsetX + '&' + encodedName + '.y=' + offsetY;
  160 + }
  161 + }
  162 + else if ((tagName === 'BUTTON') && (name.length) && (inputElement.type === 'submit')) {
  163 + return encodedName + '=' + encodeURIComponent(inputElement.value);
  164 + }
  165 + }
  166 + return null;
  167 +}
131 168 Sys.Mvc.MvcHelpers._serializeForm = function Sys_Mvc_MvcHelpers$_serializeForm(form) {
132 169 /// <param name="form" type="Object" domElement="true">
133 170 /// </param>
@@ -172,6 +209,11 @@ Sys.Mvc.MvcHelpers._serializeForm = function Sys_Mvc_MvcHelpers$_serializeForm(f
172 209 formBody.append('&');
173 210 }
174 211 }
  212 + var additionalInput = form._additionalInput;
  213 + if (additionalInput) {
  214 + formBody.append(additionalInput);
  215 + formBody.append('&');
  216 + }
175 217 return formBody.toString();
176 218 }
177 219 Sys.Mvc.MvcHelpers._asyncRequest = function Sys_Mvc_MvcHelpers$_asyncRequest(url, verb, body, triggerElement, ajaxOptions) {
@@ -200,8 +242,14 @@ Sys.Mvc.MvcHelpers._asyncRequest = function Sys_Mvc_MvcHelpers$_asyncRequest(url
200 242 body += '&';
201 243 }
202 244 body += 'X-Requested-With=XMLHttpRequest';
  245 + var upperCaseVerb = verb.toUpperCase();
  246 + var isGetOrPost = (upperCaseVerb === 'GET' || upperCaseVerb === 'POST');
  247 + if (!isGetOrPost) {
  248 + body += '&';
  249 + body += 'X-HTTP-Method-Override=' + upperCaseVerb;
  250 + }
203 251 var requestBody = '';
204   - if (verb.toUpperCase() === 'GET' || verb.toUpperCase() === 'DELETE') {
  252 + if (upperCaseVerb === 'GET' || upperCaseVerb === 'DELETE') {
205 253 if (url.indexOf('?') > -1) {
206 254 if (!url.endsWith('&')) {
207 255 url += '&';
@@ -218,7 +266,13 @@ Sys.Mvc.MvcHelpers._asyncRequest = function Sys_Mvc_MvcHelpers$_asyncRequest(url
218 266 }
219 267 var request = new Sys.Net.WebRequest();
220 268 request.set_url(url);
221   - request.set_httpVerb(verb);
  269 + if (isGetOrPost) {
  270 + request.set_httpVerb(verb);
  271 + }
  272 + else {
  273 + request.set_httpVerb('POST');
  274 + request.get_headers()['X-HTTP-Method-Override'] = upperCaseVerb;
  275 + }
222 276 request.set_body(requestBody);
223 277 if (verb.toUpperCase() === 'PUT') {
224 278 request.get_headers()['Content-Type'] = 'application/x-www-form-urlencoded;';
@@ -314,6 +368,14 @@ Sys.Mvc.MvcHelpers.updateDomElement = function Sys_Mvc_MvcHelpers$updateDomEleme
314 368
315 369 Sys.Mvc.AsyncForm = function Sys_Mvc_AsyncForm() {
316 370 }
  371 +Sys.Mvc.AsyncForm.handleClick = function Sys_Mvc_AsyncForm$handleClick(form, evt) {
  372 + /// <param name="form" type="Object" domElement="true">
  373 + /// </param>
  374 + /// <param name="evt" type="Sys.UI.DomEvent">
  375 + /// </param>
  376 + var additionalInput = Sys.Mvc.MvcHelpers._serializeSubmitButton(evt.target, evt.offsetX, evt.offsetY);
  377 + form._additionalInput = additionalInput;
  378 +}
317 379 Sys.Mvc.AsyncForm.handleSubmit = function Sys_Mvc_AsyncForm$handleSubmit(form, evt, ajaxOptions) {
318 380 /// <param name="form" type="Object" domElement="true">
319 381 /// </param>
@@ -322,6 +384,15 @@ Sys.Mvc.AsyncForm.handleSubmit = function Sys_Mvc_AsyncForm$handleSubmit(form, e
322 384 /// <param name="ajaxOptions" type="Sys.Mvc.AjaxOptions">
323 385 /// </param>
324 386 evt.preventDefault();
  387 + var validationCallbacks = form.validationCallbacks;
  388 + if (validationCallbacks) {
  389 + for (var i = 0; i < validationCallbacks.length; i++) {
  390 + var callback = validationCallbacks[i];
  391 + if (!callback()) {
  392 + return;
  393 + }
  394 + }
  395 + }
325 396 var body = Sys.Mvc.MvcHelpers._serializeForm(form);
326 397 Sys.Mvc.MvcHelpers._asyncRequest(form.action, form.method || 'post', body, form, ajaxOptions);
327 398 }
16 Nustache.Mvc.Example/Scripts/MicrosoftMvcAjax.js
@@ -6,17 +6,19 @@
6 6 Type.registerNamespace('Sys.Mvc');Sys.Mvc.$create_AjaxOptions=function(){return {};}
7 7 Sys.Mvc.InsertionMode=function(){};Sys.Mvc.InsertionMode.prototype = {replace:0,insertBefore:1,insertAfter:2}
8 8 Sys.Mvc.InsertionMode.registerEnum('Sys.Mvc.InsertionMode',false);Sys.Mvc.AjaxContext=function(request,updateTarget,loadingElement,insertionMode){this.$3=request;this.$4=updateTarget;this.$1=loadingElement;this.$0=insertionMode;}
9   -Sys.Mvc.AjaxContext.prototype={$0:0,$1:null,$2:null,$3:null,$4:null,get_data:function(){if(this.$2){return this.$2.get_responseData();}else{return null;}},get_insertionMode:function(){return this.$0;},get_loadingElement:function(){return this.$1;},get_response:function(){return this.$2;},set_response:function(value){this.$2=value;return value;},get_request:function(){return this.$3;},get_updateTarget:function(){return this.$4;}}
  9 +Sys.Mvc.AjaxContext.prototype={$0:0,$1:null,$2:null,$3:null,$4:null,get_data:function(){if(this.$2){return this.$2.get_responseData();}else{return null;}},get_insertionMode:function(){return this.$0;},get_loadingElement:function(){return this.$1;},get_object:function(){var $0=this.get_response();return ($0)?$0.get_object():null;},get_response:function(){return this.$2;},set_response:function(value){this.$2=value;return value;},get_request:function(){return this.$3;},get_updateTarget:function(){return this.$4;}}
10 10 Sys.Mvc.AsyncHyperlink=function(){}
11   -Sys.Mvc.AsyncHyperlink.handleClick=function(anchor,evt,ajaxOptions){evt.preventDefault();Sys.Mvc.MvcHelpers.$1(anchor.href,'post','',anchor,ajaxOptions);}
  11 +Sys.Mvc.AsyncHyperlink.handleClick=function(anchor,evt,ajaxOptions){evt.preventDefault();Sys.Mvc.MvcHelpers.$2(anchor.href,'post','',anchor,ajaxOptions);}
12 12 Sys.Mvc.MvcHelpers=function(){}
13   -Sys.Mvc.MvcHelpers.$0=function($p0){var $0=$p0.elements;var $1=new Sys.StringBuilder();var $2=$0.length;for(var $3=0;$3<$2;$3++){var $4=$0[$3];var $5=$4.name;if(!$5||!$5.length){continue;}var $6=$4.tagName.toUpperCase();if($6==='INPUT'){var $7=$4;var $8=$7.type;if(($8==='text')||($8==='password')||($8==='hidden')||((($8==='checkbox')||($8==='radio'))&&$4.checked)){$1.append(encodeURIComponent($5));$1.append('=');$1.append(encodeURIComponent($7.value));$1.append('&');}}else if($6==='SELECT'){var $9=$4;var $A=$9.options.length;for(var $B=0;$B<$A;$B++){var $C=$9.options[$B];if($C.selected){$1.append(encodeURIComponent($5));$1.append('=');$1.append(encodeURIComponent($C.value));$1.append('&');}}}else if($6==='TEXTAREA'){$1.append(encodeURIComponent($5));$1.append('=');$1.append(encodeURIComponent(($4.value)));$1.append('&');}}return $1.toString();}
14   -Sys.Mvc.MvcHelpers.$1=function($p0,$p1,$p2,$p3,$p4){if($p4.confirm){if(!confirm($p4.confirm)){return;}}if($p4.url){$p0=$p4.url;}if($p4.httpMethod){$p1=$p4.httpMethod;}if($p2.length>0&&!$p2.endsWith('&')){$p2+='&';}$p2+='X-Requested-With=XMLHttpRequest';var $0='';if($p1.toUpperCase()==='GET'||$p1.toUpperCase()==='DELETE'){if($p0.indexOf('?')>-1){if(!$p0.endsWith('&')){$p0+='&';}$p0+=$p2;}else{$p0+='?';$p0+=$p2;}}else{$0=$p2;}var $1=new Sys.Net.WebRequest();$1.set_url($p0);$1.set_httpVerb($p1);$1.set_body($0);if($p1.toUpperCase()==='PUT'){$1.get_headers()['Content-Type']='application/x-www-form-urlencoded;';}$1.get_headers()['X-Requested-With']='XMLHttpRequest';var $2=null;if($p4.updateTargetId){$2=$get($p4.updateTargetId);}var $3=null;if($p4.loadingElementId){$3=$get($p4.loadingElementId);}var $4=new Sys.Mvc.AjaxContext($1,$2,$3,$p4.insertionMode);var $5=true;if($p4.onBegin){$5=$p4.onBegin($4)!==false;}if($3){Sys.UI.DomElement.setVisible($4.get_loadingElement(),true);}if($5){$1.add_completed(Function.createDelegate(null,function($p1_0){
15   -Sys.Mvc.MvcHelpers.$2($1,$p4,$4);}));$1.invoke();}}
16   -Sys.Mvc.MvcHelpers.$2=function($p0,$p1,$p2){$p2.set_response($p0.get_executor());if($p1.onComplete&&$p1.onComplete($p2)===false){return;}var $0=$p2.get_response().get_statusCode();if(($0>=200&&$0<300)||$0===304||$0===1223){if($0!==204&&$0!==304&&$0!==1223){var $1=$p2.get_response().getResponseHeader('Content-Type');if(($1)&&($1.indexOf('application/x-javascript')!==-1)){eval($p2.get_data());}else{Sys.Mvc.MvcHelpers.updateDomElement($p2.get_updateTarget(),$p2.get_insertionMode(),$p2.get_data());}}if($p1.onSuccess){$p1.onSuccess($p2);}}else{if($p1.onFailure){$p1.onFailure($p2);}}if($p2.get_loadingElement()){Sys.UI.DomElement.setVisible($p2.get_loadingElement(),false);}}
  13 +Sys.Mvc.MvcHelpers.$0=function($p0,$p1,$p2){if($p0.disabled){return null;}var $0=$p0.name;if($0){var $1=$p0.tagName.toUpperCase();var $2=encodeURIComponent($0);var $3=$p0;if($1==='INPUT'){var $4=$3.type;if($4==='submit'){return $2+'='+encodeURIComponent($3.value);}else if($4==='image'){return $2+'.x='+$p1+'&'+$2+'.y='+$p2;}}else if(($1==='BUTTON')&&($0.length)&&($3.type==='submit')){return $2+'='+encodeURIComponent($3.value);}}return null;}
  14 +Sys.Mvc.MvcHelpers.$1=function($p0){var $0=$p0.elements;var $1=new Sys.StringBuilder();var $2=$0.length;for(var $4=0;$4<$2;$4++){var $5=$0[$4];var $6=$5.name;if(!$6||!$6.length){continue;}var $7=$5.tagName.toUpperCase();if($7==='INPUT'){var $8=$5;var $9=$8.type;if(($9==='text')||($9==='password')||($9==='hidden')||((($9==='checkbox')||($9==='radio'))&&$5.checked)){$1.append(encodeURIComponent($6));$1.append('=');$1.append(encodeURIComponent($8.value));$1.append('&');}}else if($7==='SELECT'){var $A=$5;var $B=$A.options.length;for(var $C=0;$C<$B;$C++){var $D=$A.options[$C];if($D.selected){$1.append(encodeURIComponent($6));$1.append('=');$1.append(encodeURIComponent($D.value));$1.append('&');}}}else if($7==='TEXTAREA'){$1.append(encodeURIComponent($6));$1.append('=');$1.append(encodeURIComponent(($5.value)));$1.append('&');}}var $3=$p0._additionalInput;if($3){$1.append($3);$1.append('&');}return $1.toString();}
  15 +Sys.Mvc.MvcHelpers.$2=function($p0,$p1,$p2,$p3,$p4){if($p4.confirm){if(!confirm($p4.confirm)){return;}}if($p4.url){$p0=$p4.url;}if($p4.httpMethod){$p1=$p4.httpMethod;}if($p2.length>0&&!$p2.endsWith('&')){$p2+='&';}$p2+='X-Requested-With=XMLHttpRequest';var $0=$p1.toUpperCase();var $1=($0==='GET'||$0==='POST');if(!$1){$p2+='&';$p2+='X-HTTP-Method-Override='+$0;}var $2='';if($0==='GET'||$0==='DELETE'){if($p0.indexOf('?')>-1){if(!$p0.endsWith('&')){$p0+='&';}$p0+=$p2;}else{$p0+='?';$p0+=$p2;}}else{$2=$p2;}var $3=new Sys.Net.WebRequest();$3.set_url($p0);if($1){$3.set_httpVerb($p1);}else{$3.set_httpVerb('POST');$3.get_headers()['X-HTTP-Method-Override']=$0;}$3.set_body($2);if($p1.toUpperCase()==='PUT'){$3.get_headers()['Content-Type']='application/x-www-form-urlencoded;';}$3.get_headers()['X-Requested-With']='XMLHttpRequest';var $4=null;if($p4.updateTargetId){$4=$get($p4.updateTargetId);}var $5=null;if($p4.loadingElementId){$5=$get($p4.loadingElementId);}var $6=new Sys.Mvc.AjaxContext($3,$4,$5,$p4.insertionMode);var $7=true;if($p4.onBegin){$7=$p4.onBegin($6)!==false;}if($5){Sys.UI.DomElement.setVisible($6.get_loadingElement(),true);}if($7){$3.add_completed(Function.createDelegate(null,function($p1_0){
  16 +Sys.Mvc.MvcHelpers.$3($3,$p4,$6);}));$3.invoke();}}
  17 +Sys.Mvc.MvcHelpers.$3=function($p0,$p1,$p2){$p2.set_response($p0.get_executor());if($p1.onComplete&&$p1.onComplete($p2)===false){return;}var $0=$p2.get_response().get_statusCode();if(($0>=200&&$0<300)||$0===304||$0===1223){if($0!==204&&$0!==304&&$0!==1223){var $1=$p2.get_response().getResponseHeader('Content-Type');if(($1)&&($1.indexOf('application/x-javascript')!==-1)){eval($p2.get_data());}else{Sys.Mvc.MvcHelpers.updateDomElement($p2.get_updateTarget(),$p2.get_insertionMode(),$p2.get_data());}}if($p1.onSuccess){$p1.onSuccess($p2);}}else{if($p1.onFailure){$p1.onFailure($p2);}}if($p2.get_loadingElement()){Sys.UI.DomElement.setVisible($p2.get_loadingElement(),false);}}
17 18 Sys.Mvc.MvcHelpers.updateDomElement=function(target,insertionMode,content){if(target){switch(insertionMode){case 0:target.innerHTML=content;break;case 1:if(content&&content.length>0){target.innerHTML=content+target.innerHTML.trimStart();}break;case 2:if(content&&content.length>0){target.innerHTML=target.innerHTML.trimEnd()+content;}break;}}}
18 19 Sys.Mvc.AsyncForm=function(){}
19   -Sys.Mvc.AsyncForm.handleSubmit=function(form,evt,ajaxOptions){evt.preventDefault();var $0=Sys.Mvc.MvcHelpers.$0(form);Sys.Mvc.MvcHelpers.$1(form.action,form.method||'post',$0,form,ajaxOptions);}
  20 +Sys.Mvc.AsyncForm.handleClick=function(form,evt){var $0=Sys.Mvc.MvcHelpers.$0(evt.target,evt.offsetX,evt.offsetY);form._additionalInput = $0;}
  21 +Sys.Mvc.AsyncForm.handleSubmit=function(form,evt,ajaxOptions){evt.preventDefault();var $0=form.validationCallbacks;if($0){for(var $2=0;$2<$0.length;$2++){var $3=$0[$2];if(!$3()){return;}}}var $1=Sys.Mvc.MvcHelpers.$1(form);Sys.Mvc.MvcHelpers.$2(form.action,form.method||'post',$1,form,ajaxOptions);}
20 22 Sys.Mvc.AjaxContext.registerClass('Sys.Mvc.AjaxContext');Sys.Mvc.AsyncHyperlink.registerClass('Sys.Mvc.AsyncHyperlink');Sys.Mvc.MvcHelpers.registerClass('Sys.Mvc.MvcHelpers');Sys.Mvc.AsyncForm.registerClass('Sys.Mvc.AsyncForm');
21 23 // ---- Do not remove this footer ----
22 24 // Generated using Script# v0.5.0.0 (http://projects.nikhilk.net)
881 Nustache.Mvc.Example/Scripts/MicrosoftMvcValidation.debug.js
... ... @@ -0,0 +1,881 @@
  1 +//!----------------------------------------------------------
  2 +//! Copyright (C) Microsoft Corporation. All rights reserved.
  3 +//!----------------------------------------------------------
  4 +//! MicrosoftMvcValidation.js
  5 +
  6 +
  7 +Type.registerNamespace('Sys.Mvc');
  8 +
  9 +////////////////////////////////////////////////////////////////////////////////
  10 +// Sys.Mvc.Validation
  11 +
  12 +Sys.Mvc.$create_Validation = function Sys_Mvc_Validation() { return {}; }
  13 +
  14 +
  15 +////////////////////////////////////////////////////////////////////////////////
  16 +// Sys.Mvc.JsonValidationField
  17 +
  18 +Sys.Mvc.$create_JsonValidationField = function Sys_Mvc_JsonValidationField() { return {}; }
  19 +
  20 +
  21 +////////////////////////////////////////////////////////////////////////////////
  22 +// Sys.Mvc.JsonValidationOptions
  23 +
  24 +Sys.Mvc.$create_JsonValidationOptions = function Sys_Mvc_JsonValidationOptions() { return {}; }
  25 +
  26 +
  27 +////////////////////////////////////////////////////////////////////////////////
  28 +// Sys.Mvc.JsonValidationRule
  29 +
  30 +Sys.Mvc.$create_JsonValidationRule = function Sys_Mvc_JsonValidationRule() { return {}; }
  31 +
  32 +
  33 +////////////////////////////////////////////////////////////////////////////////
  34 +// Sys.Mvc.ValidationContext
  35 +
  36 +Sys.Mvc.$create_ValidationContext = function Sys_Mvc_ValidationContext() { return {}; }
  37 +
  38 +
  39 +////////////////////////////////////////////////////////////////////////////////
  40 +// Sys.Mvc.NumberValidator
  41 +
  42 +Sys.Mvc.NumberValidator = function Sys_Mvc_NumberValidator() {
  43 +}
  44 +Sys.Mvc.NumberValidator.create = function Sys_Mvc_NumberValidator$create(rule) {
  45 + /// <param name="rule" type="Sys.Mvc.JsonValidationRule">
  46 + /// </param>
  47 + /// <returns type="Sys.Mvc.Validator"></returns>
  48 + return Function.createDelegate(new Sys.Mvc.NumberValidator(), new Sys.Mvc.NumberValidator().validate);
  49 +}
  50 +Sys.Mvc.NumberValidator.prototype = {
  51 +
  52 + validate: function Sys_Mvc_NumberValidator$validate(value, context) {
  53 + /// <param name="value" type="String">
  54 + /// </param>
  55 + /// <param name="context" type="Sys.Mvc.ValidationContext">
  56 + /// </param>
  57 + /// <returns type="Object"></returns>
  58 + if (Sys.Mvc._validationUtil.stringIsNullOrEmpty(value)) {
  59 + return true;
  60 + }
  61 + var n = Number.parseLocale(value);
  62 + return (!isNaN(n));
  63 + }
  64 +}
  65 +
  66 +
  67 +////////////////////////////////////////////////////////////////////////////////
  68 +// Sys.Mvc.FormContext
  69 +
  70 +Sys.Mvc.FormContext = function Sys_Mvc_FormContext(formElement, validationSummaryElement) {
  71 + /// <param name="formElement" type="Object" domElement="true">
  72 + /// </param>
  73 + /// <param name="validationSummaryElement" type="Object" domElement="true">
  74 + /// </param>
  75 + /// <field name="_validationSummaryErrorCss" type="String" static="true">
  76 + /// </field>
  77 + /// <field name="_validationSummaryValidCss" type="String" static="true">
  78 + /// </field>
  79 + /// <field name="_formValidationTag" type="String" static="true">
  80 + /// </field>
  81 + /// <field name="_onClickHandler" type="Sys.UI.DomEventHandler">
  82 + /// </field>
  83 + /// <field name="_onSubmitHandler" type="Sys.UI.DomEventHandler">
  84 + /// </field>
  85 + /// <field name="_errors" type="Array">
  86 + /// </field>
  87 + /// <field name="_submitButtonClicked" type="Object" domElement="true">
  88 + /// </field>
  89 + /// <field name="_validationSummaryElement" type="Object" domElement="true">
  90 + /// </field>
  91 + /// <field name="_validationSummaryULElement" type="Object" domElement="true">
  92 + /// </field>
  93 + /// <field name="fields" type="Array" elementType="FieldContext">
  94 + /// </field>
  95 + /// <field name="_formElement" type="Object" domElement="true">
  96 + /// </field>
  97 + /// <field name="replaceValidationSummary" type="Boolean">
  98 + /// </field>
  99 + this._errors = [];
  100 + this.fields = new Array(0);
  101 + this._formElement = formElement;
  102 + this._validationSummaryElement = validationSummaryElement;
  103 + formElement[Sys.Mvc.FormContext._formValidationTag] = this;
  104 + if (validationSummaryElement) {
  105 + var ulElements = validationSummaryElement.getElementsByTagName('ul');
  106 + if (ulElements.length > 0) {
  107 + this._validationSummaryULElement = ulElements[0];
  108 + }
  109 + }
  110 + this._onClickHandler = Function.createDelegate(this, this._form_OnClick);
  111 + this._onSubmitHandler = Function.createDelegate(this, this._form_OnSubmit);
  112 +}
  113 +Sys.Mvc.FormContext._Application_Load = function Sys_Mvc_FormContext$_Application_Load() {
  114 + var allFormOptions = window.mvcClientValidationMetadata;
  115 + if (allFormOptions) {
  116 + while (allFormOptions.length > 0) {
  117 + var thisFormOptions = allFormOptions.pop();
  118 + Sys.Mvc.FormContext._parseJsonOptions(thisFormOptions);
  119 + }
  120 + }
  121 +}
  122 +Sys.Mvc.FormContext._getFormElementsWithName = function Sys_Mvc_FormContext$_getFormElementsWithName(formElement, name) {
  123 + /// <param name="formElement" type="Object" domElement="true">
  124 + /// </param>
  125 + /// <param name="name" type="String">
  126 + /// </param>
  127 + /// <returns type="Array" elementType="Object" elementDomElement="true"></returns>
  128 + var allElementsWithNameInForm = [];
  129 + var allElementsWithName = document.getElementsByName(name);
  130 + for (var i = 0; i < allElementsWithName.length; i++) {
  131 + var thisElement = allElementsWithName[i];
  132 + if (Sys.Mvc.FormContext._isElementInHierarchy(formElement, thisElement)) {
  133 + Array.add(allElementsWithNameInForm, thisElement);
  134 + }
  135 + }
  136 + return allElementsWithNameInForm;
  137 +}
  138 +Sys.Mvc.FormContext.getValidationForForm = function Sys_Mvc_FormContext$getValidationForForm(formElement) {
  139 + /// <param name="formElement" type="Object" domElement="true">
  140 + /// </param>
  141 + /// <returns type="Sys.Mvc.FormContext"></returns>
  142 + return formElement[Sys.Mvc.FormContext._formValidationTag];
  143 +}
  144 +Sys.Mvc.FormContext._isElementInHierarchy = function Sys_Mvc_FormContext$_isElementInHierarchy(parent, child) {
  145 + /// <param name="parent" type="Object" domElement="true">
  146 + /// </param>
  147 + /// <param name="child" type="Object" domElement="true">
  148 + /// </param>
  149 + /// <returns type="Boolean"></returns>
  150 + while (child) {
  151 + if (parent === child) {
  152 + return true;
  153 + }
  154 + child = child.parentNode;
  155 + }
  156 + return false;
  157 +}
  158 +Sys.Mvc.FormContext._parseJsonOptions = function Sys_Mvc_FormContext$_parseJsonOptions(options) {
  159 + /// <param name="options" type="Sys.Mvc.JsonValidationOptions">
  160 + /// </param>
  161 + /// <returns type="Sys.Mvc.FormContext"></returns>
  162 + var formElement = $get(options.FormId);
  163 + var validationSummaryElement = (!Sys.Mvc._validationUtil.stringIsNullOrEmpty(options.ValidationSummaryId)) ? $get(options.ValidationSummaryId) : null;
  164 + var formContext = new Sys.Mvc.FormContext(formElement, validationSummaryElement);
  165 + formContext.enableDynamicValidation();
  166 + formContext.replaceValidationSummary = options.ReplaceValidationSummary;
  167 + for (var i = 0; i < options.Fields.length; i++) {
  168 + var field = options.Fields[i];
  169 + var fieldElements = Sys.Mvc.FormContext._getFormElementsWithName(formElement, field.FieldName);
  170 + var validationMessageElement = (!Sys.Mvc._validationUtil.stringIsNullOrEmpty(field.ValidationMessageId)) ? $get(field.ValidationMessageId) : null;
  171 + var fieldContext = new Sys.Mvc.FieldContext(formContext);
  172 + Array.addRange(fieldContext.elements, fieldElements);
  173 + fieldContext.validationMessageElement = validationMessageElement;
  174 + fieldContext.replaceValidationMessageContents = field.ReplaceValidationMessageContents;
  175 + for (var j = 0; j < field.ValidationRules.length; j++) {
  176 + var rule = field.ValidationRules[j];
  177 + var validator = Sys.Mvc.ValidatorRegistry.getValidator(rule);
  178 + if (validator) {
  179 + var validation = Sys.Mvc.$create_Validation();
  180 + validation.fieldErrorMessage = rule.ErrorMessage;
  181 + validation.validator = validator;
  182 + Array.add(fieldContext.validations, validation);
  183 + }
  184 + }
  185 + fieldContext.enableDynamicValidation();
  186 + Array.add(formContext.fields, fieldContext);
  187 + }
  188 + var registeredValidatorCallbacks = formElement.validationCallbacks;
  189 + if (!registeredValidatorCallbacks) {
  190 + registeredValidatorCallbacks = [];
  191 + formElement.validationCallbacks = registeredValidatorCallbacks;
  192 + }
  193 + registeredValidatorCallbacks.push(Function.createDelegate(null, function() {
  194 + return Sys.Mvc._validationUtil.arrayIsNullOrEmpty(formContext.validate('submit'));
  195 + }));
  196 + return formContext;
  197 +}
  198 +Sys.Mvc.FormContext.prototype = {
  199 + _onClickHandler: null,
  200 + _onSubmitHandler: null,
  201 + _submitButtonClicked: null,
  202 + _validationSummaryElement: null,
  203 + _validationSummaryULElement: null,
  204 + _formElement: null,
  205 + replaceValidationSummary: false,
  206 +
  207 + addError: function Sys_Mvc_FormContext$addError(message) {
  208 + /// <param name="message" type="String">
  209 + /// </param>
  210 + this.addErrors([ message ]);
  211 + },
  212 +
  213 + addErrors: function Sys_Mvc_FormContext$addErrors(messages) {
  214 + /// <param name="messages" type="Array" elementType="String">
  215 + /// </param>
  216 + if (!Sys.Mvc._validationUtil.arrayIsNullOrEmpty(messages)) {
  217 + Array.addRange(this._errors, messages);
  218 + this._onErrorCountChanged();
  219 + }
  220 + },
  221 +
  222 + clearErrors: function Sys_Mvc_FormContext$clearErrors() {
  223 + Array.clear(this._errors);
  224 + this._onErrorCountChanged();
  225 + },
  226 +
  227 + _displayError: function Sys_Mvc_FormContext$_displayError() {
  228 + if (this._validationSummaryElement) {
  229 + if (this._validationSummaryULElement) {
  230 + Sys.Mvc._validationUtil.removeAllChildren(this._validationSummaryULElement);
  231 + for (var i = 0; i < this._errors.length; i++) {
  232 + var liElement = document.createElement('li');
  233 + Sys.Mvc._validationUtil.setInnerText(liElement, this._errors[i]);
  234 + this._validationSummaryULElement.appendChild(liElement);
  235 + }
  236 + }
  237 + Sys.UI.DomElement.removeCssClass(this._validationSummaryElement, Sys.Mvc.FormContext._validationSummaryValidCss);
  238 + Sys.UI.DomElement.addCssClass(this._validationSummaryElement, Sys.Mvc.FormContext._validationSummaryErrorCss);
  239 + }
  240 + },
  241 +
  242 + _displaySuccess: function Sys_Mvc_FormContext$_displaySuccess() {
  243 + var validationSummaryElement = this._validationSummaryElement;
  244 + if (validationSummaryElement) {
  245 + var validationSummaryULElement = this._validationSummaryULElement;
  246 + if (validationSummaryULElement) {
  247 + validationSummaryULElement.innerHTML = '';
  248 + }
  249 + Sys.UI.DomElement.removeCssClass(validationSummaryElement, Sys.Mvc.FormContext._validationSummaryErrorCss);
  250 + Sys.UI.DomElement.addCssClass(validationSummaryElement, Sys.Mvc.FormContext._validationSummaryValidCss);
  251 + }
  252 + },
  253 +
  254 + enableDynamicValidation: function Sys_Mvc_FormContext$enableDynamicValidation() {
  255 + Sys.UI.DomEvent.addHandler(this._formElement, 'click', this._onClickHandler);
  256 + Sys.UI.DomEvent.addHandler(this._formElement, 'submit', this._onSubmitHandler);
  257 + },
  258 +
  259 + _findSubmitButton: function Sys_Mvc_FormContext$_findSubmitButton(element) {
  260 + /// <param name="element" type="Object" domElement="true">
  261 + /// </param>
  262 + /// <returns type="Object" domElement="true"></returns>
  263 + if (element.disabled) {
  264 + return null;
  265 + }
  266 + var tagName = element.tagName.toUpperCase();
  267 + var inputElement = element;
  268 + if (tagName === 'INPUT') {
  269 + var type = inputElement.type;
  270 + if (type === 'submit' || type === 'image') {
  271 + return inputElement;
  272 + }
  273 + }
  274 + else if ((tagName === 'BUTTON') && (inputElement.type === 'submit')) {
  275 + return inputElement;
  276 + }
  277 + return null;
  278 + },
  279 +
  280 + _form_OnClick: function Sys_Mvc_FormContext$_form_OnClick(e) {
  281 + /// <param name="e" type="Sys.UI.DomEvent">
  282 + /// </param>
  283 + this._submitButtonClicked = this._findSubmitButton(e.target);
  284 + },
  285 +
  286 + _form_OnSubmit: function Sys_Mvc_FormContext$_form_OnSubmit(e) {
  287 + /// <param name="e" type="Sys.UI.DomEvent">
  288 + /// </param>
  289 + var form = e.target;
  290 + var submitButton = this._submitButtonClicked;
  291 + if (submitButton && submitButton.disableValidation) {
  292 + return;
  293 + }
  294 + var errorMessages = this.validate('submit');
  295 + if (!Sys.Mvc._validationUtil.arrayIsNullOrEmpty(errorMessages)) {
  296 + e.preventDefault();
  297 + }
  298 + },
  299 +
  300 + _onErrorCountChanged: function Sys_Mvc_FormContext$_onErrorCountChanged() {
  301 + if (!this._errors.length) {
  302 + this._displaySuccess();
  303 + }
  304 + else {
  305 + this._displayError();
  306 + }
  307 + },
  308 +
  309 + validate: function Sys_Mvc_FormContext$validate(eventName) {
  310 + /// <param name="eventName" type="String">
  311 + /// </param>
  312 + /// <returns type="Array" elementType="String"></returns>
  313 + var fields = this.fields;
  314 + var errors = [];
  315 + for (var i = 0; i < fields.length; i++) {
  316 + var field = fields[i];
  317 + var thisErrors = field.validate(eventName);
  318 + if (thisErrors) {
  319 + Array.addRange(errors, thisErrors);
  320 + }
  321 + }
  322 + if (this.replaceValidationSummary) {
  323 + this.clearErrors();
  324 + this.addErrors(errors);
  325 + }
  326 + return errors;
  327 + }
  328 +}
  329 +
  330 +
  331 +////////////////////////////////////////////////////////////////////////////////
  332 +// Sys.Mvc.FieldContext
  333 +
  334 +Sys.Mvc.FieldContext = function Sys_Mvc_FieldContext(formContext) {
  335 + /// <param name="formContext" type="Sys.Mvc.FormContext">
  336 + /// </param>
  337 + /// <field name="_hasTextChangedTag" type="String" static="true">
  338 + /// </field>
  339 + /// <field name="_hasValidationFiredTag" type="String" static="true">
  340 + /// </field>
  341 + /// <field name="_inputElementErrorCss" type="String" static="true">
  342 + /// </field>
  343 + /// <field name="_inputElementValidCss" type="String" static="true">
  344 + /// </field>
  345 + /// <field name="_validationMessageErrorCss" type="String" static="true">
  346 + /// </field>
  347 + /// <field name="_validationMessageValidCss" type="String" static="true">
  348 + /// </field>
  349 + /// <field name="_onBlurHandler" type="Sys.UI.DomEventHandler">
  350 + /// </field>
  351 + /// <field name="_onChangeHandler" type="Sys.UI.DomEventHandler">
  352 + /// </field>
  353 + /// <field name="_onInputHandler" type="Sys.UI.DomEventHandler">
  354 + /// </field>
  355 + /// <field name="_onPropertyChangeHandler" type="Sys.UI.DomEventHandler">
  356 + /// </field>
  357 + /// <field name="_errors" type="Array">
  358 + /// </field>
  359 + /// <field name="defaultErrorMessage" type="String">
  360 + /// </field>
  361 + /// <field name="elements" type="Array" elementType="Object" elementDomElement="true">
  362 + /// </field>
  363 + /// <field name="formContext" type="Sys.Mvc.FormContext">
  364 + /// </field>
  365 + /// <field name="replaceValidationMessageContents" type="Boolean">
  366 + /// </field>
  367 + /// <field name="validationMessageElement" type="Object" domElement="true">
  368 + /// </field>
  369 + /// <field name="validations" type="Array" elementType="Validation">
  370 + /// </field>
  371 + this._errors = [];
  372 + this.elements = new Array(0);
  373 + this.validations = new Array(0);
  374 + this.formContext = formContext;
  375 + this._onBlurHandler = Function.createDelegate(this, this._element_OnBlur);
  376 + this._onChangeHandler = Function.createDelegate(this, this._element_OnChange);
  377 + this._onInputHandler = Function.createDelegate(this, this._element_OnInput);
  378 + this._onPropertyChangeHandler = Function.createDelegate(this, this._element_OnPropertyChange);
  379 +}
  380 +Sys.Mvc.FieldContext.prototype = {
  381 + _onBlurHandler: null,
  382 + _onChangeHandler: null,
  383 + _onInputHandler: null,
  384 + _onPropertyChangeHandler: null,
  385 + defaultErrorMessage: null,
  386 + formContext: null,
  387 + replaceValidationMessageContents: false,
  388 + validationMessageElement: null,
  389 +
  390 + addError: function Sys_Mvc_FieldContext$addError(message) {
  391 + /// <param name="message" type="String">
  392 + /// </param>
  393 + this.addErrors([ message ]);
  394 + },
  395 +
  396 + addErrors: function Sys_Mvc_FieldContext$addErrors(messages) {
  397 + /// <param name="messages" type="Array" elementType="String">
  398 + /// </param>
  399 + if (!Sys.Mvc._validationUtil.arrayIsNullOrEmpty(messages)) {
  400 + Array.addRange(this._errors, messages);
  401 + this._onErrorCountChanged();
  402 + }
  403 + },
  404 +
  405 + clearErrors: function Sys_Mvc_FieldContext$clearErrors() {
  406 + Array.clear(this._errors);
  407 + this._onErrorCountChanged();
  408 + },
  409 +
  410 + _displayError: function Sys_Mvc_FieldContext$_displayError() {
  411 + var validationMessageElement = this.validationMessageElement;
  412 + if (validationMessageElement) {
  413 + if (this.replaceValidationMessageContents) {
  414 + Sys.Mvc._validationUtil.setInnerText(validationMessageElement, this._errors[0]);
  415 + }
  416 + Sys.UI.DomElement.removeCssClass(validationMessageElement, Sys.Mvc.FieldContext._validationMessageValidCss);
  417 + Sys.UI.DomElement.addCssClass(validationMessageElement, Sys.Mvc.FieldContext._validationMessageErrorCss);
  418 + }
  419 + var elements = this.elements;
  420 + for (var i = 0; i < elements.length; i++) {
  421 + var element = elements[i];
  422 + Sys.UI.DomElement.removeCssClass(element, Sys.Mvc.FieldContext._inputElementValidCss);
  423 + Sys.UI.DomElement.addCssClass(element, Sys.Mvc.FieldContext._inputElementErrorCss);
  424 + }
  425 + },
  426 +
  427 + _displaySuccess: function Sys_Mvc_FieldContext$_displaySuccess() {
  428 + var validationMessageElement = this.validationMessageElement;
  429 + if (validationMessageElement) {
  430 + if (this.replaceValidationMessageContents) {
  431 + Sys.Mvc._validationUtil.setInnerText(validationMessageElement, '');
  432 + }
  433 + Sys.UI.DomElement.removeCssClass(validationMessageElement, Sys.Mvc.FieldContext._validationMessageErrorCss);
  434 + Sys.UI.DomElement.addCssClass(validationMessageElement, Sys.Mvc.FieldContext._validationMessageValidCss);
  435 + }
  436 + var elements = this.elements;
  437 + for (var i = 0; i < elements.length; i++) {
  438 + var element = elements[i];
  439 + Sys.UI.DomElement.removeCssClass(element, Sys.Mvc.FieldContext._inputElementErrorCss);
  440 + Sys.UI.DomElement.addCssClass(element, Sys.Mvc.FieldContext._inputElementValidCss);
  441 + }
  442 + },
  443 +
  444 + _element_OnBlur: function Sys_Mvc_FieldContext$_element_OnBlur(e) {
  445 + /// <param name="e" type="Sys.UI.DomEvent">
  446 + /// </param>
  447 + if (e.target[Sys.Mvc.FieldContext._hasTextChangedTag] || e.target[Sys.Mvc.FieldContext._hasValidationFiredTag]) {
  448 + this.validate('blur');
  449 + }
  450 + },
  451 +
  452 + _element_OnChange: function Sys_Mvc_FieldContext$_element_OnChange(e) {
  453 + /// <param name="e" type="Sys.UI.DomEvent">
  454 + /// </param>
  455 + e.target[Sys.Mvc.FieldContext._hasTextChangedTag] = true;
  456 + },
  457 +
  458 + _element_OnInput: function Sys_Mvc_FieldContext$_element_OnInput(e) {
  459 + /// <param name="e" type="Sys.UI.DomEvent">
  460 + /// </param>
  461 + e.target[Sys.Mvc.FieldContext._hasTextChangedTag] = true;
  462 + if (e.target[Sys.Mvc.FieldContext._hasValidationFiredTag]) {
  463 + this.validate('input');
  464 + }
  465 + },
  466 +
  467 + _element_OnPropertyChange: function Sys_Mvc_FieldContext$_element_OnPropertyChange(e) {
  468 + /// <param name="e" type="Sys.UI.DomEvent">
  469 + /// </param>
  470 + if (e.rawEvent.propertyName === 'value') {
  471 + e.target[Sys.Mvc.FieldContext._hasTextChangedTag] = true;
  472 + if (e.target[Sys.Mvc.FieldContext._hasValidationFiredTag]) {
  473 + this.validate('input');
  474 + }
  475 + }
  476 + },
  477 +
  478 + enableDynamicValidation: function Sys_Mvc_FieldContext$enableDynamicValidation() {
  479 + var elements = this.elements;
  480 + for (var i = 0; i < elements.length; i++) {
  481 + var element = elements[i];
  482 + if (Sys.Mvc._validationUtil.elementSupportsEvent(element, 'onpropertychange')) {
  483 + var compatMode = document.documentMode;
  484 + if (compatMode && compatMode >= 8) {
  485 + Sys.UI.DomEvent.addHandler(element, 'propertychange', this._onPropertyChangeHandler);
  486 + }
  487 + }
  488 + else {
  489 + Sys.UI.DomEvent.addHandler(element, 'input', this._onInputHandler);
  490 + }
  491 + Sys.UI.DomEvent.addHandler(element, 'change', this._onChangeHandler);
  492 + Sys.UI.DomEvent.addHandler(element, 'blur', this._onBlurHandler);
  493 + }
  494 + },
  495 +
  496 + _getErrorString: function Sys_Mvc_FieldContext$_getErrorString(validatorReturnValue, fieldErrorMessage) {
  497 + /// <param name="validatorReturnValue" type="Object">
  498 + /// </param>
  499 + /// <param name="fieldErrorMessage" type="String">
  500 + /// </param>
  501 + /// <returns type="String"></returns>
  502 + var fallbackErrorMessage = fieldErrorMessage || this.defaultErrorMessage;
  503 + if (Boolean.isInstanceOfType(validatorReturnValue)) {
  504 + return (validatorReturnValue) ? null : fallbackErrorMessage;
  505 + }
  506 + if (String.isInstanceOfType(validatorReturnValue)) {
  507 + return ((validatorReturnValue).length) ? validatorReturnValue : fallbackErrorMessage;
  508 + }
  509 + return null;
  510 + },
  511 +
  512 + _getStringValue: function Sys_Mvc_FieldContext$_getStringValue() {
  513 + /// <returns type="String"></returns>
  514 + var elements = this.elements;
  515 + return (elements.length > 0) ? elements[0].value : null;
  516 + },
  517 +
  518 + _markValidationFired: function Sys_Mvc_FieldContext$_markValidationFired() {
  519 + var elements = this.elements;
  520 + for (var i = 0; i < elements.length; i++) {
  521 + var element = elements[i];
  522 + element[Sys.Mvc.FieldContext._hasValidationFiredTag] = true;
  523 + }
  524 + },
  525 +
  526 + _onErrorCountChanged: function Sys_Mvc_FieldContext$_onErrorCountChanged() {
  527 + if (!this._errors.length) {
  528 + this._displaySuccess();
  529 + }
  530 + else {
  531 + this._displayError();
  532 + }
  533 + },
  534 +
  535 + validate: function Sys_Mvc_FieldContext$validate(eventName) {
  536 + /// <param name="eventName" type="String">
  537 + /// </param>
  538 + /// <returns type="Array" elementType="String"></returns>
  539 + var validations = this.validations;
  540 + var errors = [];
  541 + var value = this._getStringValue();
  542 + for (var i = 0; i < validations.length; i++) {
  543 + var validation = validations[i];
  544 + var context = Sys.Mvc.$create_ValidationContext();
  545 + context.eventName = eventName;
  546 + context.fieldContext = this;
  547 + context.validation = validation;
  548 + var retVal = validation.validator(value, context);
  549 + var errorMessage = this._getErrorString(retVal, validation.fieldErrorMessage);
  550 + if (!Sys.Mvc._validationUtil.stringIsNullOrEmpty(errorMessage)) {
  551 + Array.add(errors, errorMessage);
  552 + }
  553 + }
  554 + this._markValidationFired();
  555 + this.clearErrors();
  556 + this.addErrors(errors);
  557 + return errors;
  558 + }
  559 +}
  560 +
  561 +
  562 +////////////////////////////////////////////////////////////////////////////////
  563 +// Sys.Mvc.RangeValidator
  564 +
  565 +Sys.Mvc.RangeValidator = function Sys_Mvc_RangeValidator(minimum, maximum) {
  566 + /// <param name="minimum" type="Number">
  567 + /// </param>
  568 + /// <param name="maximum" type="Number">
  569 + /// </param>
  570 + /// <field name="_minimum" type="Number">
  571 + /// </field>
  572 + /// <field name="_maximum" type="Number">
  573 + /// </field>
  574 + this._minimum = minimum;
  575 + this._maximum = maximum;
  576 +}
  577 +Sys.Mvc.RangeValidator.create = function Sys_Mvc_RangeValidator$create(rule) {
  578 + /// <param name="rule" type="Sys.Mvc.JsonValidationRule">
  579 + /// </param>
  580 + /// <returns type="Sys.Mvc.Validator"></returns>
  581 + var min = rule.ValidationParameters['minimum'];
  582 + var max = rule.ValidationParameters['maximum'];
  583 + return Function.createDelegate(new Sys.Mvc.RangeValidator(min, max), new Sys.Mvc.RangeValidator(min, max).validate);
  584 +}
  585 +Sys.Mvc.RangeValidator.prototype = {
  586 + _minimum: null,
  587 + _maximum: null,
  588 +
  589 + validate: function Sys_Mvc_RangeValidator$validate(value, context) {
  590 + /// <param name="value" type="String">
  591 + /// </param>
  592 + /// <param name="context" type="Sys.Mvc.ValidationContext">
  593 + /// </param>
  594 + /// <returns type="Object"></returns>
  595 + if (Sys.Mvc._validationUtil.stringIsNullOrEmpty(value)) {
  596 + return true;
  597 + }
  598 + var n = Number.parseLocale(value);
  599 + return (!isNaN(n) && this._minimum <= n && n <= this._maximum);
  600 + }
  601 +}
  602 +
  603 +
  604 +////////////////////////////////////////////////////////////////////////////////
  605 +// Sys.Mvc.RegularExpressionValidator
  606 +
  607 +Sys.Mvc.RegularExpressionValidator = function Sys_Mvc_RegularExpressionValidator(pattern) {
  608 + /// <param name="pattern" type="String">
  609 + /// </param>
  610 + /// <field name="_pattern" type="String">
  611 + /// </field>
  612 + this._pattern = pattern;
  613 +}
  614 +Sys.Mvc.RegularExpressionValidator.create = function Sys_Mvc_RegularExpressionValidator$create(rule) {
  615 + /// <param name="rule" type="Sys.Mvc.JsonValidationRule">
  616 + /// </param>
  617 + /// <returns type="Sys.Mvc.Validator"></returns>
  618 + var pattern = rule.ValidationParameters['pattern'];
  619 + return Function.createDelegate(new Sys.Mvc.RegularExpressionValidator(pattern), new Sys.Mvc.RegularExpressionValidator(pattern).validate);
  620 +}
  621 +Sys.Mvc.RegularExpressionValidator.prototype = {
  622 + _pattern: null,
  623 +
  624 + validate: function Sys_Mvc_RegularExpressionValidator$validate(value, context) {
  625 + /// <param name="value" type="String">
  626 + /// </param>
  627 + /// <param name="context" type="Sys.Mvc.ValidationContext">
  628 + /// </param>
  629 + /// <returns type="Object"></returns>
  630 + if (Sys.Mvc._validationUtil.stringIsNullOrEmpty(value)) {
  631 + return true;
  632 + }
  633 + var regExp = new RegExp(this._pattern);
  634 + var matches = regExp.exec(value);
  635 + return (!Sys.Mvc._validationUtil.arrayIsNullOrEmpty(matches) && matches[0].length === value.length);
  636 + }
  637 +}
  638 +
  639 +
  640 +////////////////////////////////////////////////////////////////////////////////
  641 +// Sys.Mvc.RequiredValidator
  642 +
  643 +Sys.Mvc.RequiredValidator = function Sys_Mvc_RequiredValidator() {
  644 +}
  645 +Sys.Mvc.RequiredValidator.create = function Sys_Mvc_RequiredValidator$create(rule) {
  646 + /// <param name="rule" type="Sys.Mvc.JsonValidationRule">
  647 + /// </param>
  648 + /// <returns type="Sys.Mvc.Validator"></returns>
  649 + return Function.createDelegate(new Sys.Mvc.RequiredValidator(), new Sys.Mvc.RequiredValidator().validate);
  650 +}
  651 +Sys.Mvc.RequiredValidator._isRadioInputElement = function Sys_Mvc_RequiredValidator$_isRadioInputElement(element) {
  652 + /// <param name="element" type="Object" domElement="true">
  653 + /// </param>
  654 + /// <returns type="Boolean"></returns>
  655 + if (element.tagName.toUpperCase() === 'INPUT') {
  656 + var inputType = (element.type).toUpperCase();
  657 + if (inputType === 'RADIO') {
  658 + return true;
  659 + }
  660 + }
  661 + return false;
  662 +}
  663 +Sys.Mvc.RequiredValidator._isSelectInputElement = function Sys_Mvc_RequiredValidator$_isSelectInputElement(element) {
  664 + /// <param name="element" type="Object" domElement="true">
  665 + /// </param>
  666 + /// <returns type="Boolean"></returns>
  667 + if (element.tagName.toUpperCase() === 'SELECT') {
  668 + return true;
  669 + }
  670 + return false;
  671 +}
  672 +Sys.Mvc.RequiredValidator._isTextualInputElement = function Sys_Mvc_RequiredValidator$_isTextualInputElement(element) {
  673 + /// <param name="element" type="Object" domElement="true">
  674 + /// </param>
  675 + /// <returns type="Boolean"></returns>
  676 + if (element.tagName.toUpperCase() === 'INPUT') {
  677 + var inputType = (element.type).toUpperCase();
  678 + switch (inputType) {
  679 + case 'TEXT':
  680 + case 'PASSWORD':
  681 + case 'FILE':
  682 + return true;
  683 + }
  684 + }
  685 + if (element.tagName.toUpperCase() === 'TEXTAREA') {
  686 + return true;
  687 + }
  688 + return false;
  689 +}
  690 +Sys.Mvc.RequiredValidator._validateRadioInput = function Sys_Mvc_RequiredValidator$_validateRadioInput(elements) {
  691 + /// <param name="elements" type="Array" elementType="Object" elementDomElement="true">
  692 + /// </param>
  693 + /// <returns type="Object"></returns>
  694 + for (var i = 0; i < elements.length; i++) {
  695 + var element = elements[i];
  696 + if (element.checked) {
  697 + return true;
  698 + }
  699 + }
  700 + return false;
  701 +}
  702 +Sys.Mvc.RequiredValidator._validateSelectInput = function Sys_Mvc_RequiredValidator$_validateSelectInput(optionElements) {
  703 + /// <param name="optionElements" type="DOMElementCollection">
  704 + /// </param>
  705 + /// <returns type="Object"></returns>
  706 + for (var i = 0; i < optionElements.length; i++) {
  707 + var element = optionElements[i];
  708 + if (element.selected) {
  709 + if (!Sys.Mvc._validationUtil.stringIsNullOrEmpty(element.value)) {
  710 + return true;
  711 + }
  712 + }
  713 + }
  714 + return false;
  715 +}
  716 +Sys.Mvc.RequiredValidator._validateTextualInput = function Sys_Mvc_RequiredValidator$_validateTextualInput(element) {
  717 + /// <param name="element" type="Object" domElement="true">
  718 + /// </param>
  719 + /// <returns type="Object"></returns>
  720 + return (!Sys.Mvc._validationUtil.stringIsNullOrEmpty(element.value));
  721 +}
  722 +Sys.Mvc.RequiredValidator.prototype = {
  723 +
  724 + validate: function Sys_Mvc_RequiredValidator$validate(value, context) {
  725 + /// <param name="value" type="String">
  726 + /// </param>
  727 + /// <param name="context" type="Sys.Mvc.ValidationContext">
  728 + /// </param>
  729 + /// <returns type="Object"></returns>
  730 + var elements = context.fieldContext.elements;
  731 + if (!elements.length) {
  732 + return true;
  733 + }
  734 + var sampleElement = elements[0];
  735 + if (Sys.Mvc.RequiredValidator._isTextualInputElement(sampleElement)) {
  736 + return Sys.Mvc.RequiredValidator._validateTextualInput(sampleElement);
  737 + }
  738 + if (Sys.Mvc.RequiredValidator._isRadioInputElement(sampleElement)) {
  739 + return Sys.Mvc.RequiredValidator._validateRadioInput(elements);
  740 + }
  741 + if (Sys.Mvc.RequiredValidator._isSelectInputElement(sampleElement)) {
  742 + return Sys.Mvc.RequiredValidator._validateSelectInput((sampleElement).options);
  743 + }
  744 + return true;
  745 + }
  746 +}
  747 +
  748 +
  749 +////////////////////////////////////////////////////////////////////////////////
  750 +// Sys.Mvc.StringLengthValidator
  751 +
  752 +Sys.Mvc.StringLengthValidator = function Sys_Mvc_StringLengthValidator(minLength, maxLength) {
  753 + /// <param name="minLength" type="Number" integer="true">
  754 + /// </param>
  755 + /// <param name="maxLength" type="Number" integer="true">
  756 + /// </param>
  757 + /// <field name="_maxLength" type="Number" integer="true">
  758 + /// </field>