<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:georss="http://www.georss.org/georss" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Nesterovsky bros - javascript</title>
    <link>http://www.nesterovsky-bros.com/weblog/</link>
    <description />
    <language>en-us</language>
    <copyright>Nesterovsky bros</copyright>
    <lastBuildDate>Tue, 28 May 2013 05:54:52 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.12105.0</generator>
    <managingEditor>contact@nesterovsky-bros.com</managingEditor>
    <webMaster>contact@nesterovsky-bros.com</webMaster>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=c96c3810-95d1-46bd-b413-7fac0cdbf509</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c96c3810-95d1-46bd-b413-7fac0cdbf509.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,c96c3810-95d1-46bd-b413-7fac0cdbf509.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=c96c3810-95d1-46bd-b413-7fac0cdbf509</wfw:commentRss>
      <title>Kendo progress utility</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c96c3810-95d1-46bd-b413-7fac0cdbf509.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/05/28/KendoProgressUtility.aspx</link>
      <pubDate>Tue, 28 May 2013 05:54:52 GMT</pubDate>
      <description>  &lt;p&gt;
While developing with KendoUI we have found &lt;code&gt;kendo.ui.progress(container, toggle)&lt;/code&gt; function
to be very useful. It's used to show or hide a progress indicator in the container
element.
&lt;/p&gt;
&lt;p&gt;
At the same time we have found that we usually used it in a context of async operation.
This way, we want to show progress, perform some asynchronous operations, hide progress.
So, we clearly want to benifit from &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c96c3810-95d1-46bd-b413-7fac0cdbf509&amp;amp;url=http%3a%2f%2fen.wikipedia.org%2fwiki%2fResource_Acquisition_Is_Initialization"&gt; RAII&lt;/a&gt; pattern:
we would like to open a progress scope, and to perform some activity withing this
scope.
&lt;/p&gt;
&lt;p&gt;
Arguing like this, we have defined a utility function, which is the fusion of &lt;code&gt;kendo.ui.progress()&lt;/code&gt; and &lt;code&gt;$.when()&lt;/code&gt;.
Its signature is like this:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;nesterovskyBros.progress = function(instance /*, task ... */)&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
where &lt;code&gt;instance&lt;/code&gt; is either &lt;code&gt;Model&lt;/code&gt;, &lt;code&gt;Widget&lt;/code&gt;, &lt;code&gt;JQuery&lt;/code&gt; or
DOM &lt;code&gt;Element&lt;/code&gt;, and &lt;code&gt;task&lt;/code&gt; is one or more deferred objects. This
function shows a progress and returns a &lt;code&gt;Promise&lt;/code&gt; that will hide a progress
when all tasks will be complete. Implementation is trivial, so we quote it here:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;// Fusion of kendo.ui.progress() and $.when().&lt;br /&gt;
scope.progress = function(instance /*, task ... */)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; if (instance instanceof Model)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; instance = instance.owner &amp;&amp; instance.owner();&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; if (instance instanceof Widget)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; instance = instance.element;&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; if (instance &amp;&amp; instance.nodeType)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; instance = $(instance);&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; var id = ns + "-progress"; // "nesterovskyBros-progress";&lt;br /&gt;
&amp;nbsp; var progress = (instance &amp;&amp; instance.data(id)) || 0;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; if (arguments.length &amp;lt; 2)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return progress;&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; var result = $.when.apply(null, [].slice.call(arguments, 1));&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; if (instance)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; instance.data(id, ++progress);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; kendo.ui.progress(instance, progress &amp;gt; 0);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; result.always(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; progress = instance.data(id) || 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; instance.data(id, --progress);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kendo.ui.progress(instance, progress &amp;gt;
0);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; return result;&lt;br /&gt;
}; &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
The use is like this:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;nesterovskyBros.progress(element, $.ajax("/service1"), $.ajax("/service2")).then(myFunc);&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
The code can be found at &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=c96c3810-95d1-46bd-b413-7fac0cdbf509&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols.js"&gt; controls.js&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c96c3810-95d1-46bd-b413-7fac0cdbf509" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,c96c3810-95d1-46bd-b413-7fac0cdbf509.aspx</comments>
      <category>javascript</category>
      <category>kendoui</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=04f31825-657d-470b-9223-bb1e8961fc9d</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,04f31825-657d-470b-9223-bb1e8961fc9d.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,04f31825-657d-470b-9223-bb1e8961fc9d.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=04f31825-657d-470b-9223-bb1e8961fc9d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While trying to generalize our practices from KendoUI related projects we've participated
so far, we updated <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fapi%2fcontrols.js"> control.js</a> -
a small javascript additions to KendoUI.
</p>
        <p>
At present we have defined:
</p>
        <p>
1. An extended model. See <a href="2013/04/03/KendoUIExtendedModel.aspx" rel="bookmark">KendoUI
extended model</a>. 
</p>
        <p>
2. A lightweight user control - a widget to bind a template and a model, and to facilitate
declarative instantiation. See <a href="2013/03/26/KendoUIUserControl.aspx" rel="bookmark">KendoUI
User control</a>. 
</p>
        <p>
3. A reworked version of nesterovskyBros.defineControl() function. 
</p>
        <p style="padding-left: 1em">
          <code>var widgetType = scope.defineControl(<br />
{<br />
   name: widget-name-string,<br />
   model: widget-model-type,<br />
   template: optional-content-template,<br />
   windowOptions: optional-window-options<br />
},<br />
base);</code>
        </p>
        <p>
When <code>optional-content-template</code> is not specified then template is calculated
as following:
</p>
        <p style="padding-left: 1em">
          <code> var template = options.temlate || proto.template || model.temlate;<br /><br />
if (template === undefined) 
<br />
{<br />
  template = scope.template(options.name.toLowerCase() + "-template"); 
<br />
} </code>
        </p>
        <p>
When <code>windowOptions</code> is specified then <code>widgetType.dialog(options)</code> function
is defined. It's used to open dialog based on the specified user control. <code>windowOptions</code> is
passed to <code>kendo.ui.Window</code> constructor. <code>windowOptions.closeOnEscape</code> indicates
whether to close opened dialog on escape.
</p>
        <p>
          <code>widgetType.dialog()</code> returns a <code>kendo.ui.Window</code> instance with
content based on the user control. Window instance contains functions: 
</p>
        <ul>
          <li>
            <code>result()</code> - a <code>$.Deffered</code> for the dialog result, and 
</li>
          <li>
            <code>model()</code> - referring to the user control model. 
</li>
        </ul>
        <p>
 The model instance has functions:
</p>
        <ul>
          <li>
 <code>dialog()</code> referring to the dialog, and 
</li>
          <li>
            <code>result()</code> referring to the dialog result.</li>
        </ul>
        <p>
          <code>widget.dialog()</code> allows all css units in <code>windowOptions.width</code> and <code>windowOptions.height</code> parameters.
</p>
        <p>
          <code>base</code> - is optional user control base. It defaults to <code>nesterovskyBros.ui.UserControl</code>.
</p>
        <p>
4. Adjusted splitter. See <a href="2013/05/14/AdjustKendoUISplitter.aspx" rel="bookmark">Adjust
KendoUI Splitter</a>.
</p>
        <p>
5. Auto resize support.
</p>
        <p>
Layout is often depends on available area. One example is <code>Splitter</code> widget
that recalculates its panes when window or container <code>Splitter</code> is resized.
There are other cases when you would like to adjust layout when a container's
area is changed like: adjust grid, tab, editor or user's control contents.
</p>
        <p>
KendoUI does not provide a solution for this problem, so we have defined our own.
</p>
        <ul>
          <li>
A widget can be marked with <code>class="auto-resize"</code> marker;</li>
          <li>
A widget may define a <code>widgetType.autoResize(element)</code> function that adapts
widget to a new size.</li>
          <li>
A code can call <code>nesterovskyBros.resize(element)</code> function at trigger resizing
of the subtree.</li>
        </ul>
        <p>
To support existing controls we have defined <code>autoResize()</code> function for <code>Grid</code>, <code>Splitter</code>, <code>TabStrip</code>,
and <code>Editor</code> widgets.
</p>
        <p>
To see how auto resizing works, it's best to look into <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2findex.html">index.html</a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates%2fproducts.tmpl.html"> products.tmpl.html</a>,
and into the implementation <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fapi%2fcontrols.js"> controls.js</a>.
</p>
        <p>
Please note that we consider <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fapi%2fcontrols.js"> controls.js</a> as
an addition to KendoUI library. If in the future the library will integrate or implement
similar features we will be happy to start using their API.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d" />
      </body>
      <title>KendoUI controls.js</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,04f31825-657d-470b-9223-bb1e8961fc9d.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/05/18/KendoUIControlsjs.aspx</link>
      <pubDate>Sat, 18 May 2013 10:59:36 GMT</pubDate>
      <description>  &lt;p&gt;
While trying to generalize our practices from KendoUI related projects we've participated
so far, we updated &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fapi%2fcontrols.js"&gt; control.js&lt;/a&gt; -
a small javascript additions to KendoUI.
&lt;/p&gt;
&lt;p&gt;
At present we have defined:
&lt;/p&gt;
&lt;p&gt;
1. An extended model. See &lt;a href="2013/04/03/KendoUIExtendedModel.aspx" rel="bookmark"&gt;KendoUI
extended model&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
2. A lightweight user control - a widget to bind a template and a model, and to facilitate
declarative instantiation. See &lt;a href="2013/03/26/KendoUIUserControl.aspx" rel="bookmark"&gt;KendoUI
User control&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
3. A reworked version of nesterovskyBros.defineControl() function. 
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;var widgetType = scope.defineControl(&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; name: widget-name-string,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; model: widget-model-type,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; template: optional-content-template,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; windowOptions: optional-window-options&lt;br /&gt;
},&lt;br /&gt;
base);&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
When &lt;code&gt;optional-content-template&lt;/code&gt; is not specified then template is calculated
as following:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; var template = options.temlate || proto.template || model.temlate;&lt;br /&gt;
&lt;br /&gt;
if (template === undefined) 
&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; template = scope.template(options.name.toLowerCase() + "-template"); 
&lt;br /&gt;
} &lt;/code&gt; 
&lt;/p&gt;
&lt;p&gt;
When &lt;code&gt;windowOptions&lt;/code&gt; is specified then &lt;code&gt;widgetType.dialog(options)&lt;/code&gt; function
is defined. It&amp;#39;s used to open dialog based on the specified user control. &lt;code&gt;windowOptions&lt;/code&gt; is
passed to &lt;code&gt;kendo.ui.Window&lt;/code&gt; constructor. &lt;code&gt;windowOptions.closeOnEscape&lt;/code&gt; indicates
whether to close opened dialog on escape.
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;widgetType.dialog()&lt;/code&gt; returns a &lt;code&gt;kendo.ui.Window&lt;/code&gt; instance with
content based on the user control. Window instance contains functions: 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;result()&lt;/code&gt; - a &lt;code&gt;$.Deffered&lt;/code&gt; for the dialog result, and 
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;model()&lt;/code&gt; - referring to the user control model. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&amp;nbsp;The model instance has functions:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&amp;nbsp;&lt;code&gt;dialog()&lt;/code&gt; referring to the dialog, and 
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;result()&lt;/code&gt; referring to the dialog result.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;code&gt;widget.dialog()&lt;/code&gt; allows all css units in &lt;code&gt;windowOptions.width&lt;/code&gt; and &lt;code&gt;windowOptions.height&lt;/code&gt; parameters.
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;base&lt;/code&gt; - is optional user control base. It defaults to &lt;code&gt;nesterovskyBros.ui.UserControl&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
4. Adjusted splitter. See &lt;a href="2013/05/14/AdjustKendoUISplitter.aspx" rel="bookmark"&gt;Adjust
KendoUI Splitter&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
5. Auto resize support.
&lt;/p&gt;
&lt;p&gt;
Layout is often depends on available area. One example is &lt;code&gt;Splitter&lt;/code&gt; widget
that recalculates its panes when window or container &lt;code&gt;Splitter&lt;/code&gt; is resized.
There are other cases when you would like to adjust layout when a container&amp;#39;s
area is changed like: adjust grid, tab, editor or user&amp;#39;s control contents.
&lt;/p&gt;
&lt;p&gt;
KendoUI does not provide a solution for this problem, so we have defined our own.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
A widget can be marked with &lt;code&gt;class=&amp;quot;auto-resize&amp;quot;&lt;/code&gt; marker;&lt;/li&gt;
&lt;li&gt;
A widget may define a &lt;code&gt;widgetType.autoResize(element)&lt;/code&gt; function that adapts
widget to a new size.&lt;/li&gt;
&lt;li&gt;
A code can call &lt;code&gt;nesterovskyBros.resize(element)&lt;/code&gt; function at trigger resizing
of the subtree.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
To support existing controls we have defined &lt;code&gt;autoResize()&lt;/code&gt; function for &lt;code&gt;Grid&lt;/code&gt;, &lt;code&gt;Splitter&lt;/code&gt;, &lt;code&gt;TabStrip&lt;/code&gt;,
and &lt;code&gt;Editor&lt;/code&gt; widgets.
&lt;/p&gt;
&lt;p&gt;
To see how auto resizing works, it&amp;#39;s best to look into &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2findex.html"&gt;index.html&lt;/a&gt;, &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates%2fproducts.tmpl.html"&gt; products.tmpl.html&lt;/a&gt;,
and into the implementation &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fapi%2fcontrols.js"&gt; controls.js&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Please note that we consider &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fapi%2fcontrols.js"&gt; controls.js&lt;/a&gt; as
an addition to KendoUI library. If in the future the library will integrate or implement
similar features we will be happy to start using their API.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=04f31825-657d-470b-9223-bb1e8961fc9d" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,04f31825-657d-470b-9223-bb1e8961fc9d.aspx</comments>
      <category>Announce</category>
      <category>javascript</category>
      <category>kendoui</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=9b30445a-be57-4140-a839-fab46b42c76e</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9b30445a-be57-4140-a839-fab46b42c76e.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9b30445a-be57-4140-a839-fab46b42c76e.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=9b30445a-be57-4140-a839-fab46b42c76e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We heavily use kendo.ui.Splitter widget. Unfortunately it has several drawbacks:
</p>
        <ul>
          <li>
you cannot easily configure panes declaratively;</li>
          <li>
you cannot define a pane that takes space according to its content.</li>
        </ul>
        <p>
Although we don't like to patch widgets, in this case we found no better way but
to patch two functions: <code>kendo.ui.Splitter.fn._initPanes</code>, and  <code>kendo.ui.Splitter.fn._resize</code>.
</p>
        <p>
After the fix, splitter markup may look like the following:
</p>
        <p style="padding-left: 1em">
          <code> &lt;div style="height: 100%" data-role="splitter" data-orientation="vertical"&gt;<br />
  &lt;div <strong>data-pane</strong>='{ size: "<strong>auto</strong>",
resizable: false, scrollable: false }'&gt;<br />
    Header with size depending on content.<br />
  &lt;/div&gt;<br />
  &lt;div data-pane='{ resizable: false, scrollable: true }'&gt;<br />
    Body with size equal to a remaining area.<br />
  &lt;/div&gt;<br />
  &lt;div data-pane='{ size: "auto", resizable: false, scrollable: false }'&gt;<br />
    Footer with size depending on content.<br />
  &lt;/div&gt;<br />
&lt;/div&gt;</code>
        </p>
        <p>
Each pane may define a <code>data-pane</code> attribute with pane parameters. A pane
may specify <code>size = "auto"</code> to take space according to its content.
</p>
        <p>
The code can be found at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9b30445a-be57-4140-a839-fab46b42c76e&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fapi%2fsplitter.js"> splitter.js</a> A
test can be seen at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9b30445a-be57-4140-a839-fab46b42c76e&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fsplitter.html"> splitter.html</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9b30445a-be57-4140-a839-fab46b42c76e" />
      </body>
      <title>Adjust KendoUI Splitter</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9b30445a-be57-4140-a839-fab46b42c76e.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/05/14/AdjustKendoUISplitter.aspx</link>
      <pubDate>Tue, 14 May 2013 07:34:59 GMT</pubDate>
      <description>&lt;p&gt;
We heavily use kendo.ui.Splitter widget. Unfortunately it has several drawbacks:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
you cannot easily configure panes declaratively;&lt;/li&gt;
&lt;li&gt;
you cannot define a pane that takes space according to its content.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Although we don&amp;#39;t like to patch widgets, in this case we found no better way but
to patch two functions: &lt;code&gt;kendo.ui.Splitter.fn._initPanes&lt;/code&gt;, and&amp;nbsp; &lt;code&gt;kendo.ui.Splitter.fn._resize&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
After the fix, splitter markup may look like the following:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; &amp;lt;div style=&amp;quot;height: 100%&amp;quot; data-role="splitter" data-orientation="vertical"&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;div &lt;strong&gt;data-pane&lt;/strong&gt;=&amp;#39;{ size: &amp;quot;&lt;strong&gt;auto&lt;/strong&gt;&amp;quot;,
resizable: false, scrollable: false }&amp;#39;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Header with size depending on content.&lt;br /&gt;
&amp;nbsp; &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;div data-pane='{ resizable: false, scrollable: true }'&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Body with size equal to a remaining area.&lt;br /&gt;
&amp;nbsp; &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;div data-pane='{ size: "auto", resizable: false, scrollable: false }'&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Footer with size depending on content.&lt;br /&gt;
&amp;nbsp; &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/code&gt; 
&lt;/p&gt;
&lt;p&gt;
Each pane may define a &lt;code&gt;data-pane&lt;/code&gt; attribute with pane parameters. A pane
may specify &lt;code&gt;size = &amp;quot;auto&amp;quot;&lt;/code&gt; to take space according to its content.
&lt;/p&gt;
&lt;p&gt;
The code can be found at &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9b30445a-be57-4140-a839-fab46b42c76e&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fapi%2fsplitter.js"&gt; splitter.js&lt;/a&gt; A
test can be seen at &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9b30445a-be57-4140-a839-fab46b42c76e&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fsplitter.html"&gt; splitter.html&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9b30445a-be57-4140-a839-fab46b42c76e" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9b30445a-be57-4140-a839-fab46b42c76e.aspx</comments>
      <category>javascript</category>
      <category>kendoui</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p style="direction: ltr">
Although WCF REST service + JSON is outdated comparing to Web API, there are yet a
lot of such solutions (and probably will appear new ones) that use such "old"
technology. 
</p>
        <p>
One of the crucial points of any web application is an error handler that allows gracefully
resolve server-side exceptions and routes them as JSON objects to the client for further
processing. There are dozen approachesin Internet that solve this issue  (e.g. <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;url=http%3a%2f%2fblog.manglar.com%2fhow-to-provide-custom-json-exceptions-from-as-wcf-service%2f">http://blog.manglar.com/how-to-provide-custom-json-exceptions-from-as-wcf-service/</a>),
but there is no one that demonstrates error handling ot the client-side. We realize
that it's impossible to write something general that suits for every web application,
but we'd like to show a client-side error handler that utilizes JSON and KendoUI.
</p>
        <p style="direction: ltr">
On our opinion, the successfull error handler must display an understandable error
message on one hand, and on the other hand it has to provide technical info for developers
in order to investigate the exception reason (and to fix it, if need):
</p>
        <table border="0">
          <tr>
            <td style="vertical-align: top;">
              <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fimages%2fcolapsed-error-dialog.png">
                <img src="http://www.nesterovsky-bros.com/images/thumb-colapsed-error-dialog.png" alt="collapsed error dialog" />
              </a>
            </td>
            <td>
              <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fimages%2fexpanded-error-dialog.png">
                <img src="http://www.nesterovsky-bros.com/images/thumb-expanded-error-dialog.png" alt="collapsed error dialog" />
              </a>
            </td>
          </tr>
        </table>
        <p>
You may <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fErrorHandling.zip">download
demo project here</a>. It contains three crucial parts:
</p>
        <ul>
          <li>
A server-side error handler that catches all exceptions and serializes them as JSON
objects (see <strong>/Code/JsonErrorHandler.cs</strong> and <strong>/Code/JsonWebHttpBehaviour.cs</strong>).</li>
          <li>
An error dialog that's based on user-control defined in previous articles (see <strong>/scripts/controls/error.js</strong>,<strong> /scripts/controls/error.resources.js</strong> and <strong>/scripts/templates/error.tmpl.html</strong>).</li>
          <li>
A client-side error handler that displays errors in user-friendly's manner (see <strong>/scripts/api/api.js</strong>,
method <strong>defaultErrorHandler()</strong>).</li>
        </ul>
        <p>
Of course this is only a draft solution, but it defines a direction for further customizations
in your web applications.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f" />
      </body>
      <title>Error handling in WCF based web applications</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/05/13/ErrorHandlingInWCFBasedWebApplications.aspx</link>
      <pubDate>Mon, 13 May 2013 23:09:02 GMT</pubDate>
      <description>   &lt;p style="direction: ltr"&gt;
Although WCF REST service + JSON is outdated comparing to Web API, there are yet a
lot of such solutions (and probably will appear new ones) that use such &amp;quot;old&amp;quot;
technology. 
&lt;/p&gt;
&lt;p&gt;
One of the crucial points of any web application is an error handler that allows gracefully
resolve server-side exceptions and routes them as JSON objects to the client for further
processing. There are dozen approachesin Internet that solve this issue&amp;nbsp; (e.g. &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;amp;url=http%3a%2f%2fblog.manglar.com%2fhow-to-provide-custom-json-exceptions-from-as-wcf-service%2f"&gt;http://blog.manglar.com/how-to-provide-custom-json-exceptions-from-as-wcf-service/&lt;/a&gt;),
but there is no one that demonstrates error handling ot the client-side. We realize
that it&amp;#39;s impossible to write something general that suits for every web application,
but we&amp;#39;d like to show a client-side error handler that utilizes JSON and KendoUI.
&lt;/p&gt;
&lt;p style="direction: ltr"&gt;
On our opinion, the successfull error handler must display an understandable error
message on one hand, and on the other hand it has to provide technical info for developers
in order to investigate the exception reason (and to fix it, if need):
&lt;/p&gt;
&lt;table border="0"&gt;
&lt;tr&gt;
&lt;td style="vertical-align: top;"&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fimages%2fcolapsed-error-dialog.png"&gt; &lt;img src="http://www.nesterovsky-bros.com/images/thumb-colapsed-error-dialog.png" alt="collapsed error dialog" /&gt; &lt;/a&gt; 
&lt;/td&gt;
&lt;td&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fimages%2fexpanded-error-dialog.png"&gt; &lt;img src="http://www.nesterovsky-bros.com/images/thumb-expanded-error-dialog.png" alt="collapsed error dialog" /&gt; &lt;/a&gt; 
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;
You may &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fErrorHandling.zip"&gt;download
demo project here&lt;/a&gt;. It contains three crucial parts:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
A server-side error handler that catches all exceptions and serializes them as JSON
objects (see &lt;strong&gt;/Code/JsonErrorHandler.cs&lt;/strong&gt; and &lt;strong&gt;/Code/JsonWebHttpBehaviour.cs&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;
An error dialog that&amp;#39;s based on user-control defined in previous articles (see &lt;strong&gt;/scripts/controls/error.js&lt;/strong&gt;,&lt;strong&gt; /scripts/controls/error.resources.js&lt;/strong&gt; and &lt;strong&gt;/scripts/templates/error.tmpl.html&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;
A client-side error handler that displays errors in user-friendly&amp;#39;s manner (see &lt;strong&gt;/scripts/api/api.js&lt;/strong&gt;,
method &lt;strong&gt;defaultErrorHandler()&lt;/strong&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Of course this is only a draft solution, but it defines a direction for further customizations
in your web applications.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,3af8fe47-6f58-4e53-b4e8-6ee5a9203c2f.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET</category>
      <category>javascript</category>
      <category>kendoui</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=99e6d3c9-5860-4ccf-b565-93b68e434a30</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,99e6d3c9-5860-4ccf-b565-93b68e434a30.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,99e6d3c9-5860-4ccf-b565-93b68e434a30.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=99e6d3c9-5860-4ccf-b565-93b68e434a30</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We have upgraded KendoUI and have found that kendo window has stopped to size properly.
</p>
        <p>
In the old implementation window set dimensions like this:
</p>
        <p style="padding-left: 1em">
          <code> _dimensions: function() { 
<br />
  ...<br /><strong>  if (options.width) { 
<br />
    wrapper.width(options.width); 
<br />
  } 
<br />
  if (options.height) { 
<br />
    wrapper.height(options.height); 
<br />
  } 
<br />
  </strong>... 
<br />
}</code>
        </p>
        <p>
And here is a new implementation:
</p>
        <p style="padding-left: 1em">
          <code> _dimensions: function() { 
<br />
  ...<br /><strong>  if (options.width) { 
<br />
    wrapper.width(constrain(<span style="color: red">parseInt(options.width,
10)</span>, options.minWidth, options.maxWidth)); 
<br />
  } 
<br />
  if (options.height) { 
<br />
    wrapper.height(constrain(<span style="color: red">parseInt(options.height,
10)</span>, options.minHeight, options.maxHeight)); 
<br />
  } 
<br /></strong>  ...<br />
} </code>
        </p>
        <p>
Thus nothing but pixels are supported. Earlier we often used <code>'em'</code> units
to define dialog sizes. There was no reason to restrict it like this. That's very
unfortunate. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=99e6d3c9-5860-4ccf-b565-93b68e434a30" />
      </body>
      <title>KendoUI Window turned to the worse</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,99e6d3c9-5860-4ccf-b565-93b68e434a30.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/04/18/KendoUIWindowTurnedToTheWorse.aspx</link>
      <pubDate>Thu, 18 Apr 2013 10:44:24 GMT</pubDate>
      <description>  &lt;p&gt;
We have upgraded KendoUI and have found that kendo window has stopped to size properly.
&lt;/p&gt;
&lt;p&gt;
In the old implementation window set dimensions like this:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; _dimensions: function() { 
&lt;br /&gt;
&amp;nbsp; ...&lt;br /&gt;
&lt;strong&gt;&amp;nbsp; if (options.width) { 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; wrapper.width(options.width); 
&lt;br /&gt;
&amp;nbsp; } 
&lt;br /&gt;
&amp;nbsp; if (options.height) { 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; wrapper.height(options.height); 
&lt;br /&gt;
&amp;nbsp; } 
&lt;br /&gt;
&amp;nbsp; &lt;/strong&gt;... 
&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
And here is a new implementation:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; _dimensions: function() { 
&lt;br /&gt;
&amp;nbsp; ...&lt;br /&gt;
&lt;strong&gt;&amp;nbsp; if (options.width) { 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; wrapper.width(constrain(&lt;span style="color: red"&gt;parseInt(options.width,
10)&lt;/span&gt;, options.minWidth, options.maxWidth)); 
&lt;br /&gt;
&amp;nbsp; } 
&lt;br /&gt;
&amp;nbsp; if (options.height) { 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; wrapper.height(constrain(&lt;span style="color: red"&gt;parseInt(options.height,
10)&lt;/span&gt;, options.minHeight, options.maxHeight)); 
&lt;br /&gt;
&amp;nbsp; } 
&lt;br /&gt;
&lt;/strong&gt;&amp;nbsp; ...&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Thus nothing but pixels are supported. Earlier we often used &lt;code&gt;&amp;#39;em&amp;#39;&lt;/code&gt; units
to define dialog sizes. There was no reason to restrict it like this. That&amp;#39;s very
unfortunate. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=99e6d3c9-5860-4ccf-b565-93b68e434a30" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,99e6d3c9-5860-4ccf-b565-93b68e434a30.aspx</comments>
      <category>javascript</category>
      <category>kendoui</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=3e27a213-6843-4ad2-b603-6bc29f0ea3e0</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3e27a213-6843-4ad2-b603-6bc29f0ea3e0.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,3e27a213-6843-4ad2-b603-6bc29f0ea3e0.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=3e27a213-6843-4ad2-b603-6bc29f0ea3e0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
To simplify KendoUI development we have defined <code>nesterovskyBros.data.Model</code>,
which extends <code>kend.data.Model</code> class. 
</p>
        <h3>Extensions in <code>nesterovskyBros.data.Model</code></h3>
        <ol>
          <li>
As with <code>kendo.data.Model</code> there is <code>fields</code> Object - a set
of key/value pairs to configure the model fields, but fields have some more options: 
<ul><li><code>fields.fieldName.serializable Boolean</code> - indicates whether the field appears
in an object returned in <code>model.toJSON()</code>. Default is <code>true</code>.</li><li><code>fields.fieldName.updateDirty Boolean</code> - indicates whether the change of
the property should trigger <code>dirty</code> field change. Default is <code>true</code>.</li></ul></li>
          <li>
When model defines a field and there is a prototype function with the same name then
this function is used to get and set a field value.</li>
          <li>
When property is changed through the <code>model.set()</code> method then <code>dirty</code> change
event is triggered (provided that fields.fieldName.updateDirty !== false). This helps
to build a dependcy graph on that property.</li>
          <li>
When model instance is consturcted, the data passed in are validated, nullable and
default values are set.</li>
        </ol>
        <h3>Model example
</h3>
        <p>
Here is an example of a model:
</p>
        <p style="padding-left: 1em">
          <code>nesterovskyBros.data.ProductModel = nesterovskyBros.data.Model.define(<br />
{<br /><br />
fields:<br />
{<br />
  name: { type: "string", defaultValue: "Product Name" },<br />
  price: { type: "number", defaultValue: 10 },<br />
  unitsInStockValue: { type: "number", defaultValue: 10, serializable: false
},<br />
  unitsInStock: { type: "string" }<br />
},<br /><br />
unitsInStock: function(value)<br />
{<br />
  if (value === undefined)<br />
  {<br />
    var count = this.get("unitsInStockValue");<br /><br />
    return ["one", "two", "three", "four"][count] || (count + "");<br />
  }<br />
  else<br />
  {<br />
    this.set("unitsInStockValue", ({one: 1, two: 2, three: 3, four:
4 })[value] || value);<br />
  }<br />
}<br /><br />
}); </code>
        </p>
        <p>
Notice that:
</p>
        <ul>
          <li>
            <code>unitsInStock</code> property is implemented as a function - this helps to map
model values to presentation values. 
</li>
          <li>
when you call <code>model.toJSON()</code>, or <code>JSON.stringify()</code> you will
see in result <code>name</code>, <code>price</code>, <code>unitsInStock</code> values
only - this helps to get model's state and to store it somewhere (e.g. in <code>sessionStorage</code>).</li>
          <li>
in a code:<br /><code>  var model = new nesterovskyBros.data.ProductModel({ price: "7",
unitsInStock: "one" });</code><br />
the following is true: 
<br /><code>  (typeof(model.price) == "number") &amp;&amp; (mode.price ==
7) &amp;&amp; (model.name == "Product Name") &amp;&amp; (model.unitsInStockValue
== 1)</code></li>
        </ul>
        <p>
As with <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3e27a213-6843-4ad2-b603-6bc29f0ea3e0&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2013%2f03%2f26%2fKendoUIUserControl.aspx">UserControl</a> the
implemntation is defined in the <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3e27a213-6843-4ad2-b603-6bc29f0ea3e0&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fapi%2fcontrols.js">controls.js</a>.
The sample page is the same <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3e27a213-6843-4ad2-b603-6bc29f0ea3e0&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2findex.html">index.html</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3e27a213-6843-4ad2-b603-6bc29f0ea3e0" />
      </body>
      <title>KendoUI extended model</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3e27a213-6843-4ad2-b603-6bc29f0ea3e0.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/04/03/KendoUIExtendedModel.aspx</link>
      <pubDate>Wed, 03 Apr 2013 20:37:49 GMT</pubDate>
      <description>  &lt;p&gt;
To simplify KendoUI development we have defined &lt;code&gt;nesterovskyBros.data.Model&lt;/code&gt;,
which extends &lt;code&gt;kend.data.Model&lt;/code&gt; class. 
&lt;/p&gt;
&lt;h3&gt;Extensions in &lt;code&gt;nesterovskyBros.data.Model&lt;/code&gt;
&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
As with &lt;code&gt;kendo.data.Model&lt;/code&gt; there is &lt;code&gt;fields&lt;/code&gt; Object - a set
of key/value pairs to configure the model fields, but fields have some more options: 
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fields.fieldName.serializable Boolean&lt;/code&gt; - indicates whether the field appears
in an object returned in &lt;code&gt;model.toJSON()&lt;/code&gt;. Default is &lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fields.fieldName.updateDirty Boolean&lt;/code&gt; - indicates whether the change of
the property should trigger &lt;code&gt;dirty&lt;/code&gt; field change. Default is &lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
When model defines a field and there is a prototype function with the same name then
this function is used to get and set a field value.&lt;/li&gt;
&lt;li&gt;
When property is changed through the &lt;code&gt;model.set()&lt;/code&gt; method then &lt;code&gt;dirty&lt;/code&gt; change
event is triggered (provided that fields.fieldName.updateDirty !== false). This helps
to build a dependcy graph on that property.&lt;/li&gt;
&lt;li&gt;
When model instance is consturcted, the data passed in are validated, nullable and
default values are set.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Model example
&lt;/h3&gt;
&lt;p&gt;
Here is an example of a model:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;nesterovskyBros.data.ProductModel = nesterovskyBros.data.Model.define(&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
fields:&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; name: { type: "string", defaultValue: "Product Name" },&lt;br /&gt;
&amp;nbsp; price: { type: "number", defaultValue: 10 },&lt;br /&gt;
&amp;nbsp; unitsInStockValue: { type: "number", defaultValue: 10, serializable: false
},&lt;br /&gt;
&amp;nbsp; unitsInStock: { type: "string" }&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
unitsInStock: function(value)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; if (value === undefined)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var count = this.get("unitsInStockValue");&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return ["one", "two", "three", "four"][count] || (count + "");&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&amp;nbsp; else&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; this.set("unitsInStockValue", ({one: 1, two: 2, three: 3, four:
4 })[value] || value);&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}); &lt;/code&gt; 
&lt;/p&gt;
&lt;p&gt;
Notice that:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;unitsInStock&lt;/code&gt; property is implemented as a function - this helps to map
model values to presentation values. 
&lt;/li&gt;
&lt;li&gt;
when you call &lt;code&gt;model.toJSON()&lt;/code&gt;, or &lt;code&gt;JSON.stringify()&lt;/code&gt; you will
see in result &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;price&lt;/code&gt;, &lt;code&gt;unitsInStock&lt;/code&gt; values
only - this helps to get model&amp;#39;s state and to store it somewhere (e.g. in &lt;code&gt;sessionStorage&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
in a code:&lt;br /&gt;
&lt;code&gt;&amp;nbsp; var model = new nesterovskyBros.data.ProductModel({ price: &amp;quot;7&amp;quot;,
unitsInStock: &amp;quot;one&amp;quot; });&lt;/code&gt; 
&lt;br /&gt;
the following is true: 
&lt;br /&gt;
&lt;code&gt;&amp;nbsp; (typeof(model.price) == &amp;quot;number&amp;quot;) &amp;amp;&amp;amp; (mode.price ==
7) &amp;amp;&amp;amp; (model.name == &amp;quot;Product Name&amp;quot;) &amp;amp;&amp;amp; (model.unitsInStockValue
== 1)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
As with &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3e27a213-6843-4ad2-b603-6bc29f0ea3e0&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2013%2f03%2f26%2fKendoUIUserControl.aspx"&gt;UserControl&lt;/a&gt; the
implemntation is defined in the &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3e27a213-6843-4ad2-b603-6bc29f0ea3e0&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fapi%2fcontrols.js"&gt;controls.js&lt;/a&gt;.
The sample page is the same &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3e27a213-6843-4ad2-b603-6bc29f0ea3e0&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2findex.html"&gt;index.html&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3e27a213-6843-4ad2-b603-6bc29f0ea3e0" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,3e27a213-6843-4ad2-b603-6bc29f0ea3e0.aspx</comments>
      <category>javascript</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=f4337446-1b5e-4007-a1f8-a62b9d99681f</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,f4337446-1b5e-4007-a1f8-a62b9d99681f.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,f4337446-1b5e-4007-a1f8-a62b9d99681f.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=f4337446-1b5e-4007-a1f8-a62b9d99681f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Developing with KendoUI we try to formalize tasks. With this in mind we would like
to have user controls. 
</p>
        <p>
We define user control as following:
</p>
        <p style="padding-left: 1em">
It is a javascript class that extends Widget.<br />
It offers a way to reuse UI.<br />
It allows to define a model and a template with UI and data binding.
</p>
        <p>
Unfortunately, KendoUI does not have such API, though one can easily define it; so
we have defined our version.
</p>
        <p>
Here we review our solution. We have taken a grid KendoUI example and converted it
into a user control.
</p>
        <h3 style="direction: ltr">User control on the page
</h3>
        <p style="direction: ltr">
See <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2findex.html">index.html</a></p>
        <p style="padding-left: 1em">
          <code style="direction: ltr">&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
  &lt;title&gt;Test&lt;/title&gt;<br /><br />
  <strong>&lt;!-- (1) Include templates for controls. --&gt;</strong><br />
  &lt;script src="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates.js">scripts/templates.js</a>"&gt;&lt;/script&gt;<br /><br />
  &lt;script src="scripts/jquery/jquery.js"&gt;&lt;/script&gt;<br />
  &lt;script src="scripts/kendo/kendo.web.min.js"&gt;&lt;/script&gt;<br /><br />
  <strong>&lt;!-- (2) UserControl definition. --&gt;</strong><br />
  &lt;script src="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols.js">scripts/controls.js</a>"&gt;&lt;/script&gt;<br /><br />
  <strong>&lt;!-- (3) Confirm dialog user control. --&gt;</strong><br />
  &lt;script src="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols%2fconfirm.js">scripts/controls/confirm.js</a>"&gt;&lt;/script&gt;<br /><br />
  <strong>&lt;!-- (4) Products user control. --&gt;</strong><br />
  &lt;script src="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols%2fproducts.js">scripts/controls/products.js</a>"&gt;&lt;/script&gt;<br /><br />
  &lt;link href="styles/kendo.common.min.css" rel="stylesheet" /&gt;<br />
  &lt;link href="styles/kendo.default.min.css" rel="stylesheet" /&gt;<br />
  &lt;script&gt;<br />
$(function ()<br />
{<br />
  <strong>// (5) Bind the page.</strong><br />
  kendo.bind(<br />
    document.body,<br />
    <strong>// (6) Model as a datasource.</strong><br />
    { source: [new nesterovskyBros.data.ProductsModel] });<br />
});<br />
  &lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
  <strong>&lt;!-- (7) User control and its binding. --&gt;</strong><br />
  &lt;div data-role="<strong>products</strong>" data-bind="<strong>source: source</strong>"&gt;&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt; </code>
        </p>
        <p>
That's what we see here:
</p>
        <ol>
          <li>
Templates that define layouts. See "<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2013%2f01%2f06%2fHowToLoadKendoUITemplatesFromExternalFiles.aspx">How
To: Load KendoUI Templates from External Files</a>", and <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates.tt">templates.tt</a>.</li>
          <li>
Definition of the UserControl widget.</li>
          <li>
Confirm dialog user control (we shall mention it later).</li>
          <li>
Products user control.</li>
          <li>
Data binding that instantiates page controls.</li>
          <li>
Model is passed to a user control through the dataSource.</li>
          <li>
Use of Products user control. Notice that "data-role" defines control type,
"source" refers to the model.</li>
        </ol>
        <h3>User Control declaration
</h3>
        <p>
Declaration consists of a view and a model. 
</p>
        <p>
View is html with data binding. See <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates%2fproducts.tmpl.html">products.tmpl.html</a></p>
        <p>
We build our project using Visual Studio, so templates packaging is done with <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates.tt">templates.tt</a>.
This transformation converts products template into a tag:
</p>
        <p style="padding-left: 1em">
          <code>&lt;script id="products-template" type="text/x-kendo-template"&gt;</code>
        </p>
        <p>
thus template can be referred by a utility function: <code>nesterovskyBros.template("products-template")</code>.
</p>
        <p>
Model inherits kedo.data.Model. Here how it looks:
</p>
        <p style="padding-left: 1em">
          <code>
            <strong>// (1) Define a ProducsModel class</strong>.<br />
nesterovskyBros.data.ProductsModel = <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fdocs.kendoui.com%2fapi%2fframework%2fmodel">kendo.data.Model.define</a>(<br />
{<br /><br /><strong>// (2) Model properties.</strong><br />
fields:<br />
{<br />
  productName: { type: "string", defaultValue: "Product Name" },<br />
  productPrice: { type: "number", defaultValue: 10 },<br />
  productUnitsInStock: { type: "number", defaultValue: 10 },<br />
  products: { type: "default", defaultValue: [] }<br />
},<br /><br /><strong>// (3) Model methods.</strong><br />
addProduct: function () { ... },<br />
deleteProduct: function (e) { ... },<br />
...<br /><br />
});<br /><br /><strong>// (4) Register user control.</strong><br />
nesterovskyBros.ui.Products = nesterovskyBros.defineControl(<br />
{<br />
  name: "Products",<br />
  model: nesterovskyBros.data.ProductsModel<br />
});</code>
        </p>
        <p>
That's what we have here:
</p>
        <ol>
          <li>
We define a model that inherits KendoUI Model.</li>
          <li>
We define model fields.</li>
          <li>
We define model methods.</li>
          <li>
Register user control with  <code>nesterovskyBros.defineControl(proto)</code> call,
where:<br /><ul><li><code>proto.name</code> - defines user control name;</li><li><code>proto.model</code> - defines model type;</li><li><code>proto.template</code> - defines optional template. If not specified, a template
is retrieved from <code>$("#" + proto.name.toLowerCase() + "-template").html()</code>.</li></ul></li>
        </ol>
        <h3>UserControl API
</h3>
        <p>
Now, what's remained is API for the UserControl. See <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols.js">controls.js</a>.
</p>
        <ol>
          <li>
UserControl defines following events:<br /><ul><li><code>change</code> - triggered when data source is changed;</li><li><code>dataBound</code> - triggered when widget is data bound;</li><li><code>dataBinding</code> - triggered befor widget data binding;</li><li><code>save</code> - used to notify user to save model state.</li></ul></li>
          <li>
UserControl defines following options:<br /><ul><li><code>autoBind (default false)</code> - autoBind data source;</li><li><code>template (default $.noop)</code> - user control template.</li></ul></li>
          <li>
UserControl defines <code>dataSource</code> field and <code>setDataSource()</code> method.</li>
          <li>
UserControl defines <code>rebind()</code> method to manually rebuild widget's
view from the template and model.</li>
          <li>
UserControl sets/deletes model.owner, which is a function returning a user control
widget when model is bound/unbound to the widget.</li>
          <li>
When UserControl binds/unbinds model a <code>model.refresh</code> method is called,
if any.</li>
          <li>
You usually define you control with a call <code>nesterovskyBros.defineControl(proto)</code>.
See above.</li>
          <li>
There is also a convenience method to build a dialog based on a user control: nesterovskyBros.defineDialog(options),
where<br /><ul><li><code>options.name</code> - a user control name (used in the data-role);</li><li><code>options.model</code> - a model type;</li><li><code>options.windowOptions</code> - a window options.</li></ul>
This method returns a function that recieves a user control model, and returns a dialog
(<code>kendo.ui.Window</code>) based on the user control.<br />
Dialog has <code>model()</code> function that returns an instance of model.<br />
Model has <code>dialog()</code> function that returns an instance of the dialog.<br />
Dialog and model have <code>result()</code> function that returns an instance of deferred
object used to track dialog completion.<br />
The example of user control dialog is <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols%2fconfirm.js">confirm.js</a> and <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates%2fconfirm.tmpl.html">confirm.tmpl.html</a>.
The use is in the <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols%2fproducts.js">products.js</a> deleteProduct():<br /><p style="padding-left: 1em"><code>deleteProduct: function(e) 
<br />
{<br />
  var that = this;<br /><br />
  return nesterovskyBros.dialog.confirm(<br />
  {<br />
    title: "Please confirm",<br />
    message: "Do you want to delete the record?",<br />
    confirm: "Yes",<br />
    cancel: "No"<br />
  }).<br />
  open().<br />
  center().<br />
  result().<br />
  then(<br />
    function(confirmed)<br />
    {<br />
      if (!confirmed)<br />
      {<br />
        return;<br />
      }<br />
      ...<br />
   });<br />
}</code></p></li>
        </ol>
        <h3>Last
</h3>
        <p>
User controls along with technique to manage and cache templates allow us to build
robust web applications. As the added value it's became a trivial task to build
SPA.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f" />
      </body>
      <title>KendoUI User control</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,f4337446-1b5e-4007-a1f8-a62b9d99681f.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/03/26/KendoUIUserControl.aspx</link>
      <pubDate>Tue, 26 Mar 2013 21:40:05 GMT</pubDate>
      <description>  &lt;p&gt;
Developing with KendoUI we try to formalize tasks. With this in mind we would like
to have user controls. 
&lt;/p&gt;
&lt;p&gt;
We define user control as following:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
It is a javascript class that extends Widget.&lt;br /&gt;
It offers a way to reuse UI.&lt;br /&gt;
It allows to define a model and a template with UI and data binding.
&lt;/p&gt;
&lt;p&gt;
Unfortunately, KendoUI does not have such API, though one can easily define it; so
we have defined our version.
&lt;/p&gt;
&lt;p&gt;
Here we review our solution. We have taken a grid KendoUI example and converted it
into a user control.
&lt;/p&gt;
&lt;h3 style="direction: ltr"&gt;User control on the page
&lt;/h3&gt;
&lt;p style="direction: ltr"&gt;
See &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2findex.html"&gt;index.html&lt;/a&gt;
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code style="direction: ltr"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;strong&gt;&amp;lt;!-- (1) Include templates for controls. --&amp;gt;&lt;/strong&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;script src="&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates.js"&gt;scripts/templates.js&lt;/a&gt;"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;script src="scripts/jquery/jquery.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;script src="scripts/kendo/kendo.web.min.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;strong&gt;&amp;lt;!-- (2) UserControl definition. --&amp;gt;&lt;/strong&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;script src="&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols.js"&gt;scripts/controls.js&lt;/a&gt;"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;strong&gt;&amp;lt;!-- (3) Confirm dialog user control. --&amp;gt;&lt;/strong&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;script src="&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols%2fconfirm.js"&gt;scripts/controls/confirm.js&lt;/a&gt;"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;strong&gt;&amp;lt;!-- (4) Products user control. --&amp;gt;&lt;/strong&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;script src="&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols%2fproducts.js"&gt;scripts/controls/products.js&lt;/a&gt;"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;link href="styles/kendo.common.min.css" rel="stylesheet" /&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;link href="styles/kendo.default.min.css" rel="stylesheet" /&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;script&amp;gt;&lt;br /&gt;
$(function ()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &lt;strong&gt;// (5) Bind the page.&lt;/strong&gt;
&lt;br /&gt;
&amp;nbsp; kendo.bind(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; document.body,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;// (6) Model as a datasource.&lt;/strong&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; { source: [new nesterovskyBros.data.ProductsModel] });&lt;br /&gt;
});&lt;br /&gt;
&amp;nbsp; &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;nbsp; &lt;strong&gt;&amp;lt;!-- (7) User control and its binding. --&amp;gt;&lt;/strong&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;div data-role="&lt;strong&gt;products&lt;/strong&gt;" data-bind="&lt;strong&gt;source: source&lt;/strong&gt;"&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt; &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
That&amp;#39;s what we see here:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Templates that define layouts. See &amp;quot;&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2013%2f01%2f06%2fHowToLoadKendoUITemplatesFromExternalFiles.aspx"&gt;How
To: Load KendoUI Templates from External Files&lt;/a&gt;&amp;quot;, and &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates.tt"&gt;templates.tt&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
Definition of the UserControl widget.&lt;/li&gt;
&lt;li&gt;
Confirm dialog user control (we shall mention it later).&lt;/li&gt;
&lt;li&gt;
Products user control.&lt;/li&gt;
&lt;li&gt;
Data binding that instantiates page controls.&lt;/li&gt;
&lt;li&gt;
Model is passed to a user control through the dataSource.&lt;/li&gt;
&lt;li&gt;
Use of Products user control. Notice that &amp;quot;data-role&amp;quot; defines control type,
&amp;quot;source&amp;quot; refers to the model.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;User Control declaration
&lt;/h3&gt;
&lt;p&gt;
Declaration consists of a view and a model. 
&lt;/p&gt;
&lt;p&gt;
View is html with data binding. See &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates%2fproducts.tmpl.html"&gt;products.tmpl.html&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We build our project using Visual Studio, so templates packaging is done with &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates.tt"&gt;templates.tt&lt;/a&gt;.
This transformation converts products template into a tag:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;script id="products-template" type="text/x-kendo-template"&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
thus template can be referred by a utility function: &lt;code&gt;nesterovskyBros.template(&amp;quot;products-template&amp;quot;)&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
Model inherits kedo.data.Model. Here how it looks:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&lt;strong&gt;// (1) Define a ProducsModel class&lt;/strong&gt;.&lt;br /&gt;
nesterovskyBros.data.ProductsModel = &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fdocs.kendoui.com%2fapi%2fframework%2fmodel"&gt;kendo.data.Model.define&lt;/a&gt;(&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;// (2) Model properties.&lt;/strong&gt;
&lt;br /&gt;
fields:&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; productName: { type: "string", defaultValue: "Product Name" },&lt;br /&gt;
&amp;nbsp; productPrice: { type: "number", defaultValue: 10 },&lt;br /&gt;
&amp;nbsp; productUnitsInStock: { type: "number", defaultValue: 10 },&lt;br /&gt;
&amp;nbsp; products: { type: "default", defaultValue: [] }&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;// (3) Model methods.&lt;/strong&gt;
&lt;br /&gt;
addProduct: function () { ... },&lt;br /&gt;
deleteProduct: function (e) { ... },&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;// (4) Register user control.&lt;/strong&gt;
&lt;br /&gt;
nesterovskyBros.ui.Products = nesterovskyBros.defineControl(&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; name: "Products",&lt;br /&gt;
&amp;nbsp; model: nesterovskyBros.data.ProductsModel&lt;br /&gt;
});&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
That's what we have here:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
We define a model that inherits KendoUI Model.&lt;/li&gt;
&lt;li&gt;
We define model fields.&lt;/li&gt;
&lt;li&gt;
We define model methods.&lt;/li&gt;
&lt;li&gt;
Register user control with&amp;nbsp; &lt;code&gt;nesterovskyBros.defineControl(proto)&lt;/code&gt; call,
where:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;proto.name&lt;/code&gt; - defines user control name;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;proto.model&lt;/code&gt; - defines model type;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;proto.template&lt;/code&gt; - defines optional template. If not specified, a template
is retrieved from &lt;code&gt;$(&amp;quot;#&amp;quot; + proto.name.toLowerCase() + &amp;quot;-template&amp;quot;).html()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;UserControl API
&lt;/h3&gt;
&lt;p&gt;
Now, what&amp;#39;s remained is API for the UserControl. See &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols.js"&gt;controls.js&lt;/a&gt;.
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
UserControl defines following events:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;change&lt;/code&gt; - triggered when data source is changed;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dataBound&lt;/code&gt; - triggered when widget is data bound;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dataBinding&lt;/code&gt; - triggered befor widget data binding;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;save&lt;/code&gt; - used to notify user to save model state.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
UserControl defines following options:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;autoBind (default false)&lt;/code&gt; - autoBind data source;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;template (default $.noop)&lt;/code&gt; - user control template.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
UserControl defines &lt;code&gt;dataSource&lt;/code&gt; field and &lt;code&gt;setDataSource()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;
UserControl defines &lt;code&gt;rebind()&lt;/code&gt; method to manually rebuild widget&amp;#39;s
view from the template and model.&lt;/li&gt;
&lt;li&gt;
UserControl sets/deletes model.owner, which is a function returning a user control
widget when model is bound/unbound to the widget.&lt;/li&gt;
&lt;li&gt;
When UserControl binds/unbinds model a &lt;code&gt;model.refresh&lt;/code&gt; method is called,
if any.&lt;/li&gt;
&lt;li&gt;
You usually define you control with a call &lt;code&gt;nesterovskyBros.defineControl(proto)&lt;/code&gt;.
See above.&lt;/li&gt;
&lt;li&gt;
There is also a convenience method to build a dialog based on a user control: nesterovskyBros.defineDialog(options),
where&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;options.name&lt;/code&gt; - a user control name (used in the data-role);&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;options.model&lt;/code&gt; - a model type;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;options.windowOptions&lt;/code&gt; - a window options.&lt;/li&gt;
&lt;/ul&gt;
This method returns a function that recieves a user control model, and returns a dialog
(&lt;code&gt;kendo.ui.Window&lt;/code&gt;) based on the user control.&lt;br /&gt;
Dialog has &lt;code&gt;model()&lt;/code&gt; function that returns an instance of model.&lt;br /&gt;
Model has &lt;code&gt;dialog()&lt;/code&gt; function that returns an instance of the dialog.&lt;br /&gt;
Dialog and model have &lt;code&gt;result()&lt;/code&gt; function that returns an instance of deferred
object used to track dialog completion.&lt;br /&gt;
The example of user control dialog is &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols%2fconfirm.js"&gt;confirm.js&lt;/a&gt; and &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2ftemplates%2fconfirm.tmpl.html"&gt;confirm.tmpl.html&lt;/a&gt;.
The use is in the &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fKendoUI%2fscripts%2fcontrols%2fproducts.js"&gt;products.js&lt;/a&gt; deleteProduct():&lt;br /&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;deleteProduct: function(e) 
&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; var that = this;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; return nesterovskyBros.dialog.confirm(&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; title: "Please confirm",&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; message: "Do you want to delete the record?",&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; confirm: "Yes",&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; cancel: "No"&lt;br /&gt;
&amp;nbsp; }).&lt;br /&gt;
&amp;nbsp; open().&lt;br /&gt;
&amp;nbsp; center().&lt;br /&gt;
&amp;nbsp; result().&lt;br /&gt;
&amp;nbsp; then(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; function(confirmed)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!confirmed)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br /&gt;
&amp;nbsp;&amp;nbsp; });&lt;br /&gt;
}&lt;/code&gt; 
&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Last
&lt;/h3&gt;
&lt;p&gt;
User controls along with technique to manage and cache templates allow us to build
robust web applications. As the added value it&amp;#39;s became a trivial task to build
SPA.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=f4337446-1b5e-4007-a1f8-a62b9d99681f" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,f4337446-1b5e-4007-a1f8-a62b9d99681f.aspx</comments>
      <category>javascript</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=89749038-a489-4354-8f0a-f35c7f3c73b7</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,89749038-a489-4354-8f0a-f35c7f3c73b7.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,89749038-a489-4354-8f0a-f35c7f3c73b7.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=89749038-a489-4354-8f0a-f35c7f3c73b7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
