1 $group
2 #
3 # implements clickHandler
4 # params
5 # { ctx
6 # { editorImpl
7 # { modalManager
8 # string editorKey
9 #
10 class EditManager
11 ctor
12 param ctx
13 param options
14 set this.ctx = ctx
15 set this.options = options
16 set this.editorImpl = ctx.editorImpl
17 # do not set this in the constructor, could be yet uncreated
18 # set this.modalManager = ctx.modalManager
19 set this.dataHashKey = options.dataHashKey
20 set this.dataContentKey = options.dataContentKey
21 set this.dataPrettyKey = options.dataPrettyKey
22 set this.dataTitleKey = options.dataTitleKey
23 set this.contentHash = null
24 set this.contentOriginal = null
25 m initEditor
26 if this.editor
27 return
28 _ this.editorImpl.initialize
29 set this.editor = this.editorImpl
30 var that = this
31 var saveEl = wz.element('#' + this.editor.key + '-save')
32 var saveRefreshEl = wz.element('#' + this.editor.key + '-save-refresh')
33 var cancelEl = wz.element('#' + this.editor.key + '-cancel')
34 set this.titleElement = wz.element('#' + this.editor.key + '-title')
35 _ wz.click
36 @ cancelEl
37 function
38 _ that.ctx.modalManager.hide
39 @ that.editor.key
40 _ wz.click
41 @ saveEl
42 function
43 if that.editor.getValue() !== that.contentOriginal
44 _ that.ctx.dataManager.editSave
45 @ that.contentHash
46 _ that.editor.getValue
47 _ that.ctx.modalManager.hide
48 @ that.editor.key
49 _ wz.click
50 @ saveRefreshEl
51 function
52 if that.editor.getValue() !== that.contentOriginal
53 _ that.ctx.dataManager.editSave
54 @ that.contentHash
55 _ that.editor.getValue
56 _ that.ctx.modalManager.hide
57 @ that.editor.key
58 set location.href= location.pathname
59 m onSave
60 param data
61 _ wz.value
62 @ this.contentElementId
63 @ data.content
64 _ wz.html
65 @ this.prettyElementId
66 @ data.pretty && data.pretty.prettyLines ? data.pretty.prettyLines.join('') : data.pretty
67 m setEditor
68 param options
69 if this.editor
70 _ this.editor.setValue
71 @ options.value
72 if this.titleElement
73 _ wz.text(this.titleElement, options.title)
74 m edit
75 param options
76 # log 'wz.editManager.edit.options', options
77 _ this.initEditor
78 _ this.setEditor
79 @ options
80 m handleClick
81 param target
82 param dataValue
83 # log 'wz.editManager.handleClick.dataValue', dataValue
84 set this.contentElementId = dataValue[this.dataContentKey]
85 set this.prettyElementId = dataValue[this.dataPrettyKey]
86 set this.contentHash = dataValue[this.dataHashKey]
87 set this.contentOriginal = wz.value(this.contentElementId)
88 _ this.edit
89 {
90 @ value wz.value(this.contentElementId)
91 @ title dataValue[this.dataTitleKey]
92 _ this.ctx.modalManager.show
93 @ this.editor.key
94 @ this.editor.key + '-form'
95 m checkClick
96 param target
97 if this.editor
98 return
99 _ this.ctx.modalManager.checkClick
100 @ this.editor.key + '-form'
101 @ target
102 return false