rice-framework/krad-web/src/main/webapp/krad/scripts/krad.edit.js
/**
 * Shows the inline edit field (and retreives it if using ajax edit option).
 *
 * <p>Adds buttons and key handlers for the save and cancel functions.  Fields will return to the original value with
 * cancel, and will be sent to the server with methodToCall "saveField" when Saved.</p>
 *
 * @param $viewButton the element representing the origninal read only state of the field
 */
Shows the inline edit field (and retreives it if using ajax edit option).

Adds buttons and key handlers for the save and cancel functions.  Fields will return to the original value with
cancel, and will be sent to the server with methodToCall "saveField" when Saved.

@param $viewButton the element representing the origninal read only state of the field
Shows the inline edit field ( and retreives it if using ajax edit option ) . Adds buttons and key handlers for the save and cancel functions . Fields will return to the original value with cancel and will be sent to the server with methodToCall " saveField " when Saved . @param $viewButton the element representing the origninal read only state of the field
function showInlineEdit($viewButton) {
    var viewButtonId = $viewButton.attr("id");
    var editDivId = viewButtonId.replace(kradVariables.INLINE_EDIT.VIEW_SUFFIX, kradVariables.INLINE_EDIT.EDIT_SUFFIX);
    var $editDiv = jQuery("#" + editDivId);
    var $control = $editDiv.find("[data-role='Control']");
    if ($editDiv.is(":visible")) {
        focusEnd($control);
        return;
    }
    if ($editDiv.length) {
        $editDiv.data(kradVariables.INLINE_EDIT.ORIGINAL_VALUE, $control.val());
    }
    if ($viewButton.data(kradVariables.INLINE_EDIT.AJAX_EDIT) === true && $editDiv.length === 0) {
        var fieldId = viewButtonId.replace(kradVariables.INLINE_EDIT.INLINE_EDIT_VIEW, "");
        retrieveComponent(fieldId, kradVariables.REFRESH_METHOD_TO_CALL, function () {
            var $newView = jQuery("#" + viewButtonId);
            showInlineEdit($newView);
        });
        return;
    }
    $viewButton.hide();
    var saveEditFunc = function (event) {
        event.preventDefault();
        _saveEdit($control, viewButtonId);
        return false;
    };
    var cancelEditFunc = function (event) {
        event.preventDefault();
        return _cancelEdit($control, $editDiv, $viewButton);
    };
    jQuery(kradVariables.INLINE_EDIT.EDIT_CLASS).each(function () {
        jQuery(this).trigger("cancel." + kradVariables.INLINE_EDIT.INLINE_EDIT_NAMESPACE);
    });
    $editDiv.on("cancel." + kradVariables.INLINE_EDIT.INLINE_EDIT_NAMESPACE, function (event) {
        cancelEditFunc(event);
    });
    $control.removeAttr("readonly");
    $editDiv.show();
    var $editButtonDiv = $editDiv.find(kradVariables.INLINE_EDIT.EDIT_BUTTONS_CLASS);
    if (!$editButtonDiv.length) {
        $editButtonDiv = _createInlineEditButtons($control, $editDiv, saveEditFunc, cancelEditFunc);
    }
    focusEnd($control);
    _setupInlineEditKeyHandlers($control, cancelEditFunc, saveEditFunc);
}
function showInlineEdit ( $viewButton ) { var viewButtonId = $viewButton . attr ( "id" ) ; var editDivId = viewButtonId . replace ( kradVariables . INLINE_EDIT . VIEW_SUFFIX , kradVariables . INLINE_EDIT . EDIT_SUFFIX ) ; var $editDiv = jQuery ( "#" + editDivId ) ; var $control = $editDiv . find ( "[data-role='Control']" ) ; if ( $editDiv . is ( ":visible" ) ) { focusEnd ( $control ) ; return ; } if ( $editDiv . length ) { $editDiv . data ( kradVariables . INLINE_EDIT . ORIGINAL_VALUE , $control . val ( ) ) ; } if ( $viewButton . data ( kradVariables . INLINE_EDIT . AJAX_EDIT ) === true && $editDiv . length === 0 ) { var fieldId = viewButtonId . replace ( kradVariables . INLINE_EDIT . INLINE_EDIT_VIEW , "" ) ; retrieveComponent ( fieldId , kradVariables . REFRESH_METHOD_TO_CALL , function ( ) { var $newView = jQuery ( "#" + viewButtonId ) ; showInlineEdit ( $newView ) ; } ) ; return ; } $viewButton . hide ( ) ; var saveEditFunc = function ( event ) { event . preventDefault ( ) ; _saveEdit ( $control , viewButtonId ) ; return false ; } ; var cancelEditFunc = function ( event ) { event . preventDefault ( ) ; return _cancelEdit ( $control , $editDiv , $viewButton ) ; } ; jQuery ( kradVariables . INLINE_EDIT . EDIT_CLASS ) . each ( function ( ) { jQuery ( this ) . trigger ( "cancel." + kradVariables . INLINE_EDIT . INLINE_EDIT_NAMESPACE ) ; } ) ; $editDiv . on ( "cancel." + kradVariables . INLINE_EDIT . INLINE_EDIT_NAMESPACE , function ( event ) { cancelEditFunc ( event ) ; } ) ; $control . removeAttr ( "readonly" ) ; $editDiv . show ( ) ; var $editButtonDiv = $editDiv . find ( kradVariables . INLINE_EDIT . EDIT_BUTTONS_CLASS ) ; if ( ! $editButtonDiv . length ) { $editButtonDiv = _createInlineEditButtons ( $control , $editDiv , saveEditFunc , cancelEditFunc ) ; } focusEnd ( $control ) ; _setupInlineEditKeyHandlers ( $control , cancelEditFunc , saveEditFunc ) ; }
Shows the inline edit field (and retreives it if using ajax edit option).
Shows the inline edit field ( and retreives it if using ajax edit option ) .
// Inline edits have 2 states: a view state and an edit state
 // Derive the editDivId from the viewButtonId by replacing its suffix
 // Focus on the control if somehow the editDiv is visible already after an ajax retrieval
 // Save original value of the control to be restored on cancel
 // If the edit version of the field does not exist, retrieve it
 // Recall this function to show the edit state of the retrieved field
 // Return because we are waiting for ajax component retrieval
 // Creating save function to be used by the save button (created here to use current var handles)
 // Creating cancel function to be used by the cancel button and other cancel actions
 // (created here to use current var handles)
 // Cancel any edit fields that are currently open because we only allow one inline edit at a time
 // Add an handler for the cancel event used to close this edit when another is opened
 // Show the edit state
 // Check to see if the buttons exist, if they don't create and append them (must happen here to correctly
 // position them)
 // Setup key handlers for inline edit
