Changeset - 4cd0709b6d4b
[Not reviewed]
beta
0 6 0
Marcin Kuzminski - 15 years ago 2010-11-15 18:38:54
marcin@python-works.com
fixes #65, Added reset buttons to edit forms
6 files changed with 28 insertions and 8 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/helpers.py
Show inline comments
 
"""Helper functions
 

	
 
Consists of functions to typically be used within templates, but also
 
available to Controllers. This module is available to both as 'h'.
 
"""
 
from pygments.formatters import HtmlFormatter
 
from pygments import highlight as code_highlight
 
from pylons import url, app_globals as g
 
from pylons.i18n.translation import _, ungettext
 
from vcs.utils.annotate import annotate_highlight
 
from webhelpers.html import literal, HTML, escape
 
from webhelpers.html.tools import *
 
from webhelpers.html.builder import make_tag
 
from webhelpers.html.tags import auto_discovery_link, checkbox, css_classes, \
 
    end_form, file, form, hidden, image, javascript_link, link_to, link_to_if, \
 
    link_to_unless, ol, required_legend, select, stylesheet_link, submit, text, \
 
    password, textarea, title, ul, xml_declaration, radio
 
from webhelpers.html.tools import auto_link, button_to, highlight, js_obfuscate, \
 
    mail_to, strip_links, strip_tags, tag_re
 
from webhelpers.number import format_byte_size, format_bit_size
 
from webhelpers.pylonslib import Flash as _Flash
 
from webhelpers.pylonslib.secure_form import secure_form
 
from webhelpers.text import chop_at, collapse, convert_accented_entities, \
 
    convert_misc_entities, lchop, plural, rchop, remove_formatting, \
 
    replace_whitespace, urlify, truncate, wrap_paragraphs
 
from webhelpers.date import time_ago_in_words
 

	
 
from webhelpers.html.tags import _set_input_attrs, _set_id_attr, \
 
    convert_boolean_attrs, NotGiven
 

	
 
def _reset(name, value=None, id=NotGiven, type="reset", **attrs):
 
    _set_input_attrs(attrs, type, name, value)
 
    _set_id_attr(attrs, id, name)
 
    convert_boolean_attrs(attrs, ["disabled"])
 
    return HTML.input(**attrs)
 

	
 
reset = _reset
 

	
 
#Custom helpers here :)
 
class _Link(object):
 
    '''
 
    Make a url based on label and url with help of url_for
 
    :param label:name of link    if not defined url is used
 
    :param url: the url for link
 
    '''
 

	
 
    def __call__(self, label='', *url_, **urlargs):
 
        if label is None or '':
 
            label = url
 
        link_fn = link_to(label, url(*url_, **urlargs))
 
        return link_fn
 

	
 
link = _Link()
 

	
 
class _GetError(object):
 

	
 
    def __call__(self, field_name, form_errors):
 
        tmpl = """<span class="error_msg">%s</span>"""
 
        if form_errors and form_errors.has_key(field_name):
 
            return literal(tmpl % form_errors.get(field_name))
 

	
 
get_error = _GetError()
 

	
 
def recursive_replace(str, replace=' '):
 
    """
 
    Recursive replace of given sign to just one instance
 
    :param str: given string
 
    :param replace:char to find and replace multiple instances
 
        
 
    Examples::
 
    >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-')
 
    'Mighty-Mighty-Bo-sstones'
 
    """
 

	
 
    if str.find(replace * 2) == -1:
 
        return str
 
    else:
 
        str = str.replace(replace * 2, replace)
 
        return recursive_replace(str, replace)
 

	
 
