@@ -5,13 +5,20 @@ import BoardEdit from './BoardEdit.vue'; | |||||
import Add2Board from './pin_edit/Add2Board.vue'; | import Add2Board from './pin_edit/Add2Board.vue'; | ||||
function openPinEdit(vm, props = null) { | |||||
function openPinEdit(vm, props = null, onCreated = null) { | |||||
vm.$buefy.modal.open( | vm.$buefy.modal.open( | ||||
{ | { | ||||
parent: vm, | parent: vm, | ||||
component: PinCreateModal, | component: PinCreateModal, | ||||
props, | props, | ||||
hasModalCard: true, | hasModalCard: true, | ||||
events: { | |||||
pinCreated() { | |||||
if (onCreated !== null) { | |||||
onCreated(); | |||||
} | |||||
}, | |||||
}, | |||||
}, | }, | ||||
); | ); | ||||
} | } | ||||
@@ -92,7 +92,7 @@ import bus from '../utils/bus'; | |||||
import ModelForm from '../utils/ModelForm'; | import ModelForm from '../utils/ModelForm'; | ||||
function isURLBlank(url) { | function isURLBlank(url) { | ||||
return url !== null && url !== ''; | |||||
return url !== null && url === ''; | |||||
} | } | ||||
const fields = ['url', 'referer', 'description', 'tags']; | const fields = ['url', 'referer', 'description', 'tags']; | ||||
@@ -100,6 +100,10 @@ const fields = ['url', 'referer', 'description', 'tags']; | |||||
export default { | export default { | ||||
name: 'PinCreateModal', | name: 'PinCreateModal', | ||||
props: { | props: { | ||||
fromUrl: { | |||||
type: Object, | |||||
default: null, | |||||
}, | |||||
username: { | username: { | ||||
type: String, | type: String, | ||||
default: null, | default: null, | ||||
@@ -142,6 +146,11 @@ export default { | |||||
this.pinModel.form.description.value = this.existedPin.description; | this.pinModel.form.description.value = this.existedPin.description; | ||||
this.pinModel.form.tags.value = this.existedPin.tags; | this.pinModel.form.tags.value = this.existedPin.tags; | ||||
} | } | ||||
if (this.fromUrl) { | |||||
this.pinModel.form.url.value = this.fromUrl.url; | |||||
this.pinModel.form.referer.value = this.fromUrl.referer; | |||||
this.pinModel.form.description.value = this.fromUrl.description; | |||||
} | |||||
}, | }, | ||||
methods: { | methods: { | ||||
fetchBoardList() { | fetchBoardList() { | ||||
@@ -6,6 +6,7 @@ import Pins4User from '../views/Pins4User.vue'; | |||||
import Pins4Board from '../views/Pins4Board.vue'; | import Pins4Board from '../views/Pins4Board.vue'; | ||||
import Pins4Id from '../views/Pins4Id.vue'; | import Pins4Id from '../views/Pins4Id.vue'; | ||||
import Boards4User from '../views/Boards4User.vue'; | import Boards4User from '../views/Boards4User.vue'; | ||||
import PinCreate from '../views/PinCreate.vue'; | |||||
Vue.use(VueRouter); | Vue.use(VueRouter); | ||||
@@ -40,6 +41,11 @@ const routes = [ | |||||
name: 'boards4user', | name: 'boards4user', | ||||
component: Boards4User, | component: Boards4User, | ||||
}, | }, | ||||
{ | |||||
path: '/pin-creation/from-url', | |||||
name: 'pin-creation-from-url', | |||||
component: PinCreate, | |||||
}, | |||||
]; | ]; | ||||
const router = new VueRouter({ | const router = new VueRouter({ | ||||
@@ -5,10 +5,58 @@ | |||||
</template> | </template> | ||||
<script> | <script> | ||||
// import PinCreateModal from './PinCreateModal.vue'; | |||||
import modals from '../components/modals'; | |||||
import API from '../components/api'; | |||||
export default { | export default { | ||||
name: 'PinCreate', | |||||
name: 'PinCreateFromURL', | |||||
data() { | |||||
return { | |||||
meta: { | |||||
url: null, | |||||
referer: null, | |||||
description: null, | |||||
}, | |||||
user: { | |||||
loggedIn: false, | |||||
meta: null, | |||||
}, | |||||
}; | |||||
}, | |||||
methods: { | |||||
initialize(force = false) { | |||||
const self = this; | |||||
API.User.fetchUserInfo(force).then( | |||||
(user) => { | |||||
if (user === null) { | |||||
self.user.loggedIn = false; | |||||
self.user.meta = {}; | |||||
} else { | |||||
self.user.meta = user; | |||||
self.user.loggedIn = true; | |||||
self.createPin(); | |||||
} | |||||
}, | |||||
); | |||||
}, | |||||
onCreated() { | |||||
this.$buefy.dialog.alert( | |||||
'Please turn off this page by hand since ' | |||||
+ 'Javascript has no permission to do this', | |||||
); | |||||
}, | |||||
createPin() { | |||||
modals.openPinEdit( | |||||
this, | |||||
{ username: this.user.meta.username, fromUrl: this.meta }, | |||||
this.onCreated, | |||||
); | |||||
}, | |||||
}, | |||||
created() { | |||||
this.meta = this.$route.query; | |||||
this.initialize(); | |||||
}, | |||||
}; | }; | ||||
</script> | </script> | ||||