At present we inhabit in jquery and kendoui world. 
</p>
        <p>
There you deal with MVVM design pattern and build you page from blocks. To avoid conflicts
you usually restrict yourself from assigning ids to elements, as they make code reuse
somewhat problematic.
</p>
        <p>
But what if you have a label that you would like to associate with an input. In plain
html you would write:
</p>
        <p style="padding-left: 1em">
          <code>&lt;label <strong>for="my-input"</strong>&gt;My label:&lt;/label&gt;
&lt;input <strong> id="my-input"</strong> type="text"&gt;</code>
        </p>
        <p>
Html spec suggests to use element id to build such an association.
</p>
        <p>
So, how to avoid introduction of id, and to allow to select input while clicking on
the label?
</p>
        <p>
In our projects we use a little utility function that solves exactly this task. It's
easier to quote an example than to describe implementation:
</p>
        <p style="padding-left: 1em">
          <code>&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Label&lt;/title&gt;<br />
&lt;script src="scripts/jquery.js"&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div class="view"&gt;<br />
&lt;div&gt;A template:&lt;/div&gt;<br />
&lt;table&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;&lt;label data-for="[name=field1]"&gt;Name1:&lt;/label&gt;&lt;/td&gt;<br />
&lt;td&gt;&lt;input name="field1" type="text" /&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;&lt;label data-for="[name=field2]"&gt;Name2:&lt;/label&gt;&lt;/td&gt;<br />
&lt;td&gt;&lt;input name="field2" type="text" /&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;&lt;label data-for="[name=field3]"&gt;Name3:&lt;/label&gt;&lt;/td&gt;<br />
&lt;td&gt;&lt;input name="field3" type="text" /&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;&lt;label data-for="[name=field4]"&gt;Name4:&lt;/label&gt;&lt;/td&gt;<br />
&lt;td&gt;&lt;input name="field4" type="checkbox" /&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;&lt;label data-for="[name=field5][value=0]"&gt;Name5:&lt;/label&gt;&lt;/td&gt;<br />
&lt;td&gt;&lt;input name="field5" value="0" type="radio" /&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;&lt;label data-for="[name=field5][value=1]"&gt;Name6:&lt;/label&gt;&lt;/td&gt;<br />
&lt;td&gt;&lt;input name="field5" value="1" type="radio" /&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/div&gt;<br />
&lt;script&gt;<br />
$(document).on(<br />
"click",<br />
"label[data-for]",<br />
function(e)<br />
{<br />
var target = $(e.target);<br /><br />
target.closest(target.attr("data-view") || ".view").<br />
find(target.attr("data-for")).<br />
filter(":visible:enabled").first().click().focus().<br />
filter("input[type=checkbox],input[type=radio]").change();<br />
});<br />
&lt;/script&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt; </code>
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=89749038-a489-4354-8f0a-f35c7f3c73b7" />
      </body>
      <title>How to associate a label and avoid id conflicts in html</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,89749038-a489-4354-8f0a-f35c7f3c73b7.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/02/11/HowToAssociateALabelAndAvoidIdConflictsInHtml.aspx</link>
      <pubDate>Mon, 11 Feb 2013 21:40:18 GMT</pubDate>
      <description>  &lt;p&gt;
