From: Mike S. <ms...@us...> - 2006-11-28 22:14:53
|
Update of /cvsroot/wonder/Wonder/Ajax/Ajax/Sources/er/ajax In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv29264/Sources/er/ajax Modified Files: FocusTextField.java FocusText.java Log Message: added onEnter binding to FocusText and FocusTextField Index: FocusTextField.java =================================================================== RCS file: /cvsroot/wonder/Wonder/Ajax/Ajax/Sources/er/ajax/FocusTextField.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FocusTextField.java 6 Nov 2006 03:05:18 -0000 1.3 --- FocusTextField.java 28 Nov 2006 22:14:49 -0000 1.4 *************** *** 20,23 **** --- 20,24 ---- * @binding selectAll if true, the text will default to be selected * @binding focus if false, focus will not be grabbed + * @binding onEnter javascript to execute when the enter key is pressed */ public class FocusTextField extends ERXWOTextField { *************** *** 25,28 **** --- 26,31 ---- protected WOAssociation _selectAll; protected WOAssociation _focus; + protected WOAssociation _onEnter; + protected WOAssociation _onKeyPress; public FocusTextField(String tagname, NSDictionary nsdictionary, WOElement woelement) { *************** *** 33,38 **** --- 36,44 ---- throw new WODynamicElementCreationException("<" + getClass().getName() + "> id is a required binding."); } + //_associations.setObjectForKey(_id, ") _selectAll = (WOAssociation) _associations.removeObjectForKey("selectAll"); _focus = (WOAssociation) _associations.removeObjectForKey("focus"); + _onEnter = (WOAssociation) _associations.removeObjectForKey("onEnter"); + _onKeyPress = (WOAssociation) _associations.removeObjectForKey("onkeypress"); } *************** *** 44,60 **** WOComponent component = context.component(); boolean focus = (_focus == null || _focus.booleanValueInComponent(component)); ! if (focus) { ! String id = (String) _id.valueInComponent(component); ! boolean selectAll = (_selectAll != null && _selectAll.booleanValueInComponent(component)); ! FocusTextField.appendFocusAndSelectToResponse(response, context, id, selectAll); ! } } ! public static void appendFocusAndSelectToResponse(WOResponse response, WOContext context, String id, boolean selectAll) { WOComponent component = context.component(); AjaxUtils.appendScriptHeader(response); ! response.appendContentString("$('" + id + "').focus();"); if (selectAll) { ! response.appendContentString("$('" + id + "').select();"); } AjaxUtils.appendScriptFooter(response); --- 50,98 ---- WOComponent component = context.component(); boolean focus = (_focus == null || _focus.booleanValueInComponent(component)); ! boolean selectAll = (_selectAll != null && _selectAll.booleanValueInComponent(component)); ! String id = (String) _id.valueInComponent(component); ! String onEnterScript = (_onEnter != null) ? (String)_onEnter.valueInComponent(component) : null; ! FocusTextField.appendJavascriptToResponse(response, context, id, focus, selectAll, onEnterScript); } ! protected void _appendAttributesFromAssociationsToResponse(WOResponse response, WOContext wocontext, NSDictionary nsdictionary) { ! super._appendAttributesFromAssociationsToResponse(response, wocontext, nsdictionary); ! WOComponent component = wocontext.component(); ! String onKeyPress = (_onKeyPress != null) ? (String) _onKeyPress.valueInComponent(component) : null; ! String onEnterScript = (_onEnter != null) ? (String) _onEnter.valueInComponent(component) : null; ! String id = (String) _id.valueInComponent(component); ! FocusTextField._appendAttributesFromAssociationsToResponse(response, wocontext, id, onKeyPress, onEnterScript); ! } ! ! public static void _appendAttributesFromAssociationsToResponse(WOResponse response, WOContext wocontext, String id, String onKeyPress, String onEnterScript) { ! WOComponent component = wocontext.component(); ! if (onKeyPress != null || onEnterScript != null) { ! response.appendContentString(" onkeypress = \""); ! if (onKeyPress != null) { ! response.appendContentString(onKeyPress); ! } ! if (onEnterScript != null) { ! if (onKeyPress != null) { ! response.appendContentString("; "); ! } ! response.appendContentString(id + "SubmitOnEnter(event);"); ! } ! response.appendContentString("\""); ! } ! } ! ! public static void appendJavascriptToResponse(WOResponse response, WOContext context, String id, boolean focus, boolean selectAll, String onEnterScript) { WOComponent component = context.component(); AjaxUtils.appendScriptHeader(response); ! if (focus) { ! response.appendContentString("Field.focus('" + id + "');"); ! } if (selectAll) { ! response.appendContentString("Field.select('" + id + "');"); ! } ! if (onEnterScript != null) { ! response.appendContentString(id + "SubmitOnEnter = function(e) { if (e.which == 13 || e.which == 3) { "); ! response.appendContentString(onEnterScript); ! response.appendContentString("; Event.stop(e); } }"); } AjaxUtils.appendScriptFooter(response); Index: FocusText.java =================================================================== RCS file: /cvsroot/wonder/Wonder/Ajax/Ajax/Sources/er/ajax/FocusText.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FocusText.java 6 Nov 2006 03:05:18 -0000 1.3 --- FocusText.java 28 Nov 2006 22:14:49 -0000 1.4 *************** *** 12,17 **** /** ! * Focus text is a convenience version of ERXWOText that provides ! * support for grabbing default focus via javascript. * * @author mschrag --- 12,16 ---- /** ! * Focus text is a convenience version of ERXWOText that provides support for grabbing default focus via javascript. * * @author mschrag *************** *** 20,28 **** * @binding selectAll if true, the text will default to be selected * @binding focus if false, focus will not be grabbed */ public class FocusText extends ERXWOText { protected WOAssociation _selectAll; protected WOAssociation _focus; ! public FocusText(String tagname, NSDictionary nsdictionary, WOElement woelement) { super(tagname, nsdictionary, woelement); --- 19,30 ---- * @binding selectAll if true, the text will default to be selected * @binding focus if false, focus will not be grabbed + * @binding onEnter javascript to execute when the enter key is pressed */ public class FocusText extends ERXWOText { protected WOAssociation _selectAll; protected WOAssociation _focus; ! protected WOAssociation _onEnter; ! protected WOAssociation _onKeyPress; ! public FocusText(String tagname, NSDictionary nsdictionary, WOElement woelement) { super(tagname, nsdictionary, woelement); *************** *** 33,36 **** --- 35,49 ---- _selectAll = (WOAssociation) _associations.removeObjectForKey("selectAll"); _focus = (WOAssociation) _associations.removeObjectForKey("focus"); + _onEnter = (WOAssociation) _associations.removeObjectForKey("onEnter"); + _onKeyPress = (WOAssociation) _associations.removeObjectForKey("onkeypress"); + } + + protected void _appendAttributesFromAssociationsToResponse(WOResponse woresponse, WOContext wocontext, NSDictionary nsdictionary) { + super._appendAttributesFromAssociationsToResponse(woresponse, wocontext, nsdictionary); + WOComponent component = wocontext.component(); + String onKeyPress = (_onKeyPress != null) ? (String) _onKeyPress.valueInComponent(component) : null; + String onEnterScript = (_onEnter != null) ? (String) _onEnter.valueInComponent(component) : null; + String id = (String) _id.valueInComponent(component); + FocusTextField._appendAttributesFromAssociationsToResponse(woresponse, wocontext, id, onKeyPress, onEnterScript); } *************** *** 42,50 **** WOComponent component = context.component(); boolean focus = (_focus == null || _focus.booleanValueInComponent(component)); ! if (focus) { ! String id = (String) _id.valueInComponent(component); ! boolean selectAll = (_selectAll != null && _selectAll.booleanValueInComponent(component)); ! FocusTextField.appendFocusAndSelectToResponse(response, context, id, selectAll); ! } } } --- 55,62 ---- WOComponent component = context.component(); boolean focus = (_focus == null || _focus.booleanValueInComponent(component)); ! String id = (String) _id.valueInComponent(component); ! boolean selectAll = (_selectAll != null && _selectAll.booleanValueInComponent(component)); ! String onEnterScript = (_onEnter != null) ? (String) _onEnter.valueInComponent(component) : null; ! FocusTextField.appendJavascriptToResponse(response, context, id, focus, selectAll, onEnterScript); } } |