]> BookStack Code Mirror - bookstack/commitdiff
Standardized vue component http access and fixed some small bugs
authorDan Brown <redacted>
Mon, 28 Dec 2015 15:58:13 +0000 (15:58 +0000)
committerDan Brown <redacted>
Mon, 28 Dec 2015 15:58:13 +0000 (15:58 +0000)
app/Http/Controllers/PageController.php
app/Repos/PageRepo.php
package.json
resources/assets/js/components/image-manager.vue
resources/assets/js/components/image-picker.vue

index 2002fbdf0de0ac2eb986a213ec2a4f4f17bcd966..4997963140832896b2735da9b336e7ccdabd474f 100644 (file)
@@ -61,9 +61,7 @@ class PageController extends Controller
     {
         $this->checkPermission('page-create');
         $this->validate($request, [
-            'name'   => 'required|string|max:255',
-            'html'   => 'required|string',
-            'parent' => 'integer|exists:pages,id'
+            'name'   => 'required|string|max:255'
         ]);
 
         $input = $request->all();
@@ -121,6 +119,9 @@ class PageController extends Controller
     public function update(Request $request, $bookSlug, $pageSlug)
     {
         $this->checkPermission('page-update');
+        $this->validate($request, [
+            'name'   => 'required|string|max:255'
+        ]);
         $book = $this->bookRepo->getBySlug($bookSlug);
         $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
         $this->pageRepo->updatePage($page, $book->id, $request->all());
index f7b48efdc2f38a3bda9022ea8c45bb8f251f5ab2..052d9dd1e9abe56fca9178dbfec5f536d61d554a 100644 (file)
@@ -120,6 +120,7 @@ class PageRepo
      */
     protected function formatHtml($htmlText)
     {
+        if($htmlText == '') return $htmlText;
         libxml_use_internal_errors(true);
         $doc = new \DOMDocument();
         $doc->loadHTML($htmlText);
index e33ad170e62065f784e1007b79934301b9020ac5..2797cf0c842627dc9c249ce9b7c877eb552ec5ab 100644 (file)
@@ -9,9 +9,9 @@
     "bootstrap-sass": "^3.0.0",
     "dropzone": "^4.0.1",
     "laravel-elixir": "^3.4.0",
-    "vue": "^1.0.4",
+    "vue": "^1.0.13",
     "vue-hot-reload-api": "^1.2.1",
-    "vue-resource": "^0.1.16",
+    "vue-resource": "^0.5.1",
     "vueify": "^5.0.1",
     "vueify-insert-css": "^1.0.0",
     "zeroclipboard": "^2.2.0"
index dd4a77d57855420390dd0ccb00390839e023767b..7574806065444339ca9d93d7e817f86b53a6c853 100644 (file)
 
         methods: {
             fetchData: function () {
-                var _this = this;
-                this.$http.get('/images/' + _this.imageType + '/all/' + _this.page, function (data) {
-                    _this.images = _this.images.concat(data.images);
-                    _this.hasMore = data.hasMore;
-                    _this.page++;
+                var url = '/images/' + this.imageType + '/all/' + this.page;
+                this.$http.get(url).then((response) => {
+                    this.images = this.images.concat(response.data.images);
+                    this.hasMore = response.data.hasMore;
+                    this.page++;
                 });
             },
 
                     url: '/images/' + _this.imageType + '/upload',
                     init: function () {
                         var dz = this;
-                        this.on("sending", function (file, xhr, data) {
+                        dz.on("sending", function (file, xhr, data) {
                             data.append("_token", _this.token);
                         });
-                        this.on("success", function (file, data) {
+                        dz.on("success", function (file, data) {
                             _this.images.unshift(data);
                             $(file.previewElement).fadeOut(400, function () {
                                 dz.removeFile(file);
                             });
                         });
-                        this.on('error', function (file, errorMessage, xhr) {
+                        dz.on('error', function (file, errorMessage, xhr) {
                             if (errorMessage.file) {
                                 $(file.previewElement).find('[data-dz-errormessage]').text(errorMessage.file[0]);
                             }
             },
 
             selectButtonClick: function () {
-                if (this.callback) {
-                    this.returnCallback(this.selectedImage);
-                }
+                if (this.callback) this.returnCallback(this.selectedImage);
                 this.hide();
             },
 
 
             saveImageDetails: function (e) {
                 e.preventDefault();
-                var _this = this;
-                _this.selectedImage._token = _this.token;
-                var form = $(_this.$els.imageForm);
-                $.ajax('/images/update/' + _this.selectedImage.id, {
-                    method: 'PUT',
-                    data: _this.selectedImage
-                }).done(function () {
+                this.selectedImage._token = this.token;
+                var form = $(this.$els.imageForm);
+                var url = '/images/update/' + this.selectedImage.id;
+                this.$http.put(url, this.selectedImage).then((response) => {
                     form.showSuccess('Image name updated');
-                }).fail(function (jqXHR) {
-                    form.showFailure(jqXHR.responseJSON);
-                })
+                }, (response) => {
+                    form.showFailure(response.data);
+                });
             },
 
             deleteImage: function (e) {
                 var _this = this;
                 _this.deleteForm.force = _this.dependantPages !== false;
                 _this.deleteForm._token = _this.token;
-                $.ajax('/images/' + _this.selectedImage.id, {
-                    method: 'DELETE',
-                    data: _this.deleteForm
-                }).done(function () {
-                    _this.images.splice(_this.images.indexOf(_this.selectedImage), 1);
-                    _this.selectedImage = false;
-                    $(_this.$els.imageTitle).showSuccess('Image Deleted');
-                }).fail(function (jqXHR, textStatus) {
+                var url = '/images/' + _this.selectedImage.id;
+                this.$http.delete(url, this.deleteForm).then((response) => {
+                    this.images.splice(this.images.indexOf(this.selectedImage), 1);
+                    this.selectedImage = false;
+                    $(this.$els.imageTitle).showSuccess('Image Deleted');
+                }, (response) => {
                     // Pages failure
-                    if (jqXHR.status === 400) {
-                        _this.dependantPages = jqXHR.responseJSON;
+                    if (response.status === 400) {
+                        _this.dependantPages = response.data;
                     }
                 });
             }
index 7be976caf409298c4e83144f5e7d9436d9497db0..e3c564eb9cc7e865b5510f1b3cc89cb787f11d3a 100644 (file)
@@ -65,9 +65,8 @@
                 this.value = this.currentId === 'false' ?  imageUrl : imageModel.id;
             },
             showImageManager: function(e) {
-                var _this = this;
-                ImageManager.show(function(image) {
-                    _this.updateImageFromModel(image);
+                ImageManager.show((image) => {
+                    this.updateImageFromModel(image);
                 });
             },
             reset: function() {
             },
             remove: function() {
                 this.image = 'none';
+                this.value = 'none';
             },
             updateImageFromModel: function(model) {
-                var _this = this;
-                var isResized = _this.resizeWidth && _this.resizeHeight;
+                var isResized = this.resizeWidth && this.resizeHeight;
 
                 if (!isResized) {
-                    _this.setCurrentValue(model, model.url);
+                    this.setCurrentValue(model, model.url);
                     return;
                 }
 
-                var cropped = _this.resizeCrop ? 'true' : 'false';
-                var requestString = '/images/thumb/' + model.id + '/' + _this.resizeWidth + '/' + _this.resizeHeight + '/' + cropped;
-                _this.$http.get(requestString, function(data) {
-                    _this.setCurrentValue(model, data.url);
+                var cropped = this.resizeCrop ? 'true' : 'false';
+                var requestString = '/images/thumb/' + model.id + '/' + this.resizeWidth + '/' + this.resizeHeight + '/' + cropped;
+                this.$http.get(requestString).then((response) => {
+                    this.setCurrentValue(model, response.data.url);
                 });
             }
         }