Mixin: SC.InlineEditable

This mixin is used for views that show a seperate editor view to edit. For example, the default behavior of SC.LabelView if isEditable is set to YES is to popup an SC.InlineTextFieldView when double clicked. This is a seperate text input that will handle the editing and save its value back to the label when it is finished.

To use this functionality, all you have to do is apply this mixin to your view. You may define your own SC.InlineEditorDelegate to further customize editing behavior.

MyProject.MyView = SC.View.extend(SC.InlineEditable, {
  inlineEditorDelegate: myDelegate
});

The delegate methods will default to your view unless the inlineEditorDelegate implements them. Simple views do not require a seperate delegate. If your view has a more complicated editing interaction, you may also implement a custom delegate. For example, if you have a form with several views that all edit together, you might set the parent view as the delegate so it can manage the lifecycle and layout of the editors.

See SC.InlineEditorDelegate for more information on using a delegate to customize your view's edit behavior.

Your view can now be edited by calling beginEditing() on it.

myView.beginEditing();

This will create an editor for the view. You can then end the editing process by calling commitEditing() or discardEditing() on either the view or the editor. commitEditing() will save the value and discard will revert to the original value.

myView.commitEditing();
myView.discardEditing();

Note that the editor is a private property of the view, so the only views that should be able to access the methods on it are the editor itself, the view it is editing, and their delegates.

Defined in: inline_editable.js

Field Summary

Class Methods

Field Detail

SC.InlineEditable.exampleEditor SC.InlineEditor

The view that will be used to edit this view. Defaults to SC.InlineTextFieldView, which is simply a text field that positions itself over the view being edited.

Default value:
SC.InlineTextFieldView
SC.InlineEditable.inlineEditorDelegate SC.InlineEditorDelegate

Delegate that will be notified of events related to the editing process. Also responsible for managing the lifecycle of the editor.

Default value:
SC.InlineTextFieldDelegate
SC.InlineEditable.isEditable Boolean
Flag to enable or disable editing.
Default value:
YES
SC.InlineEditable.isEditing Boolean

Indicates whether the view is currently editing. Attempting to beginEditing a view that is already editing will fail.

Default value:
NO
SC.InlineEditable.isInlineEditable Boolean
Walk like a duck.
Default value:
YES

Class Method Detail

beginEditing()

Tells the view to start editing. This will create an editor for it and transfer control to the editor.

Will fail if the delegate returns NO to inlineEditorShouldBeginEditing.

Returns:
Boolean
whether the view successfully entered edit mode
commitEditing()

Tells the view to save the value currently in the editor and finish editing. The delegate will be consulted first by calling inlineEditorShouldCommitEditing, and the operation will not be allowed if the delegate returns NO.

Will fail if the delegate returns NO to inlineEditorShouldCommitEditing.

Returns:
Boolean
whether the delegate allowed the value to be committed
discardEditing()

Tells the view to leave edit mode and revert to the value it had before editing. May fail if the delegate returns NO to inlineEditorShouldDiscardEditing. It is possible for the delegate to return false to inlineEditorShouldDiscardEditing but true to inlineEditorShouldCommitEditing, so a client view may attempt to call commitEditing in case discardEditing fails.

Will fail if the delegate returns NO to inlineEditorShouldDiscardEditing.

Returns:
Boolean
whether the delegate allowed the view to discard its value
inlineEditorDidBeginEditing(editor, value, editable)
Sets isEditing to YES once editing has begun.
Parameters:
editor
value
editable
inlineEditorDidCommitEditing(editor, value, editable)

By default, commiting editing simply sets the value that the editor returned and cleans up.

Parameters:
editor
value
editable
inlineEditorDidDiscardEditing(editor, editable)

Calls inlineEditorDidEndEditing for backwards compatibility and then cleans up.

Parameters:
editor
editable
inlineEditorShouldBeginEditing()

Allows the view to begin editing if it is editable and it is not already editing.

Returns:
Boolean
if the view is allowed to begin editing
inlineEditorWillBeginEditing(editor, value, editable)
By default, the editor starts with the value of the view being edited.
Parameters:
editor
value
editable
inlineEditorWillDiscardEditing(editor, editable)
Calls inlineEditorWillEndEditing for backwards compatibility.
Parameters:
editor
editable
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:20 GMT-0600 (CST)