Dan Brown

Standardized vue component http access and fixed some small bugs

...@@ -61,9 +61,7 @@ class PageController extends Controller ...@@ -61,9 +61,7 @@ class PageController extends Controller
61 { 61 {
62 $this->checkPermission('page-create'); 62 $this->checkPermission('page-create');
63 $this->validate($request, [ 63 $this->validate($request, [
64 - 'name' => 'required|string|max:255', 64 + 'name' => 'required|string|max:255'
65 - 'html' => 'required|string',
66 - 'parent' => 'integer|exists:pages,id'
67 ]); 65 ]);
68 66
69 $input = $request->all(); 67 $input = $request->all();
...@@ -121,6 +119,9 @@ class PageController extends Controller ...@@ -121,6 +119,9 @@ class PageController extends Controller
121 public function update(Request $request, $bookSlug, $pageSlug) 119 public function update(Request $request, $bookSlug, $pageSlug)
122 { 120 {
123 $this->checkPermission('page-update'); 121 $this->checkPermission('page-update');
122 + $this->validate($request, [
123 + 'name' => 'required|string|max:255'
124 + ]);
124 $book = $this->bookRepo->getBySlug($bookSlug); 125 $book = $this->bookRepo->getBySlug($bookSlug);
125 $page = $this->pageRepo->getBySlug($pageSlug, $book->id); 126 $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
126 $this->pageRepo->updatePage($page, $book->id, $request->all()); 127 $this->pageRepo->updatePage($page, $book->id, $request->all());
......
...@@ -120,6 +120,7 @@ class PageRepo ...@@ -120,6 +120,7 @@ class PageRepo
120 */ 120 */
121 protected function formatHtml($htmlText) 121 protected function formatHtml($htmlText)
122 { 122 {
123 + if($htmlText == '') return $htmlText;
123 libxml_use_internal_errors(true); 124 libxml_use_internal_errors(true);
124 $doc = new \DOMDocument(); 125 $doc = new \DOMDocument();
125 $doc->loadHTML($htmlText); 126 $doc->loadHTML($htmlText);
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
9 "bootstrap-sass": "^3.0.0", 9 "bootstrap-sass": "^3.0.0",
10 "dropzone": "^4.0.1", 10 "dropzone": "^4.0.1",
11 "laravel-elixir": "^3.4.0", 11 "laravel-elixir": "^3.4.0",
12 - "vue": "^1.0.4", 12 + "vue": "^1.0.13",
13 "vue-hot-reload-api": "^1.2.1", 13 "vue-hot-reload-api": "^1.2.1",
14 - "vue-resource": "^0.1.16", 14 + "vue-resource": "^0.5.1",
15 "vueify": "^5.0.1", 15 "vueify": "^5.0.1",
16 "vueify-insert-css": "^1.0.0", 16 "vueify-insert-css": "^1.0.0",
17 "zeroclipboard": "^2.2.0" 17 "zeroclipboard": "^2.2.0"
......
...@@ -94,11 +94,11 @@ ...@@ -94,11 +94,11 @@
94 94
95 methods: { 95 methods: {
96 fetchData: function () { 96 fetchData: function () {
97 - var _this = this; 97 + var url = '/images/' + this.imageType + '/all/' + this.page;
98 - this.$http.get('/images/' + _this.imageType + '/all/' + _this.page, function (data) { 98 + this.$http.get(url).then((response) => {
99 - _this.images = _this.images.concat(data.images); 99 + this.images = this.images.concat(response.data.images);
100 - _this.hasMore = data.hasMore; 100 + this.hasMore = response.data.hasMore;
101 - _this.page++; 101 + this.page++;
102 }); 102 });
103 }, 103 },
104 104
...@@ -108,16 +108,16 @@ ...@@ -108,16 +108,16 @@
108 url: '/images/' + _this.imageType + '/upload', 108 url: '/images/' + _this.imageType + '/upload',
109 init: function () { 109 init: function () {
110 var dz = this; 110 var dz = this;
111 - this.on("sending", function (file, xhr, data) { 111 + dz.on("sending", function (file, xhr, data) {
112 data.append("_token", _this.token); 112 data.append("_token", _this.token);
113 }); 113 });
114 - this.on("success", function (file, data) { 114 + dz.on("success", function (file, data) {
115 _this.images.unshift(data); 115 _this.images.unshift(data);
116 $(file.previewElement).fadeOut(400, function () { 116 $(file.previewElement).fadeOut(400, function () {
117 dz.removeFile(file); 117 dz.removeFile(file);
118 }); 118 });
119 }); 119 });
120 - this.on('error', function (file, errorMessage, xhr) { 120 + dz.on('error', function (file, errorMessage, xhr) {
121 if (errorMessage.file) { 121 if (errorMessage.file) {
122 $(file.previewElement).find('[data-dz-errormessage]').text(errorMessage.file[0]); 122 $(file.previewElement).find('[data-dz-errormessage]').text(errorMessage.file[0]);
123 } 123 }
...@@ -149,9 +149,7 @@ ...@@ -149,9 +149,7 @@
149 }, 149 },
150 150
151 selectButtonClick: function () { 151 selectButtonClick: function () {
152 - if (this.callback) { 152 + if (this.callback) this.returnCallback(this.selectedImage);
153 - this.returnCallback(this.selectedImage);
154 - }
155 this.hide(); 153 this.hide();
156 }, 154 },
157 155
...@@ -177,17 +175,14 @@ ...@@ -177,17 +175,14 @@
177 175
178 saveImageDetails: function (e) { 176 saveImageDetails: function (e) {
179 e.preventDefault(); 177 e.preventDefault();
180 - var _this = this; 178 + this.selectedImage._token = this.token;
181 - _this.selectedImage._token = _this.token; 179 + var form = $(this.$els.imageForm);
182 - var form = $(_this.$els.imageForm); 180 + var url = '/images/update/' + this.selectedImage.id;
183 - $.ajax('/images/update/' + _this.selectedImage.id, { 181 + this.$http.put(url, this.selectedImage).then((response) => {
184 - method: 'PUT',
185 - data: _this.selectedImage
186 - }).done(function () {
187 form.showSuccess('Image name updated'); 182 form.showSuccess('Image name updated');
188 - }).fail(function (jqXHR) { 183 + }, (response) => {
189 - form.showFailure(jqXHR.responseJSON); 184 + form.showFailure(response.data);
190 - }) 185 + });
191 }, 186 },
192 187
193 deleteImage: function (e) { 188 deleteImage: function (e) {
...@@ -195,17 +190,15 @@ ...@@ -195,17 +190,15 @@
195 var _this = this; 190 var _this = this;
196 _this.deleteForm.force = _this.dependantPages !== false; 191 _this.deleteForm.force = _this.dependantPages !== false;
197 _this.deleteForm._token = _this.token; 192 _this.deleteForm._token = _this.token;
198 - $.ajax('/images/' + _this.selectedImage.id, { 193 + var url = '/images/' + _this.selectedImage.id;
199 - method: 'DELETE', 194 + this.$http.delete(url, this.deleteForm).then((response) => {
200 - data: _this.deleteForm 195 + this.images.splice(this.images.indexOf(this.selectedImage), 1);
201 - }).done(function () { 196 + this.selectedImage = false;
202 - _this.images.splice(_this.images.indexOf(_this.selectedImage), 1); 197 + $(this.$els.imageTitle).showSuccess('Image Deleted');
203 - _this.selectedImage = false; 198 + }, (response) => {
204 - $(_this.$els.imageTitle).showSuccess('Image Deleted');
205 - }).fail(function (jqXHR, textStatus) {
206 // Pages failure 199 // Pages failure
207 - if (jqXHR.status === 400) { 200 + if (response.status === 400) {
208 - _this.dependantPages = jqXHR.responseJSON; 201 + _this.dependantPages = response.data;
209 } 202 }
210 }); 203 });
211 } 204 }
......
...@@ -65,9 +65,8 @@ ...@@ -65,9 +65,8 @@
65 this.value = this.currentId === 'false' ? imageUrl : imageModel.id; 65 this.value = this.currentId === 'false' ? imageUrl : imageModel.id;
66 }, 66 },
67 showImageManager: function(e) { 67 showImageManager: function(e) {
68 - var _this = this; 68 + ImageManager.show((image) => {
69 - ImageManager.show(function(image) { 69 + this.updateImageFromModel(image);
70 - _this.updateImageFromModel(image);
71 }); 70 });
72 }, 71 },
73 reset: function() { 72 reset: function() {
...@@ -75,20 +74,20 @@ ...@@ -75,20 +74,20 @@
75 }, 74 },
76 remove: function() { 75 remove: function() {
77 this.image = 'none'; 76 this.image = 'none';
77 + this.value = 'none';
78 }, 78 },
79 updateImageFromModel: function(model) { 79 updateImageFromModel: function(model) {
80 - var _this = this; 80 + var isResized = this.resizeWidth && this.resizeHeight;
81 - var isResized = _this.resizeWidth && _this.resizeHeight;
82 81
83 if (!isResized) { 82 if (!isResized) {
84 - _this.setCurrentValue(model, model.url); 83 + this.setCurrentValue(model, model.url);
85 return; 84 return;
86 } 85 }
87 86
88 - var cropped = _this.resizeCrop ? 'true' : 'false'; 87 + var cropped = this.resizeCrop ? 'true' : 'false';
89 - var requestString = '/images/thumb/' + model.id + '/' + _this.resizeWidth + '/' + _this.resizeHeight + '/' + cropped; 88 + var requestString = '/images/thumb/' + model.id + '/' + this.resizeWidth + '/' + this.resizeHeight + '/' + cropped;
90 - _this.$http.get(requestString, function(data) { 89 + this.$http.get(requestString).then((response) => {
91 - _this.setCurrentValue(model, data.url); 90 + this.setCurrentValue(model, response.data.url);
92 }); 91 });
93 } 92 }
94 } 93 }
......