At present we inhabit in jquery and kendoui world. 
&lt;/p&gt;
&lt;p&gt;
There you deal with MVVM design pattern and build you page from blocks. To avoid conflicts
you usually restrict yourself from assigning ids to elements, as they make code reuse
somewhat problematic.
&lt;/p&gt;
&lt;p&gt;
But what if you have a label that you would like to associate with an input. In plain
html you would write:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;label &lt;strong&gt;for=&amp;quot;my-input&amp;quot;&lt;/strong&gt;&amp;gt;My label:&amp;lt;/label&amp;gt;
&amp;lt;input &lt;strong&gt; id=&amp;quot;my-input&amp;quot;&lt;/strong&gt; type=&amp;quot;text&amp;quot;&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Html spec suggests to use element id to build such an association.
&lt;/p&gt;
&lt;p&gt;
So, how to avoid introduction of id, and to allow to select input while clicking on
the label?
&lt;/p&gt;
&lt;p&gt;
In our projects we use a little utility function that solves exactly this task. It&amp;#39;s
easier to quote an example than to describe implementation:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;title&amp;gt;Label&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;script src="scripts/jquery.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;div class="view"&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;A template:&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;label data-for="[name=field1]"&amp;gt;Name1:&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;input name="field1" type="text" /&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;label data-for="[name=field2]"&amp;gt;Name2:&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;input name="field2" type="text" /&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;label data-for="[name=field3]"&amp;gt;Name3:&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;input name="field3" type="text" /&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;label data-for="[name=field4]"&amp;gt;Name4:&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;input name="field4" type="checkbox" /&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;label data-for="[name=field5][value=0]"&amp;gt;Name5:&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;input name="field5" value="0" type="radio" /&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;label data-for="[name=field5][value=1]"&amp;gt;Name6:&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;input name="field5" value="1" type="radio" /&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
$(document).on(&lt;br /&gt;
"click",&lt;br /&gt;
"label[data-for]",&lt;br /&gt;
function(e)&lt;br /&gt;
{&lt;br /&gt;
var target = $(e.target);&lt;br /&gt;
&lt;br /&gt;
target.closest(target.attr("data-view") || ".view").&lt;br /&gt;
find(target.attr("data-for")).&lt;br /&gt;
filter(":visible:enabled").first().click().focus().&lt;br /&gt;
filter("input[type=checkbox],input[type=radio]").change();&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt; &lt;/code&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=89749038-a489-4354-8f0a-f35c7f3c73b7" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,89749038-a489-4354-8f0a-f35c7f3c73b7.aspx</comments>
      <category>javascript</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=9788868d-d1a2-4d8e-a1c5-2f8d41ce2aff</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9788868d-d1a2-4d8e-a1c5-2f8d41ce2aff.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9788868d-d1a2-4d8e-a1c5-2f8d41ce2aff.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=9788868d-d1a2-4d8e-a1c5-2f8d41ce2aff</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In our applications we must support IE 8, and unfortunately we hit some leak, which
is registered as <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9788868d-d1a2-4d8e-a1c5-2f8d41ce2aff&amp;url=http%3a%2f%2fbugs.jquery.com%2fticket%2f7054">Ticket
#7054(closed bug: fixed)</a>.
</p>
        <p>
While bug declared closed as fixed we can see that memory leak in <strong>IE8</strong> like
a mad. Not sure if something can be done about it. 
</p>
        <p>
The test case is:
</p>
        <p style="padding-left: 1em">
          <code>&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
  &lt;title&gt;Test&lt;/title&gt;<br />
  &lt;script src="scripts/jquery/<strong>jquery-1.9.0.js</strong>"&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;script&gt;<br />
function testLeak()<br />
{<br />
  var handler = function () { };<br /><br />
  $('&lt;div&gt;&lt;/div&gt;').html(new Array(1000).join(new Array(1000).join('x'))).bind('abc',
handler).appendTo('#test').remove();<br />
}<br /><br />
$(function() { setInterval(testLeak, 1000); });<br />
&lt;/script&gt;<br /><strong>&lt;div id="test"&gt;&lt;/div&gt;</strong><br />
&lt;/body&gt;<br />
&lt;/html&gt; </code>
        </p>
        <p>
Update: jaubourg has pointed that we have missed to define element with id="test".
With this element leak stops.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9788868d-d1a2-4d8e-a1c5-2f8d41ce2aff" />
      </body>
      <title>jquery's Ticket's #7054 (closed bug: fixed)</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9788868d-d1a2-4d8e-a1c5-2f8d41ce2aff.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/02/10/jquerysTickets7054ClosedBugFixed.aspx</link>
      <pubDate>Sun, 10 Feb 2013 05:17:33 GMT</pubDate>
      <description>&lt;p&gt;
In our applications we must support IE 8, and unfortunately we hit some leak, which
is registered as &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9788868d-d1a2-4d8e-a1c5-2f8d41ce2aff&amp;amp;url=http%3a%2f%2fbugs.jquery.com%2fticket%2f7054"&gt;Ticket
#7054(closed bug: fixed)&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
While bug declared closed as fixed we can see that memory leak in &lt;strong&gt;IE8&lt;/strong&gt; like
a mad. Not sure if something can be done about it. 
&lt;/p&gt;
&lt;p&gt;
The test case is:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;script src="scripts/jquery/&lt;strong&gt;jquery-1.9.0.js&lt;/strong&gt;"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
function testLeak()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; var handler = function () { };&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; $('&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;').html(new Array(1000).join(new Array(1000).join('x'))).bind('abc',
handler).appendTo('#test').remove();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$(function() { setInterval(testLeak, 1000); });&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;strong&gt;&amp;lt;div id="test"&amp;gt;&amp;lt;/div&amp;gt;&lt;/strong&gt;
&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt; &lt;/code&gt; 
&lt;/p&gt;
&lt;p&gt;
Update: jaubourg has pointed that we have missed to define element with id="test".
With this element leak stops.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9788868d-d1a2-4d8e-a1c5-2f8d41ce2aff" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9788868d-d1a2-4d8e-a1c5-2f8d41ce2aff.aspx</comments>
      <category>javascript</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=b17502e5-9edf-43d2-9fab-7a5a3124ddf5</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,b17502e5-9edf-43d2-9fab-7a5a3124ddf5.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,b17502e5-9edf-43d2-9fab-7a5a3124ddf5.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=b17502e5-9edf-43d2-9fab-7a5a3124ddf5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Kendo UI Docs contains an article "<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;url=http%3a%2f%2fdocs.kendoui.com%2fhowto%2fload-templates-external-files">How
To: Load Templates from External Files</a>", where authors review two way of
dealing with Kendo UI templates.
</p>
        <p>
While using Kendo UI we have found our own answer to: <i>where will the Kendo UI templates
be defined and maintained?</i></p>
        <p style="float: right">
          <img alt="solution tree" src="content/binary/templates.png" style="width: 320px" />
        </p>
        <p>
In our .NET project we have decided to keep templates separately, and to store them
under the "templates" folder. Those templates are in fact include html,
head, and stylesheet links. This is to help us to present those tempates in the design
view. 
</p>
        <p>
In our scripts folder, we have defined a small text transformation template: "templates.tt",
which produces "templates.js" file. This template takes body contents of
each "*.tmpl.html" file from "templates" folder and builds string
of the form:
</p>
        <p style="padding-left: 1em">
          <code>document.write('&lt;script id="footer-template" type="text/x-kendo-template"&gt;...&lt;/script&gt;&lt;script
id="row-template" type="text/x-kendo-template"&gt;...&lt;/script&gt;');</code>
        </p>
        <p>
In our page that uses templates, we include "templates.js":
</p>
        <p style="padding-left: 1em">
          <code> &lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;script src="scripts/templates.js"&gt;&lt;/script&gt; 
<br />
...</code>
        </p>
        <p>
Thus, we have:
</p>
        <ul>
          <li>
clean separation of templates and page content;</li>
          <li>
automatically generated templates include file.</li>
        </ul>
        <p>
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fWebTemplates.zip">WebTemplates.zip</a> contains
a web project demonstrating our technique. "<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2ftemplates.tt.txt">templates.tt</a>"
is text template transformation used in the project.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5" />
      </body>
      <title>How To: Load KendoUI Templates from External Files</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,b17502e5-9edf-43d2-9fab-7a5a3124ddf5.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/01/06/HowToLoadKendoUITemplatesFromExternalFiles.aspx</link>
      <pubDate>Sun, 06 Jan 2013 19:43:19 GMT</pubDate>
      <description>&lt;p&gt;
Kendo UI Docs contains an article &amp;quot;&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;amp;url=http%3a%2f%2fdocs.kendoui.com%2fhowto%2fload-templates-external-files"&gt;How
To: Load Templates from External Files&lt;/a&gt;&amp;quot;, where authors review two way of
dealing with Kendo UI templates.
&lt;/p&gt;
&lt;p&gt;
While using Kendo UI we have found our own answer to: &lt;i&gt;where will the Kendo UI templates
be defined and maintained?&lt;/i&gt;
&lt;/p&gt;
&lt;p style="float: right"&gt;
&lt;img alt="solution tree" src="content/binary/templates.png" style="width: 320px" /&gt;
&lt;/p&gt;
&lt;p&gt;
In our .NET project we have decided to keep templates separately, and to store them
under the &amp;quot;templates&amp;quot; folder. Those templates are in fact include html,
head, and stylesheet links. This is to help us to present those tempates in the design
view. 
&lt;/p&gt;
&lt;p&gt;
In our scripts folder, we have defined a small text transformation template: &amp;quot;templates.tt&amp;quot;,
which produces &amp;quot;templates.js&amp;quot; file. This template takes body contents of
each &amp;quot;*.tmpl.html&amp;quot; file from &amp;quot;templates&amp;quot; folder and builds string
of the form:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;document.write('&amp;lt;script id="footer-template" type="text/x-kendo-template"&amp;gt;...&amp;lt;/script&amp;gt;&amp;lt;script
id="row-template" type="text/x-kendo-template"&amp;gt;...&amp;lt;/script&amp;gt;');&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
In our page that uses templates, we include &amp;quot;templates.js&amp;quot;:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; &amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;script src=&amp;quot;scripts/templates.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt; 
&lt;br /&gt;
...&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Thus, we have:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
clean separation of templates and page content;&lt;/li&gt;
&lt;li&gt;
automatically generated templates include file.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fWebTemplates.zip"&gt;WebTemplates.zip&lt;/a&gt; contains
a web project demonstrating our technique. &amp;quot;&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2ftemplates.tt.txt"&gt;templates.tt&lt;/a&gt;&amp;quot;
is text template transformation used in the project.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=b17502e5-9edf-43d2-9fab-7a5a3124ddf5" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,b17502e5-9edf-43d2-9fab-7a5a3124ddf5.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET</category>
      <category>javascript</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=5e4d06ce-7ca2-4145-ae50-274a4d0231f3</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5e4d06ce-7ca2-4145-ae50-274a4d0231f3.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,5e4d06ce-7ca2-4145-ae50-274a4d0231f3.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=5e4d06ce-7ca2-4145-ae50-274a4d0231f3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
For some reason KendoUI DataSource does not allow to access current ajax request.
Indeed, it seems quite natural to have a way to cancel running request.
</p>
        <p>
To achieve a desired effect we have made a small set of changes in the <code>RemoteTransport</code> class:
</p>
        <p>
          <code> var RemoteTransport_setup = kendo.RemoteTransport.fn.setup;<br /></code>
          <br />
          <code> kendo.RemoteTransport.fn.setup = function()<br />
{<br />
var that = this,<br />
options = RemoteTransport_setup.apply(that, arguments),<br />
beforeSend = options.beforeSend;<br /><br />
options.beforeSend = functions(request, options)<br />
{<br />
that.abort();<br /><br />
that._request = request;<br /><br />
if (beforeSend &amp;&amp; (beforeSend.apply(this, arguments) === false))<br />
{<br />
that._request = null;<br /><br />
return false;<br />
}<br /><br />
request.always(function() { that._request = null; });<br />
} 
<br /><br />
return options;<br />
}<br /><br />
kendo.RemoteTransport.fn.request = function()<br />
{<br />
return this._request;<br />
}<br /><br />
kendo.RemoteTransport.fn.abort = function()<br />
{<br />
var request = this._request;<br /><br />
if (request)<br />
{<br />
this._request = null;<br />
request.abort();<br />
}<br />
}</code>
        </p>
        <p>
These changes allow to get an ajax request instance: <code>grid.dataSource.request()</code>,
or to cancel a request <code>grid.dataSource.abort()</code>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5e4d06ce-7ca2-4145-ae50-274a4d0231f3" />
      </body>
      <title> KendoUI Tips</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5e4d06ce-7ca2-4145-ae50-274a4d0231f3.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/06/24/KendoUITips.aspx</link>
      <pubDate>Sun, 24 Jun 2012 19:59:30 GMT</pubDate>
      <description>  &lt;p&gt;
For some reason KendoUI DataSource does not allow to access current ajax request.
Indeed, it seems quite natural to have a way to cancel running request.
&lt;/p&gt;
&lt;p&gt;
To achieve a desired effect we have made a small set of changes in the &lt;code&gt;RemoteTransport&lt;/code&gt; class:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt; var RemoteTransport_setup = kendo.RemoteTransport.fn.setup;&lt;br /&gt;
&lt;/code&gt; 
&lt;br /&gt;
&lt;code&gt; kendo.RemoteTransport.fn.setup = function()&lt;br /&gt;
{&lt;br /&gt;
var that = this,&lt;br /&gt;
options = RemoteTransport_setup.apply(that, arguments),&lt;br /&gt;
beforeSend = options.beforeSend;&lt;br /&gt;
&lt;br /&gt;
options.beforeSend = functions(request, options)&lt;br /&gt;
{&lt;br /&gt;
that.abort();&lt;br /&gt;
&lt;br /&gt;
that._request = request;&lt;br /&gt;
&lt;br /&gt;
if (beforeSend &amp;amp;&amp;amp; (beforeSend.apply(this, arguments) === false))&lt;br /&gt;
{&lt;br /&gt;
that._request = null;&lt;br /&gt;
&lt;br /&gt;
return false;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
request.always(function() { that._request = null; });&lt;br /&gt;
} 
&lt;br /&gt;
&lt;br /&gt;
return options;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
kendo.RemoteTransport.fn.request = function()&lt;br /&gt;
{&lt;br /&gt;
return this._request;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
kendo.RemoteTransport.fn.abort = function()&lt;br /&gt;
{&lt;br /&gt;
var request = this._request;&lt;br /&gt;
&lt;br /&gt;
if (request)&lt;br /&gt;
{&lt;br /&gt;
this._request = null;&lt;br /&gt;
request.abort();&lt;br /&gt;
}&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
These changes allow to get an ajax request instance: &lt;code&gt;grid.dataSource.request()&lt;/code&gt;,
or to cancel a request &lt;code&gt;grid.dataSource.abort()&lt;/code&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5e4d06ce-7ca2-4145-ae50-274a4d0231f3" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,5e4d06ce-7ca2-4145-ae50-274a4d0231f3.aspx</comments>
      <category>javascript</category>
      <category>Tips and tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=1eeefbd4-00f5-47e4-9748-4179fe7a7a09</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,1eeefbd4-00f5-47e4-9748-4179fe7a7a09.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,1eeefbd4-00f5-47e4-9748-4179fe7a7a09.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=1eeefbd4-00f5-47e4-9748-4179fe7a7a09</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We're pleased to work with Kendo UI. Its design is good, however we find here
and there things we would wish be done better. Here is a list of problems in a no
particular order we would like to be addressed in the next release:
</p>
        <ul>
          <li>
RTL is not supported (including correct scroll bar position see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1eeefbd4-00f5-47e4-9748-4179fe7a7a09&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2012%2f06%2f11%2fTunningKendoUI.aspx">Tunning
KendoUI</a>).</li>
          <li>
Templates and binding should support a context information along with the data source.
(Why do they use <code>with</code> statement?)</li>
          <li>
attr binding should use jquery.attr() method; there should be prop binding which is
analogous to attr binding.</li>
          <li>
There should be custom binding that allows any json object to bind to different aspects
of a widget or an element.</li>
          <li>
One should be able to use format/parse functions during binding. (Allow binding to
express as a triple json object?)</li>
          <li>
            <code>parseExact(value, format, culture)</code> method should be rewritten, as it
has nothing in common with parsing data string according to exact format.</li>
          <li>
Type inference during binding is poor (<code>parseOption()</code> method). It works
neither for string "1,2", nor json " { x: 0 } ", nor for date.</li>
          <li>
Binding is not implemented for many components: splitter, grid.</li>
          <li>
Splitter's pane should support size="auto".</li>
          <li>
Drid does not support totals in group headers, nor it supports header selection.</li>
          <li>
DataSource does not works after remote error, neither it allows to cancel request.</li>
          <li>
innerHtml is used all over the code, thus one cannot rely on jquery.data().</li>
          <li>
Grid does not support customization (localization) of a column filter.</li>
          <li>
Grid should support data binding of its content.</li>
          <li>
One should be able to destroy any widget.</li>
        </ul>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=1eeefbd4-00f5-47e4-9748-4179fe7a7a09" />
      </body>
      <title>Wish list for the Kendo UI</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,1eeefbd4-00f5-47e4-9748-4179fe7a7a09.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/06/17/WishListForTheKendoUI.aspx</link>
      <pubDate>Sun, 17 Jun 2012 20:03:37 GMT</pubDate>
      <description>  &lt;p&gt;
We&amp;#39;re pleased to work with Kendo UI. Its design is good, however we find here
and there things we would wish be done better. Here is a list of problems in a no
particular order we would like to be addressed in the next release:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
RTL is not supported (including correct scroll bar position see &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=1eeefbd4-00f5-47e4-9748-4179fe7a7a09&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2012%2f06%2f11%2fTunningKendoUI.aspx"&gt;Tunning
KendoUI&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
Templates and binding should support a context information along with the data source.
(Why do they use &lt;code&gt;with&lt;/code&gt; statement?)&lt;/li&gt;
&lt;li&gt;
attr binding should use jquery.attr() method; there should be prop binding which is
analogous to attr binding.&lt;/li&gt;
&lt;li&gt;
There should be custom binding that allows any json object to bind to different aspects
of a widget or an element.&lt;/li&gt;
&lt;li&gt;
One should be able to use format/parse functions during binding. (Allow binding to
express as a triple json object?)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;parseExact(value, format, culture)&lt;/code&gt; method should be rewritten, as it
has nothing in common with parsing data string according to exact format.&lt;/li&gt;
&lt;li&gt;
Type inference during binding is poor (&lt;code&gt;parseOption()&lt;/code&gt; method). It works
neither for string "1,2", nor json " { x: 0 } ", nor for date.&lt;/li&gt;
&lt;li&gt;
Binding is not implemented for many components: splitter, grid.&lt;/li&gt;
&lt;li&gt;
Splitter&amp;#39;s pane should support size=&amp;quot;auto&amp;quot;.&lt;/li&gt;
&lt;li&gt;
Drid does not support totals in group headers, nor it supports header selection.&lt;/li&gt;
&lt;li&gt;
DataSource does not works after remote error, neither it allows to cancel request.&lt;/li&gt;
&lt;li&gt;
innerHtml is used all over the code, thus one cannot rely on jquery.data().&lt;/li&gt;
&lt;li&gt;
Grid does not support customization (localization) of a column filter.&lt;/li&gt;
&lt;li&gt;
Grid should support data binding of its content.&lt;/li&gt;
&lt;li&gt;
One should be able to destroy any widget.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=1eeefbd4-00f5-47e4-9748-4179fe7a7a09" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,1eeefbd4-00f5-47e4-9748-4179fe7a7a09.aspx</comments>
      <category>javascript</category>
      <category>Thinking aloud</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=563d1d96-9bb4-4bcb-bf00-8702fa2139c2</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,563d1d96-9bb4-4bcb-bf00-8702fa2139c2.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,563d1d96-9bb4-4bcb-bf00-8702fa2139c2.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=563d1d96-9bb4-4bcb-bf00-8702fa2139c2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Trying to make KendoUI to work with Hebrew or more generally in RTL environment we
had to find a way to guess the position of scroll bar when direction is rtl.
</p>
        <p>
The problem exists due to the fact that some browsers (Chrome one of them) always
put scroll bars to the right. That's utterly wrong. Consider a label and a listbox:
</p>
        <table>
          <tr>
            <th>
Chrome 
</th>
            <th>
IE 
</th>
          </tr>
          <tr>
            <td>
              <img alt="List in chrome" style="border: 1px solid red" src="content/binary/list-in-chrome.png" />
            </td>
            <td>
              <img alt="List in chrome" style="border: 1px solid red" src="content/binary/list-in-ie.png" />
            </td>
          </tr>
        </table>
        <p>
You can see that the scroll bar appears between the label (on the right) and the data
in the list box (on the left) in Chrome, and on the left side of the list box in the
IE.
</p>
        <p>
We came up with the following test that calculates a scroll bar position in rtl mode:
</p>
        <p>
          <code>&lt;script type="text/javascript"&gt;<br />
var _scrollbar;<br /><br />
function scrollbar()<br />
{<br />
if (!_scrollbar)<br />
{<br />
var div = document.createElement("div");<br /><br />
div.style.cssText = "overflow:scroll;zoom:1;clear:both;direction:rtl";<br />
div.innerHTML = "&lt;div&gt;&amp;nbsp;&lt;/div&gt;";<br />
document.body.appendChild(div);<br /><br />
_scrollbar =<br />
{<br />
size: div.offsetWidth - div.scrollWidth,<br />
rtlPosition: div.offsetLeft &lt; div.firstChild.offsetLeft ? "left" : "right"<br />
};<br /><br />
document.body.removeChild(div);<br />
}<br /><br />
return _scrollbar;<br />
}<br />
&lt;/script&gt; </code>
        </p>
        <p>
In conjuction with an approach described in <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=563d1d96-9bb4-4bcb-bf00-8702fa2139c2&amp;url=http%3a%2f%2fstackoverflow.com%2fquestions%2f524696%2fhow-to-create-a-style-tag-with-javascript"> How
to create a &lt;style&gt; tag with Javascript</a> we were able to define rtl css classes
for kendo controls and in particular for the grid, combobox, dropdownlist, and datepicker.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=563d1d96-9bb4-4bcb-bf00-8702fa2139c2" />
      </body>
      <title>Tunning KendoUI</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,563d1d96-9bb4-4bcb-bf00-8702fa2139c2.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/06/11/TunningKendoUI.aspx</link>
      <pubDate>Mon, 11 Jun 2012 21:09:44 GMT</pubDate>
      <description>&lt;p&gt;
Trying to make KendoUI to work with Hebrew or more generally in RTL environment we
had to find a way to guess the position of scroll bar when direction is rtl.
&lt;/p&gt;
&lt;p&gt;
The problem exists due to the fact that some browsers (Chrome one of them) always
put scroll bars to the right. That&amp;#39;s utterly wrong. Consider a label and a listbox:
&lt;/p&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;
Chrome 
&lt;/th&gt;
&lt;th&gt;
IE 
&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;img alt="List in chrome" style="border: 1px solid red" src="content/binary/list-in-chrome.png" /&gt; 
&lt;/td&gt;
&lt;td&gt;
&lt;img alt="List in chrome" style="border: 1px solid red" src="content/binary/list-in-ie.png" /&gt; 
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;
You can see that the scroll bar appears between the label (on the right) and the data
in the list box (on the left) in Chrome, and on the left side of the list box in the
IE.
&lt;/p&gt;
&lt;p&gt;
We came up with the following test that calculates a scroll bar position in rtl mode:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;
var _scrollbar;&lt;br /&gt;
&lt;br /&gt;
function scrollbar()&lt;br /&gt;
{&lt;br /&gt;
if (!_scrollbar)&lt;br /&gt;
{&lt;br /&gt;
var div = document.createElement("div");&lt;br /&gt;
&lt;br /&gt;
div.style.cssText = "overflow:scroll;zoom:1;clear:both;direction:rtl";&lt;br /&gt;
div.innerHTML = "&amp;lt;div&amp;gt;&amp;amp;nbsp;&amp;lt;/div&amp;gt;";&lt;br /&gt;
document.body.appendChild(div);&lt;br /&gt;
&lt;br /&gt;
_scrollbar =&lt;br /&gt;
{&lt;br /&gt;
size: div.offsetWidth - div.scrollWidth,&lt;br /&gt;
rtlPosition: div.offsetLeft &amp;lt; div.firstChild.offsetLeft ? "left" : "right"&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
document.body.removeChild(div);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
return _scrollbar;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/script&amp;gt; &lt;/code&gt; 
&lt;/p&gt;
&lt;p&gt;
In conjuction with an approach described in &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=563d1d96-9bb4-4bcb-bf00-8702fa2139c2&amp;amp;url=http%3a%2f%2fstackoverflow.com%2fquestions%2f524696%2fhow-to-create-a-style-tag-with-javascript"&gt; How
to create a &amp;lt;style&amp;gt; tag with Javascript&lt;/a&gt; we were able to define rtl css classes
for kendo controls and in particular for the grid, combobox, dropdownlist, and datepicker.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=563d1d96-9bb4-4bcb-bf00-8702fa2139c2" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,563d1d96-9bb4-4bcb-bf00-8702fa2139c2.aspx</comments>
      <category>javascript</category>
      <category>Tips and tricks</category>
    </item>
  </channel>
</rss>