You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2012/07/20 23:42:40 UTC
svn commit: r1363960 [2/2] - in /myfaces/tobago/trunk: tobago-core/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/
tobago-core/src/main/java/org/apa...
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java?rev=1363960&r1=1363959&r2=1363960&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java Fri Jul 20 21:42:39 2012
@@ -17,20 +17,26 @@ package org.apache.myfaces.tobago.render
* limitations under the License.
*/
+import com.google.gson.Gson;
import org.apache.commons.lang.StringUtils;
import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.component.Facets;
import org.apache.myfaces.tobago.component.SupportsMarkup;
import org.apache.myfaces.tobago.component.SupportsRenderedPartially;
+import org.apache.myfaces.tobago.component.UIColumnEvent;
import org.apache.myfaces.tobago.component.UICommand;
+import org.apache.myfaces.tobago.component.UIForm;
import org.apache.myfaces.tobago.component.UIPage;
import org.apache.myfaces.tobago.component.UISheet;
import org.apache.myfaces.tobago.context.Markup;
import org.apache.myfaces.tobago.context.ResourceManagerUtils;
+import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
import org.apache.myfaces.tobago.internal.util.Deprecation;
import org.apache.myfaces.tobago.internal.util.FacesContextUtils;
import org.apache.myfaces.tobago.internal.webapp.TobagoResponseWriterWrapper;
import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
import org.apache.myfaces.tobago.renderkit.css.Classes;
+import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
import org.apache.myfaces.tobago.renderkit.html.StyleClasses;
@@ -50,6 +56,7 @@ import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;
import java.io.IOException;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -58,6 +65,7 @@ public final class HtmlRendererUtils {
private static final Logger LOG = LoggerFactory.getLogger(HtmlRendererUtils.class);
private static final String ERROR_FOCUS_KEY = HtmlRendererUtils.class.getName() + ".ErrorFocusId";
+ private static final String FOCUS_KEY = HtmlRendererUtils.class.getName() + ".FocusId";
private HtmlRendererUtils() {
// to prevent instantiation
@@ -78,6 +86,16 @@ public final class HtmlRendererUtils {
return FacesContext.getCurrentInstance().getExternalContext().getRequestMap().containsKey(ERROR_FOCUS_KEY);
}
+ public static void renderFocus(String clientId, boolean focus, boolean error, FacesContext facesContext,
+ TobagoResponseWriter writer) throws IOException {
+ final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
+ if (!requestMap.containsKey(FOCUS_KEY)
+ && (clientId.equals(FacesContextUtils.getFocusId(facesContext)) || focus || error)) {
+ requestMap.put(FOCUS_KEY, Boolean.TRUE);
+ writer.writeAttribute(HtmlAttributes.AUTOFOCUS, true);
+ }
+ }
+
public static void renderFocusId(final FacesContext facesContext, final UIComponent component)
throws IOException {
if (component instanceof UIInput) {
@@ -141,20 +159,20 @@ public final class HtmlRendererUtils {
public static void addClickAcceleratorKey(
FacesContext facesContext, String clientId, char key)
throws IOException {
- addClickAcceleratorKey(facesContext, clientId, key, null);
+ //addClickAcceleratorKey(facesContext, clientId, key, null);
}
public static void addClickAcceleratorKey(
FacesContext facesContext, String clientId, char key, String modifier)
throws IOException {
- String str
- = createOnclickAcceleratorKeyJsStatement(clientId, key, modifier);
- writeScriptLoader(facesContext, null, new String[]{str});
+ //String str
+ // = createOnclickAcceleratorKeyJsStatement(clientId, key, modifier);
+ //writeScriptLoader(facesContext, null, new String[]{str});
}
public static void addAcceleratorKey(
FacesContext facesContext, String func, char key) throws IOException {
- addAcceleratorKey(facesContext, func, key, null);
+ //addAcceleratorKey(facesContext, func, key, null);
}
public static void addAcceleratorKey(
@@ -236,14 +254,14 @@ public final class HtmlRendererUtils {
if (scripts != null) {
LOG.error("Scripts argument for writeScriptLoader not supported anymore!");
}
- /*String allScripts = "[]";
+ String allScripts = "[]";
if (scripts != null) {
allScripts = ResourceManagerUtils.getScriptsAsJSArray(facesContext, scripts);
}
- boolean ajax = FacesContextUtils.isAjax(facesContext);*/
+ boolean ajax = FacesContextUtils.isAjax(facesContext);
writer.startJavascript();
- /* XXX fix me if scripts != null
- if (scripts != null) {
+ // XXX fix me if scripts != null
+ if (ajax || scripts != null) {
writer.write("new Tobago.ScriptLoader(");
if (!ajax) {
writer.write("\n ");
@@ -273,11 +291,11 @@ public final class HtmlRendererUtils {
}
}
writer.write(");");
- } else {*/
+ } else {
for (String afterLoadCmd : afterLoadCmds) {
writer.write(afterLoadCmd);
}
- //}
+ }
writer.endJavascript();
}
@@ -588,13 +606,75 @@ public final class HtmlRendererUtils {
return strBuilder.toString();
}
+
+ public static void renderCommandFacet(UIComponent component, FacesContext facesContext,
+ TobagoResponseWriter writer) throws IOException {
+ renderCommandFacet(component, component.getClientId(facesContext), facesContext, writer);
+ }
+
+ public static void renderCommandFacet(UIComponent component, String id, FacesContext facesContext,
+ TobagoResponseWriter writer) throws IOException {
+ if (ComponentUtils.getBooleanAttribute(component, Attributes.READONLY)
+ || ComponentUtils.getBooleanAttribute(component, Attributes.DISABLED)) {
+ return;
+ }
+ Map<String, Command> commandMap = null;
+ Map<String, UIComponent> facets = component.getFacets();
+ for (Map.Entry<String, UIComponent> entry : facets.entrySet()) {
+ UIComponent facetComponent = entry.getValue();
+ if (facetComponent.isRendered()
+ && (facetComponent instanceof AbstractUICommand || facetComponent instanceof UIForm)) {
+ if (commandMap == null) {
+ commandMap = new HashMap<String, Command>();
+ }
+ String key = entry.getKey();
+ if (Facets.RESIZE_ACTION.equals(key)) {
+ key = Facets.RESIZE;
+ }
+ commandMap.put(key, getCommandFacet(entry.getValue(), id, facesContext));
+ }
+ }
+ if (commandMap != null) {
+
+ Gson gson = new Gson();
+ writer.writeAttribute(DataAttributes.ACTION, gson.toJson(commandMap), null);
+ }
+ }
+
+ public static boolean renderSheetCommands(UISheet sheet, FacesContext facesContext,
+ TobagoResponseWriter writer) throws IOException {
+ Map<String, Command> commandMap = null;
+ for (UIComponent child : (List<UIComponent>) sheet.getChildren()) {
+ if (child instanceof UIColumnEvent) {
+ UIColumnEvent columnEvent = (UIColumnEvent) child;
+ if (columnEvent.isRendered()) {
+ UIComponent selectionChild = (UIComponent) child.getChildren().get(0);
+ if (selectionChild != null && selectionChild instanceof AbstractUICommand && selectionChild.isRendered()) {
+ UICommand action = (UICommand) selectionChild;
+ if (commandMap == null) {
+ commandMap = new HashMap<String, Command>();
+ }
+ commandMap.put(columnEvent.getEvent(), getCommandFacet(action, null, facesContext));
+ }
+ }
+ }
+ }
+ if (commandMap != null) {
+ Gson gson = new Gson();
+ writer.writeAttribute(DataAttributes.ROWACTION, gson.toJson(commandMap), null);
+ return true;
+ }
+ return false;
+ }
+
+
public static void checkForCommandFacet(UIComponent component, FacesContext facesContext, TobagoResponseWriter writer)
throws IOException {
checkForCommandFacet(component, Arrays.asList(component.getClientId(facesContext)), facesContext, writer);
}
public static void checkForCommandFacet(UIComponent component, List<String> clientIds, FacesContext facesContext,
- TobagoResponseWriter writer) throws IOException {
+ TobagoResponseWriter writer) throws IOException {
if (ComponentUtils.getBooleanAttribute(component, Attributes.READONLY)
|| ComponentUtils.getBooleanAttribute(component, Attributes.DISABLED)) {
return;
@@ -607,6 +687,47 @@ public final class HtmlRendererUtils {
}
}
+
+ private static Command getCommandFacet(UIComponent facetComponent, String focusId,
+ FacesContext facesContext) throws IOException {
+ if (facetComponent instanceof UIForm && facetComponent.getChildCount() == 1) {
+ Deprecation.LOG.warn("Please don't use a form, but a command with immediate=true instead.");
+ facetComponent = (UIComponent) facetComponent.getChildren().get(0);
+ }
+ Command command = new Command();
+ command.actionId = facetComponent.getClientId(facesContext);
+ // transition == true is the default
+ if (!ComponentUtils.getBooleanAttribute(facetComponent, Attributes.TRANSITION)) {
+ command.transistion = Boolean.FALSE;
+ }
+ String target = ComponentUtils.getStringAttribute(facetComponent, Attributes.TARGET);
+ if (target != null) {
+ command.target = target;
+ }
+ if (facetComponent instanceof AbstractUICommand
+ && ((AbstractUICommand) facetComponent).getRenderedPartially().length > 0) {
+ String clientIds = HtmlRendererUtils.getComponentIds(facesContext, facetComponent,
+ ((UICommand) facetComponent).getRenderedPartially());
+ command.partially = clientIds;
+ } else {
+ String facetAction = (String) facetComponent.getAttributes().get(Attributes.ONCLICK);
+ if (facetAction != null) {
+ // Replace @autoId
+ facetAction = StringUtils.replace(facetAction, "@autoId", facetComponent.getClientId(facesContext));
+ command.onclick = facetAction;
+ }
+ if (focusId != null) {
+ command.focus = focusId;
+ }
+ }
+
+ int delay = ComponentUtils.getIntAttribute(facetComponent, Attributes.DELAY);
+ if (delay > 0) {
+ command.delay = delay;
+ }
+ return command;
+ }
+
private static void addCommandFacet(List<String> clientIds, Map.Entry<String, UIComponent> facetEntry,
FacesContext facesContext, TobagoResponseWriter writer) throws
IOException {
@@ -724,4 +845,14 @@ public final class HtmlRendererUtils {
String jsStatement = createOnclickAcceleratorKeyJsStatement(clientId, accessKey, null);
FacesContextUtils.addMenuAcceleratorScript(facesContext, jsStatement);
}
+
+ private static class Command {
+ private String actionId;
+ private Boolean transistion;
+ private String target;
+ private String partially;
+ private String focus;
+ private String onclick;
+ private Integer delay;
+ }
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-in.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-in.js?rev=1363960&r1=1363959&r2=1363960&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-in.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-in.js Fri Jul 20 21:42:39 2012
@@ -15,6 +15,138 @@
* limitations under the License.
*/
+Tobago.In = function(inId, required, requiredClass, maxLength) {
+ this.id = inId;
+ this.required = required;
+ this.requiredClass = requiredClass;
+ this.maxLength = maxLength;
+ this.setup();
+};
+
+Tobago.In.init = function(elements) {
+ var ins = Tobago.Utils.selectWidthJQuery(elements, ".tobago-in");
+ ins.each(function(){
+ var id = jQuery(this).attr("id");
+ var suggest = jQuery(this).attr("data-tobago-suggest") != undefined;
+ var required = jQuery(this).attr("required") != undefined;
+ if (suggest) {
+ new Tobago.AutocompleterAjax(id, required, 'tobago-in-markup-required');
+ } else {
+ new Tobago.In(id, required, 'tobago-in-markup-required');
+ }
+ });
+ ins = Tobago.Utils.selectWidthJQuery(elements, ".tobago-date");
+ ins.each(function(){
+ var id = jQuery(this).attr("id");
+ var required = jQuery(this).attr("required") != undefined;
+ new Tobago.In(id, required, 'tobago-date-markup-required');
+ });
+ ins = Tobago.Utils.selectWidthJQuery(elements, ".tobago-textarea");
+ ins.each(function(){
+ var id = jQuery(this).attr("id");
+ var required = jQuery(this).attr("required") != undefined;
+ new Tobago.In(id, required, 'tobago-textarea-markup-required');
+ });
+};
+
+Tobago.In.prototype.setup = function() {
+ var ctrl;
+ if (this.required) {
+ ctrl = Tobago.element(this.id);
+ if (ctrl.value && ctrl.value.length > 0) {
+ Tobago.removeCssClass(this.id, this.requiredClass);
+ }
+ Tobago.addBindEventListener(ctrl, 'focus', this, 'enterRequired');
+ Tobago.addBindEventListener(ctrl, 'blur', this, 'leaveRequired');
+ }
+ if (this.maxLength && this.maxLength > 0) {
+ ctrl = Tobago.element(this.id);
+ Tobago.addBindEventListener(ctrl, 'change', this, 'checkMaxLength');
+ Tobago.addBindEventListener(ctrl, 'keypress', this, 'checkMaxLength');
+ if (jQuery.browser.msie) {
+ Tobago.addBindEventListener(ctrl, 'paste', this, 'checkMaxLengthOnPaste');
+ }
+ }
+};
+
+// XXX IE only
+Tobago.In.prototype.checkMaxLengthOnPaste = function(event) {
+ if (!event) {
+ event = window.event;
+ }
+ var input = Tobago.element(event);
+ var pasteText = window.clipboardData.getData('Text');
+ var range = document.selection.createRange();
+ if (input.value.length - range.text.length + pasteText.length > this.maxLength) {
+ pasteText = pasteText.substring(0, this.maxLength - input.value.length + range.text.length);
+ range.text = pasteText;
+ event.returnValue = false;
+ }
+};
+
+Tobago.In.prototype.checkMaxLength = function(event) {
+ if (!event) {
+ event = window.event;
+ }
+ var ctrl = Tobago.element(event);
+ var elementLength = ctrl.value.length;
+ if (elementLength > this.maxLength) {
+ // Input is longer than max, truncate and return false.
+ // This takes care of the case where the user has pasted in text
+ // that's too long. Return true here because the onChange event can
+ // continue (now that we've truncated the value). This allows chained
+ // handlers to work.
+ ctrl.value = ctrl.value.substr(0, this.maxLength);
+ return true;
+ }
+
+ // If less than max length (i.e. within acceptable range), return true
+ if (elementLength < this.maxLength) {
+ return true;
+ }
+
+ // If we've made it to here, we know that elementLength == length
+
+ // If this is a change event, the field has already been updated to a string
+ // of the maximum allowable length. This is fine. Continue processing.
+ if (event.type == 'change') {
+ return true;
+ }
+
+ // If we've made it to here, we know that this is a keyPress event
+
+ // If the input is something less than a space (e.g. tab, CR, etc.)
+ // return true.
+ // If key was CTRL-v (or APPLE-v), which will be used to paste some new text,
+ // pass it along.
+ if (event) {
+ if ((event.which < 32)
+ || ((event.which == 118) && (event.ctrlKey || event.metaKey))) {
+ return true;
+ }
+ }
+
+ // Default return FALSE. If we're here, this is an onKeyPress event, it's a
+ // printable character, and elementLength already equals the maximum allowed.
+ // We need to return false here to cancel the event otherwise this last
+ // character will end up in the input field in position MAX+1.
+ return false;
+};
+
+Tobago.In.prototype.enterRequired = function(e) {
+ Tobago.removeCssClass(this.id, this.requiredClass);
+};
+
+Tobago.In.prototype.leaveRequired = function(e) {
+ var ctrl = Tobago.element(this.id);
+ if (!ctrl.value || ctrl.value.length == 0) {
+ Tobago.addCssClass(ctrl.id, this.requiredClass);
+ }
+};
+
+Tobago.registerListener(Tobago.In.init, Tobago.Phase.DOCUMENT_READY);
+Tobago.registerListener(Tobago.In.init, Tobago.Phase.AFTER_UPDATE);
+
Tobago.AutocompleterAjax = function (elementId, required, requiredClass, options) {
LOG.debug('new Tobago.AutocompleterAjax ' + elementId); // @DEV_ONLY
this.id = elementId;
@@ -40,8 +172,6 @@ Tobago.AutocompleterAjax = function (ele
var input = Tobago.element(elementId);
- input.setAttribute('autocomplete', 'off');
-
this.oldValue = input.value;
Tobago.addBindEventListener(input, 'keyup', this, 'doCheckSuggest');
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-logging.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-logging.js?rev=1363960&r1=1363959&r2=1363960&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-logging.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-logging.js Fri Jul 20 21:42:39 2012
@@ -418,3 +418,9 @@ LOG.LogMessage.prototype.displayOn = fun
return this.type <= type;
};
+LOG.init = function() {
+ new LOG.LogArea({hide:true});
+};
+
+Tobago.registerListener(LOG.init, Tobago.Phase.DOCUMENT_READY);
+
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?rev=1363960&r1=1363959&r2=1363960&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js Fri Jul 20 21:42:39 2012
@@ -59,13 +59,6 @@ Tobago.Sheet = function(sheetId, firstRo
this.mouseDownX = undefined;
this.mouseDownY = undefined;
- Tobago.addAjaxComponent(this.id, this);
- // option are only used for ajax request
- this.options = {
- // overlay is created by sheet itself, so disable this in Tobago.Transport
- createOverlay: false
- };
-
this.ppPrefix = Tobago.SUB_COMPONENT_SEP + "pagingPages" + Tobago.SUB_COMPONENT_SEP;
this.firstRegExp = new RegExp(this.ppPrefix + "First$");
@@ -86,6 +79,43 @@ Tobago.Sheet = function(sheetId, firstRo
LOG.debug("Sheet-total time = " + (this.endTime.getTime() - this.startTime.getTime())); // @DEV_ONLY
};
+Tobago.Sheet.init = function(elements) {
+ var sheets = Tobago.Utils.selectWidthJQuery(elements, ".tobago-sheet");
+ sheets.each(function initSheets() {
+ var sheet = jQuery(this);
+ var id = sheet.attr("id");
+ var frequency;
+ var frequencyStr = sheet.attr("data-tobago-reload");
+ if (frequencyStr != undefined) {
+ frequency = parseInt(frequencyStr);
+ }
+ var selectionMode = sheet.attr("data-tobago-selectionmode");
+ var commandStr = sheet.attr("data-tobago-rowaction");
+ var click;
+ var dblclick;
+ if (commandStr != undefined) {
+ var commands = jQuery.parseJSON(commandStr);
+ click = commands.click;
+ dblclick = commands.dblclick;
+ }
+ var columnSelectorIndex;
+ var selectorMenu = sheet.find(".tobago-sheet-headerDiv > .tobago-sheet-header > .tobago-sheet-selectorMenu");
+ if (selectorMenu) {
+ columnSelectorIndex = selectorMenu.parent().index();
+ }
+ new Tobago.Sheet(id, undefined, selectionMode, columnSelectorIndex, frequency,
+ click != undefined ? click.actionId : undefined,
+ click != undefined ? click.partially : undefined,
+ dblclick != undefined ? dblclick.actionId : undefined,
+ dblclick != undefined ? dblclick.partially: undefined,
+ sheet.attr("data-tobago-partially"));
+ });
+};
+
+Tobago.registerListener(Tobago.Sheet.init, Tobago.Phase.DOCUMENT_READY);
+Tobago.registerListener(Tobago.Sheet.init, Tobago.Phase.AFTER_UPDATE);
+
+
Tobago.Sheet.prototype.setupSortHeaders = function() {
var sheet = this;
jQuery(Tobago.Utils.escapeClientId(sheet.id)).find(".tobago-sheet-header[sorterId]").each(function() {
@@ -171,10 +201,7 @@ Tobago.Sheet.prototype.doPaging = functi
Tobago.Sheet.prototype.reloadWithAction = function(source, action, options) {
LOG.debug("reload sheet with action \"" + action + "\""); // @DEV_ONLY
- var reloadOptions = Tobago.extend({}, this.options);
- reloadOptions = Tobago.extend(reloadOptions, options);
- Tobago.createOverlay(jQuery(Tobago.Utils.escapeClientId(this.id)));
- Tobago.Updater.update(source, action, this.renderedPartially?this.renderedPartially:this.id, reloadOptions);
+ Tobago.Updater.update(source, action, this.renderedPartially?this.renderedPartially:this.id, options);
};
Tobago.Sheet.prototype.afterDoUpdateSuccess = function() {
@@ -281,7 +308,7 @@ Tobago.Sheet.prototype.setupResizer = fu
};
Tobago.Sheet.prototype.setup = function() {
- this.setupStart = new Date();
+ this.setupStart = new Date(); // @DEV_ONLY
this.setupResizer();
@@ -319,7 +346,7 @@ Tobago.Sheet.prototype.setup = function(
this.setupRowPaging();
this.initReload();
- this.setupEnd = new Date();
+ this.setupEnd = new Date(); // @DEV_ONLY
};
Tobago.Sheet.prototype.setScrollPosition = function() {
@@ -407,11 +434,6 @@ Tobago.Sheet.prototype.doSelection = fun
srcElement = event.srcElement;
}
- //LOG.debug("event.ctrlKey = " + event.ctrlKey);
- //LOG.debug("event.shiftKey = " + event.shiftKey);
- //LOG.debug("srcElement = " + srcElement.tagName);
- //LOG.debug("Actionid " + this.clickActionId);
- //LOG.debug("ID " + this.id);
if (srcElement.id.search(/_data_row_selector_/) > -1 || !Tobago.isInputElement(srcElement.tagName)) {
if (Math.abs(this.mouseDownX - event.clientX) + Math.abs(this.mouseDownY - event.clientY) > 5) {
@@ -443,10 +465,14 @@ Tobago.Sheet.prototype.doSelection = fun
} else if (this.selectable != "singleOrNone" || !wasSelected) {
this.toggleSelection(rowIndex, row.get(0), selector);
}
- //LOG.debug("selected rows = " + hidden.value);
if (this.clickActionId) {
- var action = this.id + ":" + rowIndex + ":" + this.clickActionId;
- //LOG.debug("Action " + action);
+ var action;
+ var index = this.clickActionId.indexOf(this.id);
+ if (index >= 0) {
+ action = this.id + ":" + rowIndex + ":" + this.clickActionId.substring(index + this.id.length +1);
+ } else {
+ action = this.id + ":" + rowIndex + ":" + this.clickActionId;
+ }
if (this.clickReloadComponentId && this.clickReloadComponentId.length > 0) {
Tobago.reloadComponent(srcElement, this.clickReloadComponentId, action)
} else {
@@ -470,18 +496,17 @@ Tobago.Sheet.prototype.doDblClick = func
srcElement = event.srcElement;
}
- //LOG.debug("event.ctrlKey = " + event.ctrlKey);
- //LOG.debug("event.shiftKey = " + event.shiftKey);
- //LOG.debug("srcElement = " + srcElement.tagName);
- //LOG.debug("Actionid " + this.clickActionId);
- //LOG.debug("ID " + this.id);
if (! Tobago.isInputElement(srcElement.tagName)) {
var row = jQuery(Tobago.element(event)).closest("tr");
var rowIndex = row.index() + this.firstRowIndex;
- //LOG.debug("selected rows = " + hidden.value);
if (this.dblClickActionId) {
- var action = this.id + ":" + rowIndex + ":" + this.dblClickActionId;
- //LOG.debug("dblAction " + action);
+ var action;
+ var index = this.clickActionId.indexOf(this.id);
+ if (index >= 0) {
+ action = this.id + ":" + rowIndex + ":" + this.clickActionId.substring(index + this.id.length +1);
+ } else {
+ action = this.id + ":" + rowIndex + ":" + this.clickActionId;
+ }
if (this.dblClickReloadComponentId && this.dblClickReloadComponentId.length > 0) {
Tobago.reloadComponent(srcElement, this.dblClickReloadComponentId, action)
} else {
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=1363960&r1=1363959&r2=1363960&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Fri Jul 20 21:42:39 2012
@@ -42,7 +42,7 @@ var TbgTimer = {
LOG.debug('until appOnload ' + (this.startAppOnload.getTime() - this.startOnload.getTime())); // @DEV_ONLY
LOG.debug('until scriptLoaders ' + (this.startScriptLoaders.getTime() - this.startOnload.getTime())); // @DEV_ONLY
LOG.debug('time scriptLoaders ' + (this.endScriptLoaders.getTime() - this.startScriptLoaders.getTime())); // @DEV_ONLY
- LOG.debug('until nach onload ' + (this.endOnload.getTime() - this.startTbgJs.getTime())); // @DEV_ONLY
+ LOG.debug('until after onload ' + (this.endOnload.getTime() - this.startTbgJs.getTime())); // @DEV_ONLY
LOG.debug('total ' + totaljs); // @DEV_ONLY
}
};
@@ -304,6 +304,7 @@ var Tobago = {
window.setTimeout(Tobago.registerResizeAction, 1000);
}
+ Tobago.ensureScrollbarWeights();
window.setTimeout(Tobago.finishPageLoading, 1);
if (TbgTimer.endBody) { // @DEV_ONLY
TbgTimer.endOnload = new Date(); // @DEV_ONLY
@@ -314,7 +315,7 @@ var Tobago = {
Tobago.registerCurrentScripts();
if (TbgTimer.endBody) { // @DEV_ONLY
TbgTimer.startScriptLoaders = new Date(); // @DEV_ONLY
- } // @DEV_ONLY
+ } // @DEV_ONLY
Tobago.startScriptLoaders();
if (TbgTimer.endBody) { // @DEV_ONLY
TbgTimer.endScriptLoaders = new Date(); // @DEV_ONLY
@@ -930,6 +931,66 @@ var Tobago = {
Tobago.resizeAction();
}
},
+
+ initDom: function(elements) {
+ var autofocus = Tobago.Utils.selectWidthJQuery(elements, '[autofocus]');
+ autofocus.each(function setupFocus() {
+ Tobago.focusId = jQuery(this).attr("id");
+ Tobago.setFocus();
+ });
+ var commandButtons = Tobago.Utils.selectWidthJQuery(elements, '[data-tobago-action]');
+ commandButtons.each(function setupInputFacetCommand() {
+ var command = jQuery(this);
+ var text = command.attr("data-tobago-action");
+ var commands = jQuery.parseJSON(text);
+
+ if (commands.click) {
+ command.click(function() {
+ if (commands.click.partially) {
+ Tobago.reloadComponent(this, commands.click.partially, commands.click.actionId, commands.click);
+ } else {
+ Tobago.submitAction(this, commands.click.actionId, commands.click);
+ }
+ });
+ }
+ if (commands.change) {
+ command.change(function() {
+ if (commands.change.partially) {
+ Tobago.reloadComponent(this, commands.change.partially, commands.change.actionId, commands.change);
+ } else {
+ Tobago.submitAction(this, commands.change.actionId, commands.change);
+ }
+ });
+ }
+
+ if (commands.complete) {
+ if (commands.complete.partially) {
+ Tobago.reloadComponent(this, commands.complete.partially, commands.complete.actionId, commands.complete);
+ } else {
+ Tobago.submitAction(this, commands.complete.actionId, commands.complete);
+ }
+ }
+ if (commands.resize) {
+ Tobago.resizeAction = function() {
+ Tobago.submitAction(this, commands.resize.actionId, commands.resize);
+ }
+ }
+ if (commands.action) {
+ var delay = 100;
+ if (commands.action.delay) {
+ delay = commands.action.delay;
+ }
+ setTimeout(Tobago.submitAction(this, commands.action.actionId, commands.action), delay);
+ }
+ });
+ var accesskeys = Tobago.Utils.selectWidthJQuery(elements, '[accesskey]');
+ accesskeys.each(function setupAccessKey() {
+ var el = jQuery(this);
+ new Tobago.AcceleratorKey(function clickAccelKey() {
+ Tobago.clickOnElement(el.attr("id"))}, el.attr("accesskey"));
+ });
+ },
+
frameKiller: function() {
if (Tobago.form.style.display == 'none') {
if (self == top) {
@@ -955,12 +1016,21 @@ var Tobago = {
return Tobago.Utils.selectWidthJQuery(elements, selector);
},
- calculateScrollbarWeights: function(id) {
+ ensureScrollbarWeights: function() {
+ var id = Tobago.page.id + Tobago.SUB_COMPONENT_SEP + 'scrollbarWeight';
var hidden = jQuery(Tobago.Utils.escapeClientId(id));
- var outer = hidden.prev();
- hidden.val(''
- + (100 - outer.prop('clientWidth')) + ';'
- + (100 - outer.prop('clientHeight')));
+ if (hidden.val().length == 0) {
+ var outer = hidden.prev();
+ hidden.val(''
+ + (100 - outer.prop('clientWidth')) + ';'
+ + (100 - outer.prop('clientHeight')));
+ } else {
+ var scrollbarWeights = hidden.val().split(",");
+ if (scrollbarWeights.length == 2) {
+ Tobago.Config.set('Tobago', 'verticalScrollbarWeight', scrollbarWeights[0]);
+ Tobago.Config.set('Tobago', 'horizontalScrollbarWeight', scrollbarWeights[1]);
+ }
+ }
},
clickOnElement: function(id) {
@@ -1551,109 +1621,8 @@ Tobago.Config = {
Tobago.Config.set("Tobago", "themeConfig", "standard/standard");
Tobago.registerListener(Tobago.frameKiller, Tobago.Phase.DOCUMENT_READY);
-
-Tobago.In = function(inId, required, requiredClass, maxLength) {
- this.id = inId;
- this.required = required;
- this.requiredClass = requiredClass;
- this.maxLength = maxLength;
- this.setup();
-};
-
-Tobago.In.prototype.setup = function() {
- var ctrl;
- if (this.required) {
- ctrl = Tobago.element(this.id);
- if (ctrl.value && ctrl.value.length > 0) {
- Tobago.removeCssClass(this.id, this.requiredClass);
- }
- Tobago.addBindEventListener(ctrl, 'focus', this, 'enterRequired');
- Tobago.addBindEventListener(ctrl, 'blur', this, 'leaveRequired');
- }
- if (this.maxLength && this.maxLength > 0) {
- ctrl = Tobago.element(this.id);
- Tobago.addBindEventListener(ctrl, 'change', this, 'checkMaxLength');
- Tobago.addBindEventListener(ctrl, 'keypress', this, 'checkMaxLength');
- if (jQuery.browser.msie) {
- Tobago.addBindEventListener(ctrl, 'paste', this, 'checkMaxLengthOnPaste');
- }
- }
-};
-
-// XXX IE only
-Tobago.In.prototype.checkMaxLengthOnPaste = function(event) {
- if (!event) {
- event = window.event;
- }
- var input = Tobago.element(event);
- var pasteText = window.clipboardData.getData('Text');
- var range = document.selection.createRange();
- if (input.value.length - range.text.length + pasteText.length > this.maxLength) {
- pasteText = pasteText.substring(0, this.maxLength - input.value.length + range.text.length);
- range.text = pasteText;
- event.returnValue = false;
- }
-};
-
-Tobago.In.prototype.checkMaxLength = function(event) {
- if (!event) {
- event = window.event;
- }
- var ctrl = Tobago.element(event);
- var elementLength = ctrl.value.length;
- if (elementLength > this.maxLength) {
- // Input is longer than max, truncate and return false.
- // This takes care of the case where the user has pasted in text
- // that's too long. Return true here because the onChange event can
- // continue (now that we've truncated the value). This allows chained
- // handlers to work.
- ctrl.value = ctrl.value.substr(0, this.maxLength);
- return true;
- }
-
- // If less than max length (i.e. within acceptable range), return true
- if (elementLength < this.maxLength) {
- return true;
- }
-
- // If we've made it to here, we know that elementLength == length
-
- // If this is a change event, the field has already been updated to a string
- // of the maximum allowable length. This is fine. Continue processing.
- if (event.type == 'change') {
- return true;
- }
-
- // If we've made it to here, we know that this is a keyPress event
-
- // If the input is something less than a space (e.g. tab, CR, etc.)
- // return true.
- // If key was CTRL-v (or APPLE-v), which will be used to paste some new text,
- // pass it along.
- if (event) {
- if ((event.which < 32)
- || ((event.which == 118) && (event.ctrlKey || event.metaKey))) {
- return true;
- }
- }
-
- // Default return FALSE. If we're here, this is an onKeyPress event, it's a
- // printable character, and elementLength already equals the maximum allowed.
- // We need to return false here to cancel the event otherwise this last
- // character will end up in the input field in position MAX+1.
- return false;
-};
-
-Tobago.In.prototype.enterRequired = function(e) {
- Tobago.removeCssClass(this.id, this.requiredClass);
-};
-
-Tobago.In.prototype.leaveRequired = function(e) {
- var ctrl = Tobago.element(this.id);
- if (!ctrl.value || ctrl.value.length == 0) {
- Tobago.addCssClass(ctrl.id, this.requiredClass);
- }
-};
+Tobago.registerListener(Tobago.initDom, Tobago.Phase.DOCUMENT_READY);
+Tobago.registerListener(Tobago.initDom, Tobago.Phase.AFTER_UPDATE);
// XXX: 2nd parameter enableAjax is deprecated
Tobago.Panel = function(panelId, enableAjax, autoReload) {
@@ -2652,11 +2621,56 @@ Tobago.SelectManyShuttle.copyValues = fu
hidden.find("option").remove();
shuttle.find(".tobago-selectManyShuttle-selected option").clone()
.attr('selected', 'selected').appendTo(hidden);
+ var e = jQuery.Event("change");
+ // trigger an change event for command facets
+ hidden.trigger( e );
};
Tobago.registerListener(Tobago.SelectManyShuttle.init, Tobago.Phase.DOCUMENT_READY);
Tobago.registerListener(Tobago.SelectManyShuttle.init, Tobago.Phase.AFTER_UPDATE);
+Tobago.SelectOneRadio = {};
+
+Tobago.SelectOneRadio.init = function(elements) {
+ var selectOneRadios = Tobago.Utils.selectWidthJQuery(elements, ".tobago-selectOneRadio");
+ selectOneRadios.each(function() {
+ var ul = jQuery(this);
+ var radios = jQuery('input[name="' + ul.attr('id').replace(/:/g, '\\:') + '"]');
+ radios.each(function () {
+ var selectOneRadio = jQuery(this);
+ selectOneRadio.data('oldValue', selectOneRadio.attr('checked'));
+ });
+ radios.click(function() {
+ var selectOneRadio = jQuery(this);
+ var readonly = selectOneRadio.attr('readonly');
+ var required = selectOneRadio.attr('required');
+ if (!required && !readonly) {
+ if (selectOneRadio.data('oldValue') == selectOneRadio.attr('checked')) {
+ selectOneRadio.attr('checked', false);
+ }
+ selectOneRadio.data('oldValue', selectOneRadio.attr('checked'));
+ }
+ var radios = jQuery('input[name="' + ul.attr('id').replace(/:/g, '\\:') + '"]');
+ if (readonly) {
+ radios.each(function () {
+ var radio = jQuery(this);
+ radio.attr('checked'. radio.data('oldValue'));
+ });
+ } else {
+ radios.each(function () {
+ if (this.id != selectOneRadio.get(0).id) {
+ var radio = jQuery(this);
+ radio.attr('checked', false);
+ radio.data('oldValue', radio.attr('checked'));
+ }
+ });
+ }
+ });
+ });
+};
+
+Tobago.registerListener(Tobago.SelectOneRadio.init, Tobago.Phase.DOCUMENT_READY);
+Tobago.registerListener(Tobago.SelectOneRadio.init, Tobago.Phase.AFTER_UPDATE);
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Tobago.File = {};