Created
August 14, 2018 13:06
-
-
Save themodernpk/f1c935d70693c6ad788ea314470f9fff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('meta[name=csrf-token]').getAttribute('content'); | |
//#########################Vue################################################# | |
const app = new VueCommon({ | |
el: '#app', | |
data: { | |
urls : [], | |
practice : { | |
product_line_id : 2 | |
}, | |
file : '', | |
files :[], | |
image_name : "", | |
product_lines : [], | |
prefix : [], | |
suffix : [], | |
roles : [], | |
is_practice_added : false, | |
locations : [], | |
doctors : [], | |
formatMobile: null, | |
practiceMobile: null, | |
doctorMobile : null, | |
}, | |
mounted: function () { | |
this.urls.base = $('base').attr('href'); | |
let url = window.location.href; | |
url = url.slice(0, url.lastIndexOf('/')); | |
this.urls.current = url; | |
this.getAsset(); | |
/* this.practice = { | |
product_line_id : 2 | |
};*/ | |
let vm = this; | |
window.onbeforeunload = function() { | |
return vm.deletePracticeData(); | |
} | |
// console.warn(this.doctor); | |
// this.init(); | |
}, | |
watch:{ | |
practiceMobile : function (val) { | |
if(val) | |
{ | |
// console.log(phone) | |
var numbers = val.replace(/\D/g, ''), | |
char = {0:'(',3:') ',6:'-'}; | |
var phone_format = ""; | |
for (var i = 0; i < numbers.length; i++) { | |
phone_format += (char[i]||'') + numbers[i]; | |
} | |
this.formatMobile = phone_format; | |
} else { | |
this.formatMobile = null; | |
} | |
this.practiceMobile = this.formatMobile; | |
this.practice.phone = this.formatMobile; | |
}, | |
}, | |
methods:{ | |
//--------------------------------------------------------------------- | |
getAsset : function () { | |
let url = this.urls.current+'/assets'; | |
this.processHttpRequest(url, '', this.afterAsset); | |
}, | |
//--------------------------------------------------------------------- | |
afterAsset : function (data) { | |
this.product_lines = data.lines; | |
this.prefix = data.prefix; | |
this.suffix = data.suffix; | |
this.roles = data.roles; | |
NProgress.done(); | |
}, | |
//--------------------------------------------------------------------- | |
store : function (event, field) { | |
if (event){ | |
event.preventDefault(); | |
} | |
/*if (this.image_name==='' || (!this.image_name)){ | |
alertify.error("Please upload product image"); | |
return; | |
}*/ | |
let url = this.urls.current+"/store"; | |
this.practice.field = field; | |
this.processHttpRequest(url, this.practice, this.afterStore); | |
/* if (this.image_name.split('.').pop().toLowerCase()==="jpg" || this.image_name.split('.').pop().toLowerCase()==="png") { | |
return; | |
} | |
alertify.error("Please Upload image with png and jpg");*/ | |
}, | |
//--------------------------------------------------------------------- | |
uploadFile : function (event) { | |
event.preventDefault(); | |
// let file = this.$refs.files.files[0]; | |
// console.warn(this.image_name, this.file) | |
let formData = new FormData(); | |
// let fileName = file.name; | |
let file_name = this.image_name.substr(0, this.image_name.indexOf('.')); | |
formData.append('file', this.file); | |
formData.append('name', Date.now()+"_"+file_name); | |
formData.append('dir','practice/logo'); | |
let url = this.urls.current+"/upload"; | |
if (this.image_name.split('.').pop().toLowerCase()==="jpg" || this.image_name.split('.').pop().toLowerCase()==="png"){ | |
// console.log(file); | |
this.processHttpRequest(url, formData, this.uploadAfter); | |
return; | |
} | |
alertify.error("Please Upload image with png and jpg"); | |
}, | |
//--------------------------------------------------------------------- | |
handleImage: function (event) { | |
event.preventDefault(); | |
this.file = this.$refs.files.files[0]; | |
this.image_name = this.file.name; | |
this.uploadFile(event) | |
}, | |
//--------------------------------------------------------------------- | |
afterStore: function (data) { | |
if(!data.product_line_id) | |
{ | |
data.product_line_id = ""; | |
} | |
if (data.id){ | |
this.practice = {}; | |
this.locations = []; | |
this.doctors = []; | |
this.practice = data; | |
this.practiceMobile = this.practice.phone; | |
this.locations = data.locations; | |
this.doctors = data.doctors; | |
} | |
this.$nextTick(() => { | |
$('.phone-formatter').formatter({ | |
'pattern': '([[999]]) [[999]]-[[9999]]', | |
'persistent': true | |
}); | |
}); | |
NProgress.done(); | |
// window.location = data | |
}, | |
//--------------------------------------------------------------------- | |
uploadAfter : function (data) { | |
this.practice.practice_logo = data; | |
this.store(null, 'practice_logo'); | |
NProgress.done(); | |
}, | |
//--------------------------------------------------------------------- | |
lineName : function (id) { | |
let lineName = ""; | |
$.each(this.product_lines, function(key, value) { | |
if (value.id === id){ | |
lineName = value.name; | |
} | |
}); | |
return lineName+" "; | |
}, | |
//--------------------------------------------------------------------- | |
formatSKU : function (sku) { | |
sku = sku.split(" ").join(""); | |
return sku; | |
}, | |
//--------------------------------------------------------------------- | |
storeFields : function (event, field, item, table) { | |
event.preventDefault(); | |
let url = this.urls.current+"/store/fields"; | |
item.field = field; | |
item.table = table; | |
if (field === 'new'){ | |
item = { | |
se_practice_id : this.practice.id, | |
field : field, | |
table : table, | |
} | |
} | |
this.processHttpRequest(url, item, this.afterStore); | |
}, | |
//--------------------------------------------------------------------- | |
deleteItem : function (event, id, table) { | |
event.preventDefault(); | |
let url = this.urls.current+"/delete"; | |
let params = { | |
id : id, | |
table : table, | |
se_practice_id : this.practice.id | |
}; | |
this.processHttpRequest(url, params, this.afterStore); | |
}, | |
//--------------------------------------------------------------------- | |
submit : function (event) { | |
if (event){ | |
event.preventDefault(); | |
} | |
let url = this.urls.current+"/submit"; | |
this.processHttpRequest(url, {se_practice_id : this.practice.id}, this.afterSubmit); | |
}, | |
//--------------------------------------------------------------------- | |
afterSubmit : function (data) { | |
this.is_practice_added = true; | |
NProgress.done(); | |
window.location = data.redirect_url; | |
}, | |
//--------------------------------------------------------------------- | |
deletePracticeData : function () { | |
if (this.practice){ | |
if (this.practice.id && !this.is_practice_added){ | |
let url = this.urls.current+"/delete/practice"; | |
this.processHttpRequest(url, {se_practice_id : this.practice.id}, this.afterDelete); | |
} | |
} | |
}, | |
//--------------------------------------------------------------------- | |
afterDelete : function (data) { | |
NProgress.done(); | |
}, | |
//--------------------------------------------------------------------- | |
//--------------------------------------------------------------------- | |
//--------------------------------------------------------------------- | |
//--------------------------------------------------------------------- | |
} | |
}); | |
//#########################jQuery############################################## | |
(function (document, window, $) { | |
})(document, window, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment