Created
July 16, 2019 12:06
-
-
Save esmeromichael/4ca9e94224f11990b8e4eef10af9dcfe to your computer and use it in GitHub Desktop.
x
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
$('.save_brand').on('click', function(e){ | |
var me = $(this); | |
e.preventDefault(); | |
var brand_id = $('.brand_id option:selected').val() | |
var category_id = $('.category_id').val(); | |
var name = $('#name').val(); | |
if(!brand_id){ | |
notify('danger', 'Please select brand'); | |
return false; | |
} | |
else if(!category_id){ | |
notify('danger', 'Please select category.'); | |
return false; | |
} | |
else if(name == ""){ | |
notify('danger', 'Please fill name.'); | |
return false; | |
} | |
if ( me.data('requestRunning') ) { | |
return; | |
} | |
me.data('requestRunning', true); | |
$.ajax({ | |
// url: '/admin/corporate/save', | |
url : BASE_URL+"/admin/menuitem/save", | |
type: 'post', | |
data: $('#add_edit_menu_form').serialize(), | |
cache: false, | |
success: function(data){ | |
if(data.success){ | |
$('#data_action').val('edit'); | |
$('#menuitem_id').val(data.item.id); | |
$('#recipe_image_placeholder').html(''); | |
$('#recipe_image_placeholder').html(setImageHTML(null)); | |
$('#uploading').hide(); | |
//avatar upload | |
$("input[name='uploadImage']").change(function () { | |
if (this.files.length > 0) { | |
if (!window.FormData) { | |
alert("Your browser does not support FormData object."); | |
return false; | |
} | |
//console.log(this.form); return; | |
$.ajax({ | |
url: BASE_URL+"/admin/menuitem/save-image", | |
method: 'POST', | |
dataType: 'json', | |
data: new FormData(this.form), | |
contentType: false, | |
processData: false, | |
beforeSend: function () { | |
//Pace.start; | |
$('#uploading').show(); | |
}, | |
success: function (data) { | |
if (data.success) { | |
var uploaded_url = data.image_url; | |
$(".avatar_img .embed-avatar .img-avatar").css({"background": "url('" + uploaded_url + "') no-repeat center"}); | |
}else{ | |
} | |
}, | |
complete: function () { | |
//Pace.stop; | |
$('#uploading').hide(); | |
}, | |
error: function () { | |
$('#uploading').hide(); | |
} | |
}); | |
} | |
}); | |
notify('success', data.message); | |
} | |
else{ | |
notify('warning', data.message); | |
} | |
}, | |
complete: function() { | |
me.data('requestRunning', false); | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment