(window.webpackJsonp=window.webpackJsonp||[]).push([[4,3],{362:function(t,e,n){"use strict";n.r(e);var o={name:"Header",props:["page"]},l=n(115),component=Object(l.a)(o,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",[n("b-navbar",{attrs:{toggleable:"lg",type:"dark",variant:"info"}},[n("b-navbar-brand",{staticClass:"font-weight-bold",attrs:{href:"#"}},[t._v("FAKE TODO")]),t._v(" "),n("b-navbar-toggle",{attrs:{target:"nav-collapse"}}),t._v(" "),n("b-collapse",{attrs:{id:"nav-collapse","is-nav":""}},[n("b-navbar-nav",{staticClass:"ml-auto"},[n("b-nav-item",{staticClass:"font-weight-bold",attrs:{href:"#",id:"btn-sync-todo"}},[n("span",{staticClass:"fa fa-sync-alt"}),t._v(" Sync\n ")])],1)],1)],1)],1)}),[],!1,null,"5a3d4068",null);e.default=component.exports},382:function(t,e,n){"use strict";n.r(e);n(12),n(16),n(206);var o=n(363),l=n.n(o),r=n(27),d=n(160);r.default.use(d.a);var c=n(381),m=r.default.extend({name:"IndexPage",data:function(){return{page:{title:"Homepage"},todos:[],addItemModal:!0,nameState:!1,nameValue:"",nameError:""}},mounted:function(){var t=this,e=this,n=function(){return e.fetchTodos((function(n){var o=n.data.data;o.forEach((function(t){t.isDisabled=1===t.status})),e.todos=o,t.$bvToast.toast("Todo contents have been synchronized",{title:"Todo Sync",variant:"success",solid:!0})}),(function(){}))};document.getElementById("btn-sync-todo").addEventListener("click",n),n()},methods:{validateInput:function(){return this.nameValue.length<3?(this.nameState=!1,this.nameError="Name must be at least 3 characters",!1):this.nameValue.length>100?(this.nameState=!0,this.nameError="Name must be less than 100 characters",!1):(this.nameState=!0,this.nameError="",!0)},fetchTodos:function(t,e){l()({method:"get",url:"http://localhost:8000/api/todos",responseType:"stream"}).then(t).catch(e)},addItem:function(){var t=this;this.validateInput()&&c.ajax({method:"POST",url:"http://localhost:8000/api/todos",data:{userId:1,title:t.nameValue},success:function(e){t.todos.push(e.data),t.addItemModal=!1},error:function(t){if(422===t.status)for(var e in t.responseJSON)t.responseJSON.hasOwnProperty(e)&&(this.nameError=t.responseJSON[e][0])}})},removeItem:function(t){var e=this;c.ajax({method:"GET",url:"http://localhost:8000/api/todos/".concat(t.id,"/delete"),success:function(n){console.log(n,t.id),e.todos.splice(e.todos.indexOf(t),1)}})},syncTodo:function(t){c.ajax({method:"POST",url:"http://localhost:8000/api/todos/".concat(t.id,"/put"),data:{status:t.isDisabled?1:0},success:function(t){console.log(t)}})}}}),v=n(115),component=Object(v.a)(m,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",[n("Header",{attrs:{page:t.page}}),t._v(" "),n("div",{staticClass:"row d-flex justify-content-center mt-4"},[n("div",{staticClass:"col-md-7"},[n("div",{staticClass:"card"},[n("div",{staticClass:"card-header text-uppercase font-weight-bold d-flex justify-content-between"},[n("span",{staticClass:"mt-2"},[t._v("Todo Application")]),t._v(" "),n("b-button",{directives:[{name:"b-modal",rawName:"v-b-modal.modalPopover",modifiers:{modalPopover:!0}}],staticClass:"font-weight-bold z-depth-0",attrs:{variant:"primary",size:"sm"}},[n("i",{staticClass:"fa fa-plus"}),t._v(" Add\n ")])],1),t._v(" "),n("div",{staticClass:"card-body"},[n("div",{staticClass:"table-responsive table-responsive-md"},[n("table",{staticClass:"table table-bordered table-striped table-hover"},[t._m(0),t._v(" "),n("tbody",t._l(t.todos,(function(e){return n("tr",[n("td",[n("i",{staticClass:"fa fa-file-alt"}),t._v(" "+t._s(e.title)+"\n ")]),t._v(" "),n("td",[n("b-form-checkbox",{attrs:{name:"check-button",switch:""},on:{change:function(n){return t.syncTodo(e)}},model:{value:e.isDisabled,callback:function(n){t.$set(e,"isDisabled",n)},expression:"todo.isDisabled"}},[t._v("\n "+t._s(e.isDisabled?"Completed":"Pending")+"\n ")])],1),t._v(" "),n("td",[n("a",{staticClass:"btn btn-sm text-danger font-weight-bold hover z-depth-0",attrs:{href:"#"},on:{click:function(n){return n.preventDefault(),t.removeItem(e)}}},[n("i",{staticClass:"fa fa-minus"}),t._v(" Remove\n ")])])])})),0)])])])])])]),t._v(" "),n("div",[n("b-modal",{attrs:{id:"modalPopover",title:"Add Item","ok-only":"","hide-footer":""},model:{value:t.addItemModal,callback:function(e){t.addItemModal=e},expression:"addItemModal"}},[n("form",{attrs:{method:"post"},on:{submit:function(e){return e.preventDefault(),t.addItem.apply(null,arguments)}}},[n("b-form-input",{attrs:{placeholder:"Enter your name",state:t.nameState,"aria-describedby":"input-live-help input-live-feedback",trim:""},on:{input:t.validateInput},model:{value:t.nameValue,callback:function(e){t.nameValue=e},expression:"nameValue"}}),t._v(" "),n("b-form-invalid-feedback",{attrs:{id:"input-live-feedback"}},[t._v(t._s(t.nameError))]),t._v(" "),n("div",{staticClass:"text-right"},[n("button",{staticClass:"btn btn-sm btn-primary font-weight-bold mx-0 z-depth-0",attrs:{type:"submit"}},[t._v("Save\n ")])])],1)])],1)],1)}),[function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("thead",[n("tr",[n("th",{staticClass:"text-uppercase font-weight-bold"},[t._v("Title")]),t._v(" "),n("th",{staticClass:"text-uppercase font-weight-bold"},[t._v("State")]),t._v(" "),n("th",{staticClass:"text-uppercase font-weight-bold"},[t._v("Action")])])])}],!1,null,null,null);e.default=component.exports;installComponents(component,{Header:n(362).default})}}]);
|