Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update froala to v2 #355

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/accounts/accounts-tab/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if (Meteor.isClient) {
index: 80,
identifier: 'accounts-index',
title: i18n('accounts.index.title'),
iconClass: 'fa fa-user',
routeName: 'accounts.index',
activeRouteRegex: 'accounts',
permission: 'accounts.index'
Expand Down
7 changes: 7 additions & 0 deletions packages/base/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ orion.links.attachSchema(new SimpleSchema({
title: {
type: String
},
iconClass: {
type: String,
optional: true
},
routeName: {
type: String,
optional: true
Expand All @@ -38,6 +42,9 @@ orion.links.add = function(options) {
if (_.isFunction(options.title)) {
options.title = options.title();
}
if (_.isFunction(options.iconClass)) {
options.iconClass = options.iconClass();
}
self.upsert({ identifier: options.identifier }, { $set: options });
});
};
Expand Down
12 changes: 9 additions & 3 deletions packages/bootstrap/views/sidebar/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<span class="caret"></span>
</a>
<a href="{{ RouterLayerPathFor routeName }}">
{{ title }}
{{>orionBootstrapSidebarLinkIcon}} {{ title }}
</a>
{{ else }}
<a data-target="#admin-links-{{ identifier }}" href="#" data-toggle="collapse">
{{ title }}
{{>orionBootstrapSidebarLinkIcon}} {{ title }}
<span class="caret"></span>
</a>
{{/ if }}
Expand All @@ -37,7 +37,13 @@
</li>
{{ else }}
<li class="{{ RouterLayerIsActiveRoutePartial activeRouteRegex }}">
<a href="{{ RouterLayerPathFor routeName }}">{{ title }}</a>
<a href="{{ RouterLayerPathFor routeName }}">{{>orionBootstrapSidebarLinkIcon}} {{ title }}</a>
</li>
{{/ if }}
</template>

<template name="orionBootstrapSidebarLinkIcon">
{{#if iconClass}}
<i class="sidebar-icon {{iconClass}}"></i>
{{/if}}
</template>
4 changes: 4 additions & 0 deletions packages/bootstrap/views/sidebar/sidebar.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
padding-right: 20px;
cursor: pointer;
}
.sidebar-icon {
display: inline;
padding-right: 4px;
}
}
1 change: 1 addition & 0 deletions packages/collections/collections_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ orion.collections.onCreated(function() {
activeRouteRegex: 'collections.' + self.name,
permission: 'collections.' + self.name + '.index',
title: self.name[0].toUpperCase() + self.name.slice(1),
iconClass: 'fa fa-table',
index: 30
}, self.link);
orion.links.add(linkOptions);
Expand Down
1 change: 1 addition & 0 deletions packages/config/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ if (Meteor.isClient) {
index: 100,
identifier: 'config-update',
title: i18n('config.update.title'),
iconClass: 'fa fa-wrench',
routeName: 'config.update',
activeRouteRegex: 'config',
permission: 'config.update'
Expand Down
1 change: 1 addition & 0 deletions packages/dictionary/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Tracker.autorun(function () {
index: 10,
identifier: 'dictionary-update',
title: i18n('dictionary.update.title'),
iconClass: 'fa fa-at',
routeName: 'dictionary.update',
activeRouteRegex: 'dictionary',
permission: 'dictionary.update',
Expand Down
2 changes: 1 addition & 1 deletion packages/froala/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ orion.attributes.registerAttribute('froala', {
};
},
valueOut: function() {
return this.find('.editor').editable('getHTML', false, true);
return this.find('.editor').froalaEditor('html.get', false, true);
}
});

Expand Down
18 changes: 11 additions & 7 deletions packages/froala/froala.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ ReactiveTemplates.onRendered('attribute.froala', function () {
// Find the element
var element = parent.find('.editor');
// initialize froala
element.editable({
element.froalaEditor({
imageManagerLoadURL: '/api/froala/images',
imageManagerDeleteURL: '/api/froala/images',
imageManagerDeleteMethod: "DELETE",
imageManagerDeleteParams: {user_id: Meteor.userId()},
inlineMode: false,
placeholder: '',
minHeight: Options.get('froala.height', 400), // setting a default height
heightMin: Options.get('froala.height', 400), // setting a default height
key: orion.config.get('FROALA_ACTIVATION_KEY') // set license key if exists
});

// set the current value of the attribute
element.editable("setHTML", this.data.value, true);
element.froalaEditor("html.set", this.data.value, true);

// Handle image uploads
element.on('editable.beforeImageUpload', function (e, editor, files) {
element.on('froalaEditor.image.beforeUpload', function (e, editor, files) {
var upload = orion.filesystem.upload({
fileList: files,
name: files[0].name,
Expand All @@ -26,16 +30,16 @@ ReactiveTemplates.onRendered('attribute.froala', function () {
if (upload.error) {
console.log(upload.error, "error uploading file")
} else {
element.editable("insertHTML", "<img class='fr-fin' data-file-id='" + upload.fileId + "' src='" + upload.url + "'>", true);
element.froalaEditor("html.insert", "<img class='fr-fin' data-file-id='" + upload.fileId + "' src='" + upload.url + "'>", true);
}
element.editable("hidePopups");
element.froalaEditor("popups.hideAll");
}
});
return false;
});
// Handle image deletes
// If its uploaded through filesystem, it deletes the image and prevent the server call to delete
element.on('editable.beforeRemoveImage', function (e, editor, img) {
element.on('froalaEditor.image.beforeRemove', function (e, editor, img) {
var imgId = img.attr("data-file-id");
if (!imgId) {
return;
Expand Down
24 changes: 24 additions & 0 deletions packages/froala/froala_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const Api = new Restivus({
useDefaultAuth: true,
prettyJson: true
});

Api.addRoute('froala/images/', {
get() {
return orion.filesystem.collection.find({
uploader: {$in: ['image-attribute', 'froala']}
}).map(function(image){
return {
thumb: image.url,
url: image.url,
tag: "froala" // TODO: add tags to filesystem
}
});
},
delete(){
let {src} = this.bodyParams;
// TODO: only allow admin to delete, see also orion:filesystem permission
orion.filesystem.collection.remove({url: src});
return "";
}
});
6 changes: 5 additions & 1 deletion packages/froala/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Package.onUse(function(api) {
'orionjs:[email protected]',
'[email protected]_1',
'orionjs:[email protected]',
'froala:[email protected]',
'froala:[email protected]',
'nimble:[email protected]',
]);

api.imply([
Expand All @@ -23,6 +24,9 @@ Package.onUse(function(api) {
api.addFiles([
'attribute.js',
]);
api.addFiles([
'froala_server.js',
], 'server');

api.addFiles([
'froala.html',
Expand Down
1 change: 1 addition & 0 deletions packages/pages/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if (Meteor.isClient) {
index: 40,
identifier: 'pages-index',
title: i18n('pages.index.title'),
iconClass: 'fa fa-file-o',
routeName: 'pages.index',
activeRouteRegex: 'pages',
permission: 'pages.index',
Expand Down