Browse Source

Swaps note create modal for collapsible form.

Christopher Leggett 5 years ago
parent
commit
72f7aeba42
3 changed files with 150 additions and 72 deletions
  1. 117 45
      public/js/app.js
  2. 6 24
      resources/js/components/note-form-modal.vue
  3. 27 3
      resources/js/components/notes.vue

+ 117 - 45
public/js/app.js

@@ -2529,7 +2529,8 @@ __webpack_require__.r(__webpack_exports__);
 /* harmony default export */ __webpack_exports__["default"] = ({
   props: {
     populateWith: {
-      type: Object
+      type: Object,
+      require: true
     },
     modalId: {
       type: String,
@@ -2547,32 +2548,14 @@ __webpack_require__.r(__webpack_exports__);
   },
   data: function data() {
     return {
-      note: {}
+      note: JSON.parse(JSON.stringify(this.populateWith))
     };
   },
-  mounted: function mounted() {
-    if (!this.populateWith) {
-      this.note = {
-        thenote: '',
-        notetype: this.noteType,
-        noteuser: this.noteUser,
-        woid: this.woid
-      };
-    } else {
-      this.note = JSON.parse(JSON.stringify(this.populateWith));
-    }
-  },
   methods: {
     updateNote: function updateNote(note) {
-      if (this.populateWith) {
-        axios.put('/api/workorders/notes/' + note.noteid, note).then(function (response) {
-          hideModal();
-        });
-      } else {
-        axios.post('/api/workorders/notes', note).then(function (response) {
-          hideModal();
-        });
-      }
+      axios.put('/api/workorders/notes/' + note.noteid, note).then(function (response) {
+        hideModal();
+      });
     },
     hideModal: function hideModal() {
       $('#' + this.modalId).modal('hide');
@@ -2619,6 +2602,17 @@ __webpack_require__.r(__webpack_exports__);
 //
 //
 //
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
 
 /* harmony default export */ __webpack_exports__["default"] = ({
   mixins: [_mixins_dateMixin__WEBPACK_IMPORTED_MODULE_0__["default"]],
@@ -2626,7 +2620,13 @@ __webpack_require__.r(__webpack_exports__);
   data: function data() {
     return {
       notes: Object.values(this.initialnotes),
-      currentOrder: 'order-first'
+      currentOrder: 'order-first',
+      newNote: {
+        notetype: this.noteType,
+        thenote: '',
+        noteuser: this.authusername,
+        woid: this.woid
+      }
     };
   },
   methods: {
@@ -2642,6 +2642,14 @@ __webpack_require__.r(__webpack_exports__);
       }
 
       return this.currentOrder;
+    },
+    createNote: function createNote() {
+      var _this = this;
+
+      axios.post('/api/workorders/notes', this.newNote).then(function (response) {
+        $('#note' + _this.noteType + 'add').collapse('hide');
+        _this.newNote.thenote = '';
+      });
     }
   }
 });
@@ -50093,27 +50101,91 @@ var render = function() {
     "ul",
     { staticClass: "list-unstyled" },
     [
-      _c("note-form-modal", {
-        attrs: {
-          "modal-id": "note" + _vm.noteType + "CreateModal",
-          "note-type": _vm.noteType,
-          woid: _vm.woid,
-          "note-user": _vm.authusername
-        }
-      }),
-      _vm._v(" "),
-      _c(
-        "button",
-        {
-          staticClass: "btn btn-primary",
-          attrs: {
-            type: "button",
-            "data-toggle": "modal",
-            "data-target": "#note" + _vm.noteType + "CreateModal"
-          }
-        },
-        [_c("i", { staticClass: "fas fa-fw fa-plus" }), _vm._v(" Add New Note")]
-      ),
+      _c("div", { staticClass: "row" }, [
+        _c(
+          "div",
+          {
+            staticClass:
+              "col-md-2 d-flex justify-content-center justify-content-md-start"
+          },
+          [
+            _c(
+              "button",
+              {
+                staticClass: "btn btn-primary m-2",
+                attrs: {
+                  type: "button",
+                  "data-toggle": "collapse",
+                  "data-target": "#note" + _vm.noteType + "add"
+                }
+              },
+              [
+                _c("i", { staticClass: "fas fa-fw fa-plus" }),
+                _vm._v(" Add New Note")
+              ]
+            )
+          ]
+        ),
+        _vm._v(" "),
+        _c("div", { staticClass: "col-md-10" }, [
+          _c(
+            "div",
+            {
+              staticClass: "collapse",
+              attrs: { id: "note" + _vm.noteType + "add" }
+            },
+            [
+              _c(
+                "div",
+                {
+                  staticClass:
+                    "d-flex flex-wrap flex-md-nowrap justify-content-center"
+                },
+                [
+                  _c("textarea", {
+                    directives: [
+                      {
+                        name: "model",
+                        rawName: "v-model",
+                        value: _vm.newNote.thenote,
+                        expression: "newNote.thenote"
+                      }
+                    ],
+                    staticClass: "form-control",
+                    attrs: {
+                      name: "newnote" + _vm.noteType,
+                      id: "newnote" + _vm.noteType
+                    },
+                    domProps: { value: _vm.newNote.thenote },
+                    on: {
+                      input: function($event) {
+                        if ($event.target.composing) {
+                          return
+                        }
+                        _vm.$set(_vm.newNote, "thenote", $event.target.value)
+                      }
+                    }
+                  }),
+                  _vm._v(" "),
+                  _c(
+                    "button",
+                    {
+                      staticClass: "btn btn-secondary m-2",
+                      attrs: { type: "button" },
+                      on: {
+                        click: function($event) {
+                          return _vm.createNote()
+                        }
+                      }
+                    },
+                    [_vm._v("Save")]
+                  )
+                ]
+              )
+            ]
+          )
+        ])
+      ]),
       _vm._v(" "),
       _vm._l(this.notes, function(note, index) {
         return _c(

+ 6 - 24
resources/js/components/note-form-modal.vue

@@ -20,6 +20,7 @@ export default {
     props: {
         populateWith: {
             type: Object,
+            require: true
         },
         modalId: {
             type: String,
@@ -37,34 +38,15 @@ export default {
     },
     data () {
         return {
-            note: {}
-        }
-    },
-    mounted () {
-        if(!this.populateWith) {
-            this.note = {
-                thenote: '',
-                notetype: this.noteType,
-                noteuser: this.noteUser,
-                woid: this.woid,
-            }
-        } else {
-            this.note = JSON.parse(JSON.stringify(this.populateWith))
+            note: JSON.parse(JSON.stringify(this.populateWith))
         }
     },
     methods: {
         updateNote (note) {
-            if (this.populateWith) {
-                axios.put('/api/workorders/notes/' + note.noteid, note)
-                    .then((response) => {
-                        hideModal()
-                    })
-            } else {
-                axios.post('/api/workorders/notes', note)
-                    .then((response) => {
-                        hideModal()
-                    })
-            }
+            axios.put('/api/workorders/notes/' + note.noteid, note)
+                .then((response) => {
+                    hideModal()
+                })
         },
         hideModal () {
             $('#'+this.modalId).modal('hide')

+ 27 - 3
resources/js/components/notes.vue

@@ -1,7 +1,18 @@
 <template>
     <ul class="list-unstyled">
-        <note-form-modal :modal-id="'note'+noteType+'CreateModal'" :note-type="noteType" :woid="woid" :note-user="authusername"></note-form-modal>
-        <button type="button" data-toggle="modal" :data-target="'#note'+noteType+'CreateModal'" class="btn btn-primary"><i class="fas fa-fw fa-plus"></i> Add New Note</button>
+            <div class="row">
+                <div class="col-md-2 d-flex justify-content-center justify-content-md-start">
+                    <button type="button" data-toggle="collapse" :data-target="'#note'+noteType+'add'" class="btn btn-primary m-2"><i class="fas fa-fw fa-plus"></i> Add New Note</button>
+                </div>
+                <div class="col-md-10">
+                    <div class="collapse" :id="'note'+noteType+'add'">
+                        <div class="d-flex flex-wrap flex-md-nowrap justify-content-center">
+                            <textarea :name="'newnote'+noteType" :id="'newnote'+noteType" class="form-control" v-model="newNote.thenote"></textarea>
+                            <button type="button" class="btn btn-secondary m-2" @click="createNote()">Save</button>
+                        </div>
+                    </div>
+                </div>
+            </div>
         <li class="row no-gutters mb-2" v-bind:key="index" v-for="(note, index) in this.notes">
             <note-form-modal :modal-id="'note'+note.noteid+'editModal'" :populate-with="note"></note-form-modal>
             <div class="col-md-1 d-flex flex-column mx-md-3" :class="setOrder(index)">
@@ -33,7 +44,13 @@ export default {
     data () {
         return {
             notes: Object.values(this.initialnotes),
-            currentOrder: 'order-first'
+            currentOrder: 'order-first',
+            newNote: {
+                notetype: this.noteType,
+                thenote: '',
+                noteuser: this.authusername,
+                woid: this.woid
+            }
         }
     },
     methods: {
@@ -48,6 +65,13 @@ export default {
                 }
             }
             return this.currentOrder
+        },
+        createNote () {
+            axios.post('/api/workorders/notes', this.newNote)
+                    .then((response) => {
+                        $('#note'+this.noteType+'add').collapse('hide')
+                        this.newNote.thenote = ''
+                    })
         }
     }
 }