]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/controllers.js
Add APP_LOGGING
[bookstack] / resources / assets / js / controllers.js
index af740f508e9585fa83daf971d328c96bc5392bba..6a88aa81152a6822b81071a77c9f9aa2ccda5870 100644 (file)
@@ -1,12 +1,12 @@
 "use strict";
 
-import moment from 'moment';
-import 'moment/locale/en-gb';
-import editorOptions from "./pages/page-form";
+const moment = require('moment');
+require('moment/locale/en-gb');
+const editorOptions = require("./pages/page-form");
 
 moment.locale('en-gb');
 
-export default function (ngApp, events) {
+module.exports = function (ngApp, events) {
 
     ngApp.controller('ImageManagerController', ['$scope', '$attrs', '$http', '$timeout', 'imageManagerService',
         function ($scope, $attrs, $http, $timeout, imageManagerService) {
@@ -64,7 +64,7 @@ export default function (ngApp, events) {
                 $scope.$apply(() => {
                     $scope.images.unshift(data);
                 });
-                events.emit('success', 'Image uploaded');
+                events.emit('success', trans('components.image_upload_success'));
             };
 
             /**
@@ -151,10 +151,9 @@ export default function (ngApp, events) {
                 if ($scope.searching) components['term'] = $scope.searchTerm;
 
 
-                let urlQueryString = Object.keys(components).map((key) => {
+                url += Object.keys(components).map((key) => {
                     return key + '=' + encodeURIComponent(components[key]);
                 }).join('&');
-                url += urlQueryString;
 
                 $http.get(url).then((response) => {
                     $scope.images = $scope.images.concat(response.data.images);
@@ -209,7 +208,7 @@ export default function (ngApp, events) {
                 event.preventDefault();
                 let url = window.baseUrl('/images/update/' + $scope.selectedImage.id);
                 $http.put(url, this.selectedImage).then(response => {
-                    events.emit('success', 'Image details updated');
+                    events.emit('success', trans('components.image_update_success'));
                 }, (response) => {
                     if (response.status === 422) {
                         let errors = response.data;
@@ -238,7 +237,7 @@ export default function (ngApp, events) {
                 $http.delete(url).then((response) => {
                     $scope.images.splice($scope.images.indexOf($scope.selectedImage), 1);
                     $scope.selectedImage = false;
-                    events.emit('success', 'Image successfully deleted');
+                    events.emit('success', trans('components.image_delete_success'));
                 }, (response) => {
                     // Pages failure
                     if (response.status === 400) {
@@ -260,39 +259,6 @@ export default function (ngApp, events) {
 
         }]);
 
-
-    ngApp.controller('BookShowController', ['$scope', '$http', '$attrs', '$sce', function ($scope, $http, $attrs, $sce) {
-        $scope.searching = false;
-        $scope.searchTerm = '';
-        $scope.searchResults = '';
-
-        $scope.searchBook = function (e) {
-            e.preventDefault();
-            let term = $scope.searchTerm;
-            if (term.length == 0) return;
-            $scope.searching = true;
-            $scope.searchResults = '';
-            let searchUrl = window.baseUrl('/search/book/' + $attrs.bookId);
-            searchUrl += '?term=' + encodeURIComponent(term);
-            $http.get(searchUrl).then((response) => {
-                $scope.searchResults = $sce.trustAsHtml(response.data);
-            });
-        };
-
-        $scope.checkSearchForm = function () {
-            if ($scope.searchTerm.length < 1) {
-                $scope.searching = false;
-            }
-        };
-
-        $scope.clearSearch = function () {
-            $scope.searching = false;
-            $scope.searchTerm = '';
-        };
-
-    }]);
-
-
     ngApp.controller('PageEditController', ['$scope', '$http', '$attrs', '$interval', '$timeout', '$sce',
         function ($scope, $http, $attrs, $interval, $timeout, $sce) {
 
@@ -309,9 +275,9 @@ export default function (ngApp, events) {
 
         // Set initial header draft text
         if ($scope.isUpdateDraft || $scope.isNewPageDraft) {
-            $scope.draftText = 'Editing Draft'
+            $scope.draftText = trans('entities.pages_editing_draft');
         } else {
-            $scope.draftText = 'Editing Page'
+            $scope.draftText = trans('entities.pages_editing_page');
         }
 
         let autoSave = false;
@@ -388,7 +354,7 @@ export default function (ngApp, events) {
                 lastSave = Date.now();
             }, errorRes => {
                 if (draftErroring) return;
-                events.emit('error', 'Failed to save draft. Ensure you have internet connection before saving this page.')
+                events.emit('error', trans('errors.page_draft_autosave_fail'));
                 draftErroring = true;
             });
         }
@@ -421,7 +387,7 @@ export default function (ngApp, events) {
             let url = window.baseUrl('/ajax/page/' + pageId);
             $http.get(url).then((responseData) => {
                 if (autoSave) $interval.cancel(autoSave);
-                $scope.draftText = 'Editing Page';
+                $scope.draftText = trans('entities.pages_editing_page');
                 $scope.isUpdateDraft = false;
                 $scope.$broadcast('html-update', responseData.data.html);
                 $scope.$broadcast('markdown-update', responseData.data.markdown || responseData.data.html);
@@ -429,7 +395,7 @@ export default function (ngApp, events) {
                 $timeout(() => {
                     startAutoSave();
                 }, 1000);
-                events.emit('success', 'Draft discarded, The editor has been updated with the current page content');
+                events.emit('success', trans('entities.pages_draft_discarded'));
             });
         };
 
@@ -594,7 +560,7 @@ export default function (ngApp, events) {
                 $scope.$apply(() => {
                     $scope.files.push(data);
                 });
-                events.emit('success', 'File uploaded');
+                events.emit('success', trans('entities.attachments_file_uploaded'));
             };
 
             /**
@@ -612,7 +578,7 @@ export default function (ngApp, events) {
                         data.link = '';
                     }
                 });
-                events.emit('success', 'File updated');
+                events.emit('success', trans('entities.attachments_file_updated'));
             };
 
             /**
@@ -638,7 +604,7 @@ export default function (ngApp, events) {
                 file.uploaded_to = pageId;
                 $http.post(window.baseUrl('/attachments/link'), file).then(resp => {
                     $scope.files.push(resp.data);
-                    events.emit('success', 'Link attached');
+                    events.emit('success', trans('entities.attachments_link_attached'));
                     $scope.file = getCleanFile();
                 }, checkError('link'));
             };
@@ -672,7 +638,7 @@ export default function (ngApp, events) {
                         $scope.editFile.link = '';
                     }
                     $scope.editFile = false;
-                    events.emit('success', resp.headers('message-success'));
+                    events.emit('success', trans('entities.attachments_updated_success'));
                 }, checkError('edit'));
             };