Author: abelevich
Date: 2010-08-13 08:40:20 -0400 (Fri, 13 Aug 2010)
New Revision: 18616
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js
Log:
JS api refactoring
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2010-08-13
11:46:22 UTC (rev 18615)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2010-08-13
12:40:20 UTC (rev 18616)
@@ -9,22 +9,21 @@
this.changedCss = options.changedCss;
this.showControls = options.showControls;
-
this.element = $(document.getElementById(id));
this.editContainer = $(document.getElementById(options.editContainer));
this.input = $(document.getElementById(options.input));
this.label = $(document.getElementById(options.label));
this.initialValue = this.label.text();
- richfaces.Event.bind(this.element, this.editEvent, this.editState, this);
- richfaces.Event.bind(this.input, "change", this.changedState,
this);
- richfaces.Event.bind(this.input, "blur", this.readyState, this);
+ richfaces.Event.bind(this.element, this.editEvent, this.edit, this);
+ richfaces.Event.bind(this.input, "change", this.save, this);
+ richfaces.Event.bind(this.input, "blur", this.save, this);
if(this.showControls) {
this.okbtn = $(document.getElementById(options.okbtn));
this.cancelbtn = $(document.getElementById(options.cancelbtn));
- richfaces.Event.bind(this.okbtn, "mousedown", this.clickOk,
this);
- richfaces.Event.bind(this.cancelbtn, "mousedown",
this.clickCancel, this);
+ richfaces.Event.bind(this.okbtn, "mousedown", this.saveBtnHandler,
this);
+ richfaces.Event.bind(this.cancelbtn, "mousedown",
this.cancelBtnHandler, this);
}
};
@@ -37,40 +36,15 @@
$.extend(richfaces.ui.InplaceInput.prototype, ( function () {
return {
name : "RichFaces.ui.InplaceInput",
-
- switchToState: function(state) {
- if(this.currentState != state) {
- var states = RichFaces.ui.InplaceInput;
- switch(state) {
- case states.READY: this.doReady(); break;
- case states.EDIT: this.doEdit(); break;
- case states.CHANGED: this.doChanged(); break;
- default:
- }
- this.currentState = state;
- }
- },
-
- editState: function(){
- this.switchToState(RichFaces.ui.InplaceInput.EDIT);
- },
-
- changedState: function(){
- this.switchToState(RichFaces.ui.InplaceInput.CHANGED);
- },
- readyState: function() {
- if(!this.showControls) {
- this.switchToState(RichFaces.ui.InplaceInput.READY);
- }
- },
-
- doEdit: function() {
+/****************** public methods *****************************************/
+
+ edit: function() {
this.editContainer.removeClass(this.noneCss);
this.input.focus();
},
-
- doChanged: function() {
+
+ save: function() {
var inputValue = this.input.val();
if(inputValue.length > 0) {
this.label.text(inputValue);
@@ -81,26 +55,34 @@
} else {
this.element.removeClass(this.changedCss);
}
+
+ this.editContainer.addClass(this.noneCss);
},
-
- doReady: function() {
+
+ cancel: function() {
+ var text = this.label.text();
+ this.input.val(text);
this.editContainer.addClass(this.noneCss);
},
- clickOk: function() {
- this.changedState();
- this.switchToState(RichFaces.ui.InplaceInput.READY);
- return false;
+ setValue: function (value) {
+ this.input.val(value);
+ this.save();
+ },
+
+ getValue: function() {
+ return this.input.val();
},
- clickCancel: function() {
- var text = this.label.text();
- this.input.val(text);
- this.switchToState(RichFaces.ui.InplaceInput.READY);
- return false;
+ saveBtnHandler: function() {
+ this.save(); return false;
+ },
+
+ cancelBtnHandler: function() {
+ this.cancel(); return false;
}
}
- })());
+ })());
})(jQuery, window.RichFaces);