class _ToolTip(object):
 

	
 
    def __call__(self, tooltip_title, trim_at=50):
 
        """
 
        Special function just to wrap our text into nice formatted autowrapped
 
        text
rhodecode/templates/admin/repos/repo_edit.html
Show inline comments
 
@@ -104,97 +104,98 @@
 
                                <td>${h.radio('perm_%s' % r2p.user.username,'repository.read')}</td>
 
                                <td>${h.radio('perm_%s' % r2p.user.username,'repository.write')}</td>
 
                                <td>${h.radio('perm_%s' % r2p.user.username,'repository.admin')}</td>
 
                                <td>${r2p.user.username}</td>
 
                                <td>
 
                                  %if r2p.user.username !='default':
 
                                    <span class="delete_icon action_button" onclick="ajaxAction(${r2p.user.user_id},'${'id%s'%id(r2p.user.username)}')">
 
                                        <script type="text/javascript">
 
                                            function ajaxAction(user_id,field_id){
 
                                                var sUrl = "${h.url('delete_repo_user',repo_name=c.repo_name)}";
 
                                                var callback = { success:function(o){
 
                                                var tr = YAHOO.util.Dom.get(String(field_id));
 
                                                tr.parentNode.removeChild(tr);},failure:function(o){
 
                                                    alert("${_('Failed to remove user')}");},};
 
                                                var postData = '_method=delete&user_id='+user_id; 
 
                                                var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);};
 
                                        </script>           
 
                                    </span>
 
                                  %endif                    
 
                                </td>
 
                            </tr>
 
                            %endif
 
                        %endfor
 

	
 
                        <tr id="add_perm_input">
 
                            <td>${h.radio('perm_new_user','repository.none')}</td>
 
                            <td>${h.radio('perm_new_user','repository.read')}</td>
 
                            <td>${h.radio('perm_new_user','repository.write')}</td>
 
                            <td>${h.radio('perm_new_user','repository.admin')}</td>
 
                            <td class='ac'>
 
                                <div class="perm_ac" id="perm_ac">
 
                                    ${h.text('perm_new_user_name',class_='yui-ac-input')}
 
                                    <div id="perm_container"></div>
 
                                </div>
 
                            </td>
 
                            <td></td>
 
                        </tr>
 
                        <tr>
 
                            <td colspan="6">
 
                                <span id="add_perm" class="add_icon" style="cursor: pointer;">
 
                                ${_('Add another user')}
 
                                </span>
 
                            </td>
 
                        </tr>
 
                    </table>             
 
             </div>
 
             
 
            <div class="buttons">
 
              ${h.submit('save','save',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
              ${h.submit('save','Save',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
              ${h.reset('reset','Reset',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
            </div>                                                          
 
        </div>
 
    </div>
 
    </div>    
 
    ${h.end_form()}
 
        <script type="text/javascript">
 
            YAHOO.util.Event.onDOMReady(function(){
 
                var D = YAHOO.util.Dom;
 
                if(!D.hasClass('perm_new_user_name','error')){
 
                    D.setStyle('add_perm_input','display','none');
 
                }
 
                YAHOO.util.Event.addListener('add_perm','click',function(){
 
                    D.setStyle('add_perm_input','display','');
 
                    D.setStyle('add_perm','opacity','0.6');
 
                    D.setStyle('add_perm','cursor','default');
 
                });
 
            });
 
        </script>
 
        <script type="text/javascript">    
 
        YAHOO.example.FnMultipleFields = function(){
 
            var myContacts = ${c.users_array|n}
 
            
 
            // Define a custom search function for the DataSource
 
            var matchNames = function(sQuery) {
 
                // Case insensitive matching
 
                var query = sQuery.toLowerCase(),
 
                    contact,
 
                    i=0,
 
                    l=myContacts.length,
 
                    matches = [];
 
                
 
                // Match against each name of each contact
 
                for(; i<l; i++) {
 
                    contact = myContacts[i];
 
                    if((contact.fname.toLowerCase().indexOf(query) > -1) ||
 
                        (contact.lname.toLowerCase().indexOf(query) > -1) ||
 
                        (contact.nname && (contact.nname.toLowerCase().indexOf(query) > -1))) {
 
                        matches[matches.length] = contact;
 
                    }
 
                }
 
        
 
                return matches;
 
            };
 
        
 
            // Use a FunctionDataSource
 
            var oDS = new YAHOO.util.FunctionDataSource(matchNames);
 
            oDS.responseSchema = {
 
                fields: ["id", "fname", "lname", "nname"]
rhodecode/templates/admin/settings/settings.html
Show inline comments
 
## -*- coding: utf-8 -*-
 
<%inherit file="/base/base.html"/>
 

	
 
<%def name="title()">
 
    ${_('Settings administration')} - ${c.rhodecode_name}
 
</%def>
 

	
 
<%def name="breadcrumbs_links()">
 
    ${h.link_to(_('Admin'),h.url('admin_home'))} &raquo; ${_('Settings')}
 
</%def>
 

	
 
<%def name="page_nav()">
 
	${self.menu('admin')}
 
</%def>
 

	
 
<%def name="main()">
 
<div class="box">
 
    <!-- box / title -->
 
    <div class="title">
 
        ${self.breadcrumbs()}       
 
    </div>
 
    <!-- end box / title -->
 
    
 
    <h3>${_('Remap and rescan repositories')}</h3>
 
    ${h.form(url('admin_setting', setting_id='mapping'),method='put')}
 
    <div class="form">
 
        <!-- fields -->
 
        
 
        <div class="fields">
 
			<div class="field">
 
		        <div class="label label-checkbox">
 
		            <label for="destroy">${_('rescan option')}:</label>
 
		        </div>
 
		        <div class="checkboxes">
 
		            <div class="checkbox">
 
		                ${h.checkbox('destroy',True)}
 
		                <label for="checkbox-1">
 
		                <span class="tooltip" tooltip_title="${h.tooltip(_('In case a repository was deleted from filesystem and there are leftovers in the database check this option to scan obsolete data in database and remove it.'))}">
 
		                ${_('destroy old data')}</span> </label>
 
		            </div>
 
		        </div>
 
			</div>
 
                            
 
            <div class="buttons">
 
            ${h.submit('rescan','rescan repositories',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
            ${h.submit('rescan','Rescan repositories',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
            </div>                                                          
 
        </div>
 
    </div>  
 
    ${h.end_form()}
 
    
 
    <h3>${_('Whoosh indexing')}</h3>
 
    ${h.form(url('admin_setting', setting_id='whoosh'),method='put')}
 
    <div class="form">
 
        <!-- fields -->
 
        
 
        <div class="fields">
 
            <div class="field">
 
                <div class="label label-checkbox">
 
                    <label for="destroy">${_('index build option')}:</label>
 
                </div>
 
                <div class="checkboxes">
 
                    <div class="checkbox">
 
                        ${h.checkbox('full_index',True)}
 
                        <label for="checkbox-1">${_('build from scratch')}</label>
 
                    </div>
 
                </div>
 
            </div>
 
                            
 
            <div class="buttons">
 
            ${h.submit('reindex','reindex',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
            ${h.submit('reindex','Reindex',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
            </div>                                                          
 
        </div>
 
    </div>  
 
    ${h.end_form()}
 
         
 
    <h3>${_('Global application settings')}</h3> 
 
    ${h.form(url('admin_setting', setting_id='global'),method='put')}
 
    <div class="form">
 
        <!-- fields -->
 
        
 
        <div class="fields">
 
             
 
             <div class="field">
 
                <div class="label">
 
                    <label for="rhodecode_title">${_('Application name')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.text('rhodecode_title',size=30)}
 
                </div>
 
             </div>
 
                          
 
            <div class="field">
 
                <div class="label">
 
                    <label for="rhodecode_realm">${_('Realm text')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.text('rhodecode_realm',size=30)}
 
                </div>
 
            </div>
 
                                     
 
            <div class="buttons">
 
                ${h.submit('save','save settings',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
                ${h.submit('save','Save settings',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
                ${h.reset('reset','Reset',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
           </div>                                                          
 
        </div>
 
    </div>      
 
    ${h.end_form()}
 

	
 
    <h3>${_('Mercurial settings')}</h3> 
 
    ${h.form(url('admin_setting', setting_id='mercurial'),method='put')}
 
    <div class="form">
 
        <!-- fields -->
 
        
 
        <div class="fields">
 
             
 
             <div class="field">
 
                <div class="label label-checkbox">
 
                    <label for="web_push_ssl">${_('Web')}:</label>
 
                </div>
 
                <div class="checkboxes">
 
					<div class="checkbox">
 
						${h.checkbox('web_push_ssl','true')}
 
						<label for="web_push_ssl">${_('require ssl for pushing')}</label>
 
					</div>
 
				</div>
 
             </div>						
 

	
 
             <div class="field">
 
                <div class="label label-checkbox">
 
                    <label for="web_push_ssl">${_('Hooks')}:</label>
 
                </div>
 
                <div class="checkboxes">
 
					<div class="checkbox">
 
						${h.checkbox('hooks_changegroup_update','True')}
 
						<label for="hooks_changegroup_update">${_('Update repository after push (hg update)')}</label>
 
					</div>
 
					<div class="checkbox">
 
						${h.checkbox('hooks_changegroup_repo_size','True')}
 
						<label for="hooks_changegroup_repo_size">${_('Show repository size after push')}</label>
 
					</div>
 
                    <div class="checkbox">
 
                        ${h.checkbox('hooks_pretxnchangegroup_push_logger','True')}
 
                        <label for="hooks_pretxnchangegroup_push_logger">${_('Log user push commands')}</label>
 
                    </div>
 
                    <div class="checkbox">
 
                        ${h.checkbox('hooks_preoutgoing_pull_logger','True')}
 
                        <label for="hooks_preoutgoing_pull_logger">${_('Log user pull commands')}</label>
 
                    </div>                    										
 
				</div>
 
             </div>	
 
							                          
 
            <div class="field">
 
                <div class="label">
 
                    <label for="paths_root_path">${_('Repositories location')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.text('paths_root_path',size=30,readonly="readonly")}			                    
 
					<span id="path_unlock" class="tooltip" 
 
						tooltip_title="${h.tooltip(_('This a crucial application setting. If You really sure you need to change this, you must restart application in order to make this settings take effect. Click this label to unlock.'))}">
 
		                ${_('unlock')}</span>
 
                </div>
 
            </div>
 
                                     
 
            <div class="buttons">
 
                ${h.submit('save','save settings',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
                ${h.submit('save','Save settings',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
                ${h.reset('reset','Reset',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
           </div>                                                          
 
        </div>
 
    </div>      
 
    ${h.end_form()}
 
    
 
    <script type="text/javascript">
 
        YAHOO.util.Event.onDOMReady(function(){
 
            YAHOO.util.Event.addListener('path_unlock','click',function(){
 
                YAHOO.util.Dom.get('paths_root_path').removeAttribute('readonly');
 
            });
 
        });
 
    </script>
 
</div>
 
</%def>    
rhodecode/templates/admin/users/user_edit.html
Show inline comments
 
@@ -56,55 +56,56 @@
 
                </div>
 
             </div>
 
            
 
             <div class="field">
 
                <div class="label">
 
                    <label for="name">${_('First Name')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.text('name',class_='small')}
 
                </div>
 
             </div>
 
            
 
             <div class="field">
 
                <div class="label">
 
                    <label for="lastname">${_('Last Name')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.text('lastname',class_='small')}
 
                </div>
 
             </div>
 
            
 
             <div class="field">
 
                <div class="label">
 
                    <label for="email">${_('Email')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.text('email',class_='small')}
 
                </div>
 
             </div>
 
            
 
             <div class="field">
 
                <div class="label label-checkbox">
 
                    <label for="active">${_('Active')}:</label>
 
                </div>
 
                <div class="checkboxes">
 
                    ${h.checkbox('active',value=True)}
 
                </div>
 
             </div>
 
             
 
             <div class="field">
 
                <div class="label label-checkbox">
 
                    <label for="admin">${_('Admin')}:</label>
 
                </div>
 
                <div class="checkboxes">
 
                    ${h.checkbox('admin',value=True)}
 
                </div>
 
             </div>             
 
            <div class="buttons">
 
              ${h.submit('save','save',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
              ${h.submit('save','Save',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
              ${h.reset('reset','Reset',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
            </div>             
 
    	</div>    
 
    </div>
 
    ${h.end_form()}
 
</div>    
 
</%def>  
 
\ No newline at end of file
rhodecode/templates/admin/users/user_edit_my_account.html
Show inline comments
 
@@ -26,97 +26,101 @@
 
	    <div class="form">
 
	        <div class="fields">
 
	             <div class="field">
 
	                <div class="label">
 
	                    <label for="username">${_('Username')}:</label>
 
	                </div>
 
	                <div class="input">
 
	                    ${h.text('username')}
 
	                </div>
 
	             </div>
 
	            
 
	             <div class="field">
 
	                <div class="label">
 
	                    <label for="new_password">${_('New password')}:</label>
 
	                </div>
 
	                <div class="input">
 
	                    ${h.password('new_password')}
 
	                </div>
 
	             </div>
 
	            
 
	             <div class="field">
 
	                <div class="label">
 
	                    <label for="name">${_('First Name')}:</label>
 
	                </div>
 
	                <div class="input">
 
	                    ${h.text('name')}
 
	                </div>
 
	             </div>
 
	            
 
	             <div class="field">
 
	                <div class="label">
 
	                    <label for="lastname">${_('Last Name')}:</label>
 
	                </div>
 
	                <div class="input">
 
	                    ${h.text('lastname')}
 
	                </div>
 
	             </div>
 
	            
 
	             <div class="field">
 
	                <div class="label">
 
	                    <label for="email">${_('Email')}:</label>
 
	                </div>
 
	                <div class="input">
 
	                    ${h.text('email')}
 
	                </div>
 
	             </div>
 
	            
 
	            <div class="buttons">
 
	              ${h.submit('save','save',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
	              ${h.submit('save','Save',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
	              ${h.reset('reset','Reset',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
	              
 
	              
 
	              
 
	            </div>             
 
	    	</div>
 
	    </div>    	
 
    ${h.end_form()}
 
    </div>
 
</div>    
 

	
 
<div class="box box-right">
 
    <!-- box / title -->
 
    <div class="title">
 
        <h5>${_('My repositories')}
 
        <input class="top-right-rounded-corner top-left-rounded-corner bottom-left-rounded-corner bottom-right-rounded-corner" id="q_filter" size="15" type="text" name="filter" value="${_('quick filter...')}"/>
 
        </h5>   
 
    </div>
 
    <!-- end box / title -->
 
    <div class="table">
 
	    <table>
 
	    <thead>
 
            <tr>
 
            <th class="left">${_('Name')}</th>
 
            <th class="left">${_('revision')}</th>
 
            <th colspan="2" class="left">${_('action')}</th>            
 
	    </thead>
 
	     <tbody>
 
	     %if c.user_repos:
 
		     %for repo in c.user_repos:
 
		        <tr>
 
		            <td>
 
                     %if repo['repo'].dbrepo.repo_type =='hg':
 
                       <img class="icon" title="${_('Mercurial repository')}" alt="${_('Mercurial repository')}" src="/images/icons/hgicon.png"/>
 
                     %elif repo['repo'].dbrepo.repo_type =='git':
 
                       <img class="icon" title="${_('Git repository')}" alt="${_('Git repository')}" src="/images/icons/giticon.png"/>
 
                     %else:
 
                       
 
                     %endif 		            
 
		             %if repo['repo'].dbrepo.private:
 
		                <img class="icon" alt="${_('private')}" src="/images/icons/lock.png"/>
 
		             %else:
 
		                <img class="icon" alt="${_('public')}" src="/images/icons/lock_open.png"/>
 
		             %endif
 
		                                             
 
		            ${h.link_to(repo['repo'].name, h.url('summary_home',repo_name=repo['repo'].name),class_="repo_name")}
 
		            %if repo['repo'].dbrepo.fork:
 
		            	<a href="${h.url('summary_home',repo_name=repo['repo'].dbrepo.fork.repo_name)}">
 
		            	<img class="icon" alt="${_('public')}"
 
		            	title="${_('Fork of')} ${repo['repo'].dbrepo.fork.repo_name}" 
 
		            	src="/images/icons/arrow_divide.png"/></a>
 
		            %endif		            
rhodecode/templates/settings/repo_settings.html
Show inline comments
 
@@ -83,97 +83,98 @@
 
                                <td>${h.radio('perm_%s' % r2p.user.username,'repository.write')}</td>
 
                                <td>${h.radio('perm_%s' % r2p.user.username,'repository.admin')}</td>
 
                                <td>${r2p.user.username}</td>
 
                                <td>
 
                                  %if r2p.user.username !='default':
 
                                    <span class="delete_icon action_button" onclick="ajaxAction(${r2p.user.user_id},'${'id%s'%id(r2p.user.username)}')">
 
                                        <script type="text/javascript">
 
                                            function ajaxAction(user_id,field_id){
 
                                                var sUrl = "${h.url('delete_repo_user',repo_name=c.repo_name)}";
 
                                                var callback = { success:function(o){
 
                                                var tr = YAHOO.util.Dom.get(String(field_id));
 
                                                tr.parentNode.removeChild(tr);},failure:function(o){
 
                                                	alert("${_('Failed to remove user')}");},};
 
                                                var postData = '_method=delete&user_id='+user_id; 
 
                                                var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);};
 
                                        </script>           
 
                                    </span>
 
                                  %endif                    
 
                                </td>
 
                            </tr>
 
                            %endif
 
                        %endfor
 

	
 

	
 
                        <tr id="add_perm_input">
 
                            <td>${h.radio('perm_new_user','repository.none')}</td>
 
                            <td>${h.radio('perm_new_user','repository.read')}</td>
 
                            <td>${h.radio('perm_new_user','repository.write')}</td>
 
                            <td>${h.radio('perm_new_user','repository.admin')}</td>
 
                            <td class='ac'>
 
                                <div class="perm_ac" id="perm_ac">
 
                                    ${h.text('perm_new_user_name',class_='yui-ac-input')}
 
                                    <div id="perm_container"></div>
 
                                </div>
 
                            </td>
 
                            <td></td>
 
                        </tr>
 
                        <tr>
 
                            <td colspan="6">
 
                                <span id="add_perm" class="add_icon" style="cursor: pointer;">
 
                                ${_('Add another user')}
 
                                </span>
 
                            </td>
 
                        </tr>
 
                    </table>             
 
             </div>
 
             
 
            <div class="buttons">
 
              ${h.submit('update','update',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
              ${h.submit('update','Update',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
              ${h.reset('reset','Reset',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
            </div>                                                          
 
        </div>
 
    </div>    
 
    ${h.end_form()}
 
        <script type="text/javascript">
 
            YAHOO.util.Event.onDOMReady(function(){
 
                var D = YAHOO.util.Dom;
 
                if(!D.hasClass('perm_new_user_name','error')){
 
                    D.setStyle('add_perm_input','display','none');
 
                }
 
                YAHOO.util.Event.addListener('add_perm','click',function(){
 
                    D.setStyle('add_perm_input','display','');
 
                    D.setStyle('add_perm','opacity','0.6');
 
                    D.setStyle('add_perm','cursor','default');
 
                });
 
            });
 
        </script>
 
        <script type="text/javascript">    
 
        YAHOO.example.FnMultipleFields = function(){
 
            var myContacts = ${c.users_array|n}
 
            
 
            // Define a custom search function for the DataSource
 
            var matchNames = function(sQuery) {
 
                // Case insensitive matching
 
                var query = sQuery.toLowerCase(),
 
                    contact,
 
                    i=0,
 
                    l=myContacts.length,
 
                    matches = [];
 
                
 
                // Match against each name of each contact
 
                for(; i<l; i++) {
 
                    contact = myContacts[i];
 
                    if((contact.fname.toLowerCase().indexOf(query) > -1) ||
 
                        (contact.lname.toLowerCase().indexOf(query) > -1) ||
 
                        (contact.nname && (contact.nname.toLowerCase().indexOf(query) > -1))) {
 
                        matches[matches.length] = contact;
 
                    }
 
                }
 
        
 
                return matches;
 
            };
 
        
 
            // Use a FunctionDataSource
 
            var oDS = new YAHOO.util.FunctionDataSource(matchNames);
 
            oDS.responseSchema = {
 
                fields: ["id", "fname", "lname", "nname"]
 
            }
0 comments (0 inline, 0 general)