-
Notifications
You must be signed in to change notification settings - Fork 206
/
view-content.js
182 lines (152 loc) · 4.93 KB
/
view-content.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import $ from 'jquery';
import { notEmpty } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import Notifier from '../../mixins/notifier';
import Component from '@ember/component';
export default Component.extend(Notifier, {
documentService: service('document'),
sectionService: service('section'),
store: service(),
appMeta: service(),
linkSvc: service('link'),
hasPages: notEmpty('pages'),
showInsertSectionModal: false,
newSectionLocation: '',
toEdit: '',
canEdit: computed('permissions', 'document.protection', function() {
let canEdit = this.get('document.protection') !== this.get('constants').ProtectionType.Lock && this.get('permissions.documentEdit');
return canEdit;
}),
voteThanks: false,
showLikes: false,
showDeleteBlockDialog: false,
deleteBlockId: '',
didReceiveAttrs() {
this._super(...arguments);
// Show/allow liking if space allows it and document is published.
this.set('showLikes', this.get('folder.allowLikes') && this.get('document.isLive'));
},
didInsertElement() {
this._super(...arguments);
},
didRender() {
this._super(...arguments);
this.jumpToSection(this.get('currentPageId'));
this.contentLinkHandler();
},
contentLinkHandler() {
let linkSvc = this.get('linkSvc');
let doc = this.get('document');
let self = this;
$("a[data-documize='true']").off('click').on('click', function (e) {
let link = linkSvc.getLinkObject(self.get('links'), this);
// local link? exists?
if ((link.linkType === "section" || link.linkType === "tab") && link.documentId === doc.get('id')) {
let exists = self.get('pages').findBy('id', link.targetId);
if (_.isUndefined(exists)) {
link.orphan = true;
} else {
if (link.linkType === "section") {
self.jumpToSection(link.targetId);
}
}
}
if (link.orphan) {
$(this).addClass('broken-link');
e.preventDefault();
e.stopPropagation();
return false;
}
e.preventDefault();
e.stopPropagation();
linkSvc.linkClick(doc, link);
return false;
});
},
jumpToSection(cp) {
if (!_.isEmpty(cp) && !_.isUndefined(cp) && !_.isNull(cp)) {
this.get('browser').scrollTo(`#page-${cp}`)
}
},
addSection(model) {
let constants = this.get('constants');
if (this.get('document.protection') === constants.ProtectionType.Review) {
model.page.set('status', model.page.get('relativeId') === '' ? constants.ChangeState.PendingNew : constants.ChangeState.Pending);
}
return this.get('onInsertSection')(model);
},
actions: {
onSavePageAsBlock(block) {
let cb = this.get('onSavePageAsBlock');
const promise = cb(block);
promise.then(() => {
let refresh = this.get('refresh');
refresh();
});
},
onCopyPage(pageId, documentId) {
let cb = this.get('onCopyPage');
cb(pageId, documentId);
},
onMovePage(pageId, documentId) {
let cb = this.get('onMovePage');
cb(pageId, documentId);
},
onDeletePage(params) {
let cb = this.get('onDeletePage');
cb(params);
},
onSavePage(page, meta) {
let document = this.get('document');
let constants = this.get('constants');
switch (document.get('protection')) {
case constants.ProtectionType.Lock:
break;
case constants.ProtectionType.Review:
// detect edits to newly created pending page
if (page.get('relativeId') === '' && page.get('status') === constants.ChangeState.PendingNew) {
// new page, edits
this.set('toEdit', '');
this.get('onSavePage')(page, meta);
} else if (page.get('relativeId') !== '' && page.get('status') === constants.ChangeState.Published) {
// existing page, first edit
const promise = this.addSection({ page: page, meta: meta });
promise.then((/*id*/) => { this.set('toEdit', ''); });
} else if (page.get('relativeId') !== '' && page.get('status') === constants.ChangeState.Pending) {
// existing page, subsequent edits
this.set('toEdit', '');
this.get('onSavePage')(page, meta);
}
break;
case constants.ProtectionType.None:
// for un-protected documents, edits welcome!
this.set('toEdit', '');
this.get('onSavePage')(page, meta);
break;
}
},
onShowSectionWizard(beforePage) {
this.set('newSectionLocation', beforePage);
this.set('showInsertSectionModal', true)
},
onShowDeleteBlockModal(id) {
this.set('deleteBlockId', id);
this.set('showDeleteBlockDialog', true);
},
onVote(vote) {
this.get('documentService').vote(this.get('document.id'), vote);
this.set('voteThanks', true);
}
}
});