external editor support
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
class EditorMenu {
|
||||
|
||||
constructor() {
|
||||
this.restrict = "E";
|
||||
this.templateUrl = "frontend/directives/editor-menu.html";
|
||||
this.scope = {
|
||||
callback: "&",
|
||||
selectedEditor: "="
|
||||
};
|
||||
}
|
||||
|
||||
controller($scope, modelManager, extensionManager, syncManager) {
|
||||
'ngInject';
|
||||
|
||||
$scope.formData = {};
|
||||
|
||||
let editorContentType = "SN|Editor";
|
||||
|
||||
let defaultEditor = {
|
||||
default: true,
|
||||
name: "Plain"
|
||||
}
|
||||
|
||||
$scope.sysEditors = [defaultEditor];
|
||||
$scope.editors = modelManager.itemsForContentType(editorContentType);
|
||||
|
||||
$scope.editorForUrl = function(url) {
|
||||
return $scope.editors.filter(function(editor){return editor.url == url})[0];
|
||||
}
|
||||
|
||||
$scope.selectEditor = function(editor) {
|
||||
$scope.callback()(editor);
|
||||
}
|
||||
|
||||
$scope.deleteEditor = function(editor) {
|
||||
if(confirm("Are you sure you want to delete this editor?")) {
|
||||
modelManager.setItemToBeDeleted(editor);
|
||||
syncManager.sync();
|
||||
}
|
||||
}
|
||||
|
||||
$scope.submitNewEditorRequest = function() {
|
||||
var editor = createEditor($scope.formData.url);
|
||||
modelManager.addItem(editor);
|
||||
editor.setDirty(true);
|
||||
syncManager.sync();
|
||||
$scope.editors.push(editor);
|
||||
$scope.formData = {};
|
||||
}
|
||||
|
||||
function createEditor(url) {
|
||||
var name = getParameterByName("name", url);
|
||||
return modelManager.createItem({
|
||||
content_type: editorContentType,
|
||||
url: url,
|
||||
name: name
|
||||
})
|
||||
}
|
||||
|
||||
function getParameterByName(name, url) {
|
||||
name = name.replace(/[\[\]]/g, "\\$&");
|
||||
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
|
||||
results = regex.exec(url);
|
||||
if (!results) return null;
|
||||
if (!results[2]) return '';
|
||||
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
angular.module('app.frontend').directive('editorMenu', () => new EditorMenu);
|
||||
@@ -1,4 +1,3 @@
|
||||
// Start from filter
|
||||
angular.module('app.frontend').filter('startFrom', function() {
|
||||
return function(input, start) {
|
||||
return input.slice(start);
|
||||
|
||||
5
app/assets/javascripts/app/services/filters/trusted.js
Normal file
5
app/assets/javascripts/app/services/filters/trusted.js
Normal file
@@ -0,0 +1,5 @@
|
||||
angular.module('app.frontend').filter('trusted', ['$sce', function ($sce) {
|
||||
return function(url) {
|
||||
return $sce.trustAsResourceUrl(url);
|
||||
};
|
||||
}]);
|
||||
@@ -8,7 +8,7 @@ class ModelManager {
|
||||
this.itemChangeObservers = [];
|
||||
this.items = [];
|
||||
this._extensions = [];
|
||||
this.acceptableContentTypes = ["Note", "Tag", "Extension"];
|
||||
this.acceptableContentTypes = ["Note", "Tag", "Extension", "SN|Editor"];
|
||||
}
|
||||
|
||||
get allItems() {
|
||||
@@ -121,6 +121,8 @@ class ModelManager {
|
||||
item = new Tag(json_obj);
|
||||
} else if(json_obj.content_type == "Extension") {
|
||||
item = new Extension(json_obj);
|
||||
} else if(json_obj.content_type == "SN|Editor") {
|
||||
item = new Editor(json_obj);
|
||||
} else {
|
||||
item = new Item(json_obj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user