forked from lawrencepit/slick-grid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
slick.globaleditorlock.js
54 lines (42 loc) · 1.44 KB
/
slick.globaleditorlock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/***
* A singleton for controlling access to the editing functionality for multiple components capable of editing the same data.
*/
var GlobalEditorLock = new function()
{
var currentEditor = null;
this.isEditing = function()
{
return (currentEditor != null);
}
this.hasLock = function(editor)
{
return (currentEditor == editor);
}
this.enterEditMode = function(editor)
{
if (currentEditor != null)
throw "GlobalEditorLock : enterEditMode : currentEditor == null";
if (!editor.commitCurrentEdit)
throw "GlobalEditorLock : enterEditMode : editor must implement .commitCurrentEdit()";
if (!editor.cancelCurrentEdit)
throw "GlobalEditorLock : enterEditMode : editor must implement .cancelCurrentEdit()";
currentEditor = editor;
}
this.leaveEditMode = function(editor)
{
if (currentEditor != editor)
throw "GlobalEditorLock : leaveEditMode() : currentEditor != editor";
currentEditor = null;
}
this.commitCurrentEdit = function()
{
if (currentEditor)
return currentEditor.commitCurrentEdit();
return true;
}
this.cancelCurrentEdit = function()
{
if (currentEditor)
currentEditor.cancelCurrentEdit();
}
};