/
controllers.js
46 lines (39 loc) · 1.24 KB
/
controllers.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
var editorApp = angular.module('editorApp', []);
editorApp.controller('PageCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.init = function(ctx, workspace, path) {
$scope.path = path
$scope.ctx = ctx
$scope.workspace = workspace
$scope.url = ctx + '/.rest/nodes/v1/'+ workspace + path
$http.get($scope.url).
success(function(data) {
//console.log(data)
$scope.page = data;
}).
error(function(data) {
alert('ERROR: ' + data)
});
};
$scope.save = function() {
$http.post($scope.url, $scope.page).
success(function(data) {
alert('Page saved')
}).
error(function(data) {
alert('ERROR: ' + data)
});
}
$scope.preview = function() {
window.open($scope.ctx + $scope.path)
}
$scope.publish = function() {
// In order for this to work you need to grant "rest" role get&post for "/.rest/commands*"
$http.post($scope.ctx + '/.rest/commands/v1/website/activate', {"path":$scope.page.path, "uuid": $scope.page.identifier, "repository":$scope.workspace}).
success(function(data) {
alert('Publication workflow started')
}).
error(function(data) {
alert('ERROR: ' + data)
});
}
}]);