797 lines
29 KiB
JavaScript
797 lines
29 KiB
JavaScript
if(typeof Supplier==='undefined'){
|
|
class Supplier extends DataModel{
|
|
|
|
/*
|
|
* Constructor
|
|
*/
|
|
constructor (data,options) {
|
|
super(data,options)
|
|
if(typeof this.contact ==="undefined"){
|
|
this.contact=[];
|
|
}
|
|
console.log('Supplier constructor called');
|
|
};
|
|
};
|
|
window.Supplier=Supplier;
|
|
}
|
|
|
|
|
|
window.SupplierAdmin=function (options,SupplierItem) {
|
|
/*
|
|
* Variables accessible
|
|
* in the class
|
|
*/
|
|
let Opts = {
|
|
token:null,
|
|
containerCssSelector: '.containerSupplier',
|
|
testMode:false,
|
|
URL:{
|
|
getDataTableContent:'',
|
|
index:'',
|
|
show:'',
|
|
edit:'',
|
|
create:'',
|
|
store:'',
|
|
update:'',
|
|
destroy:'',
|
|
attachFile:'',
|
|
detachFile:'',
|
|
},
|
|
dataTable:{
|
|
orderDirective:[1, 'asc']
|
|
},
|
|
onAfterInitViewDetails:function (){}
|
|
};
|
|
let Supplier = {};
|
|
let root = this;
|
|
let contactPopupWorkflow='new';
|
|
/*
|
|
* Constructor
|
|
*/
|
|
this.construct = function (options,SupplierItem) {
|
|
console.log('SupplierAdmin constructor called');
|
|
$.extend(Opts, options);
|
|
if(!SupplierItem){
|
|
console.log('supplier letre kellet hozni ');
|
|
if(!APP.Supplier){
|
|
APP.Supplier=new window.Supplier();
|
|
}
|
|
root.Supplier=APP.Supplier;
|
|
}
|
|
};
|
|
this.getOpts=function (){
|
|
return Opts;
|
|
}
|
|
|
|
this.formDataToDataObjectAPICallOld= function (CSSSelector) {
|
|
let data = new FormData(document.querySelector(CSSSelector));
|
|
//let formJSON = Object.fromEntries(data.entries());
|
|
var formJSON = {};
|
|
data.forEach((value, key) => {
|
|
// Reflect.has in favor of: formJSON.hasOwnProperty(key)
|
|
if(!Reflect.has(formJSON, key)){
|
|
formJSON[key] = value;
|
|
return;
|
|
}
|
|
if(!Array.isArray(formJSON[key])){
|
|
formJSON[key] = [formJSON[key]];
|
|
}
|
|
formJSON[key].push(value);
|
|
});
|
|
|
|
$(CSSSelector+' input[data-inputmask]').each(function (){
|
|
if(formJSON[$(this).attr('name')]){
|
|
formJSON[$(this).attr('name')]=formJSON[$(this).attr('name')].replace(/[_ ]+$/g,"");
|
|
}
|
|
});
|
|
//formJSON.productGroups=$(".productCategorySelect").select2().val();
|
|
|
|
|
|
/*Multiselect or checkbox to array:
|
|
ajaxData['productGroup']=$(".productCategorySelect").select2().val();
|
|
|
|
formJSON.multiselectName = data.getAll('multiselectName');
|
|
$.each(formJSON, function (item, value) {
|
|
formJSON[$.lcFirst(item.replace('contact', ''))] = value;
|
|
delete formJSON[item];
|
|
});
|
|
if(formJSON.phone){
|
|
formJSON.phone=formJSON.phone.replaceAll('_','');
|
|
}
|
|
if(formJSON.email){
|
|
formJSON.email=formJSON.email.replaceAll('_','');
|
|
}
|
|
*/
|
|
return formJSON;
|
|
}
|
|
|
|
this.formDataToDataObjectAPICall = function (CSSSelectorForm) {
|
|
let ajaxData=new FormData($(CSSSelectorForm)[0]);
|
|
$.each(ajaxData.getAll('profitCenter'),function(key,value){
|
|
ajaxData.append('profitCenter[]',value);
|
|
})
|
|
$.each(ajaxData.getAll('productGroup'),function(key,value){
|
|
ajaxData.append('productGroup[]',value);
|
|
})
|
|
$.each(ajaxData.getAll('supplierService'),function(key,value){
|
|
ajaxData.append('supplierService[]',value);
|
|
})
|
|
$.each(ajaxData.getAll('contactId'),function(key,value){
|
|
ajaxData.append('contactId[]',value);
|
|
})
|
|
|
|
ajaxData.append('_token',$('input[name=_token]').val());
|
|
|
|
$(CSSSelectorForm+' input[data-inputmask]').each(function (){
|
|
let indexKey=$(this).attr('name');
|
|
if(ajaxData.get(indexKey)){
|
|
ajaxData.set(indexKey,ajaxData.get(indexKey).replace(/[_ ]+$/g,""));
|
|
}
|
|
});
|
|
|
|
return ajaxData;
|
|
}
|
|
|
|
this.clickSaveButton=function (event) {
|
|
debug('Save clicked');
|
|
let CSSSelectorForm=Opts.containerCssSelector+' .supplierForm';
|
|
event.preventDefault();
|
|
if ($(CSSSelectorForm+' input[name="canSeeInOrder"]').val()==1 && $(CSSSelectorForm)[0].checkValidity() === false) {
|
|
console.log('validaton false');
|
|
event.stopPropagation();
|
|
return;
|
|
} else {
|
|
console.log('validaton ok');
|
|
//do your ajax submition here
|
|
}
|
|
let ajaxData=root.formDataToDataObjectAPICall(CSSSelectorForm);
|
|
|
|
|
|
|
|
let ajaxUrl=Opts.URL.store;
|
|
let ajaxMethod="POST";
|
|
if(root.Supplier.id){
|
|
ajaxUrl=Opts.URL.update.replace('%id%',root.Supplier.id);
|
|
//ajaxMethod="PUT";
|
|
//ajaxData=new FormData($(CSSSelectorForm)[0]);
|
|
ajaxData.append('_method','PUT');
|
|
}
|
|
|
|
debug(ajaxMethod);
|
|
debug(ajaxData);
|
|
|
|
$.ajax({
|
|
url:ajaxUrl,
|
|
data:ajaxData,
|
|
type:ajaxMethod,
|
|
contentType:false,
|
|
processData: false,
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('input[name="_token"]').val()
|
|
},
|
|
|
|
success:function (data){
|
|
debug('d1: Save success ');
|
|
debug(data);
|
|
if(data.success==true){
|
|
|
|
//Opts.onAfterInitViewDetails=root.autofillDetails;
|
|
Opts.dataTable.orderDirective=[0, 'desc'];
|
|
Toast.create("Sikeres rögzítés!", ajaxData.get('name')+" nevű beszálllító elmentve", TOAST_STATUS.SUCCESS,5000);
|
|
APP.loadMainContent(Opts.URL.index+'?init=0',root.initViewList);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
this.setDetailsViewData=function () {
|
|
debug('setDetailsViewData');
|
|
console.log(Supplier);
|
|
let CSSSelectorForm=Opts.containerCssSelector+' .supplierForm';
|
|
let needToSet=[
|
|
'name','hooreycaId','nameId',
|
|
'orderEmail','orderEmail2','address','mailingAddress','phone','fax','customerServicePhone',
|
|
'name22',
|
|
'openHours', 'ordersDeadline', 'minOrderValue',
|
|
];
|
|
$.each(needToSet,function () {
|
|
if(typeof root.Supplier[this]!='undefined'){
|
|
$(CSSSelectorForm+' input[name='+this+']').val(root.Supplier[this]);
|
|
$(CSSSelectorForm+' textarea[name='+this+']').val(root.Supplier[this]);
|
|
}
|
|
})
|
|
if(typeof root.Supplier['note']!='undefined'){
|
|
$(CSSSelectorForm+' textarea[name=note]').val(root.Supplier.note);
|
|
}
|
|
if(typeof root.Supplier['emailAttachmentType']!='undefined'){
|
|
$(CSSSelectorForm+' input[name=emailAttachmentType][value='+root.Supplier['emailAttachmentType']+']').prop('checked',true);
|
|
}
|
|
$(CSSSelectorForm+' *[data-toggle=canSee][data-title='+root.Supplier.canSee+']').click();
|
|
$(CSSSelectorForm+' *[data-toggle=canSeeInOrder][data-title='+root.Supplier.canSeeInOrder+']').click();
|
|
$(CSSSelectorForm+' *[data-toggle=hooreycaDataActive][data-title='+root.Supplier.hooreycaDataActive+']').click();
|
|
let productGroup=[];
|
|
$.each(root.Supplier.product_group,function () {
|
|
productGroup.push(this.name);
|
|
});
|
|
$(CSSSelectorForm+' .productCategorySelect').val(productGroup).change();
|
|
|
|
let service=[];
|
|
$.each(root.Supplier.service,function () {
|
|
service.push(this.name);
|
|
});
|
|
$(CSSSelectorForm+' .serviceSelect').val(service).change();
|
|
|
|
let profitCenter=[];
|
|
$.each(root.Supplier.profit_center,function () {
|
|
profitCenter.push(this.name);
|
|
});
|
|
//$(CSSSelectorForm+' .profitCenterSelect').val(profitCenter).change();
|
|
//debug(profitCenter);
|
|
$.each(profitCenter,function () {
|
|
$('input[value="'+$.escapeSelector(this)+'"]').prop( "checked", true );
|
|
})
|
|
|
|
if(typeof root.Supplier['logoFile']!='undefined' && (root.Supplier['logoFile'])){
|
|
$(CSSSelectorForm+' img.imageLogo').attr('src',root.Supplier['logoFile']);
|
|
}
|
|
|
|
//debug(APP.SupplierAdmin.formDataToDataObjectAPICall('.supplierForm')['productGroup']);
|
|
//$('[name=productGroup]').val(['Büféáru_édesipari_termékek','Tojás']).change();
|
|
//root.setDetailsViewData();
|
|
}
|
|
this.initViewDetails=function (options,SupplierItem){
|
|
debug('**call initViewDetails ');
|
|
if(!APP.ContactPopUp){
|
|
console.log('nincs APP.ContactPopUp')
|
|
APP.ContactPopUp = new window.ContactPopUp();
|
|
}else{
|
|
console.log('mar van APP.ContactPopUp')
|
|
}
|
|
APP.ContactPopUp.init({
|
|
active:true,
|
|
onAfterSave:root.contactAction
|
|
});
|
|
root.renderContact();
|
|
$('.supplierForm .buttonNewContact').bind('click',function (){
|
|
APP.SupplierAdmin.setContactPopupWorkflow('new');
|
|
APP.ContactPopUp.clearData();
|
|
APP.ContactPopUp.show();
|
|
});
|
|
$('[data-toggle="tooltip"]').tooltip();
|
|
initRadioButtons();
|
|
$(":input").inputmask({
|
|
"onincomplete": function () {
|
|
console.log($(this).data('required'));
|
|
if ($(this).val().length > 0 || $(this).data('required') === true) {
|
|
$(this).addClass('is-invalid');
|
|
}
|
|
},
|
|
"oncomplete": function () {
|
|
$(this).removeClass('is-invalid');
|
|
$(this).addClass('is-valid');
|
|
},
|
|
"oncleared": function () {
|
|
console.log('cleared');
|
|
$(this).removeClass('is-invalid');
|
|
}
|
|
});
|
|
|
|
$('form.supplierForm button.FormSaveButton').off('click');
|
|
$('form.supplierForm button.FormSaveButton').on('click',root.clickSaveButton);
|
|
root.setDetailsViewData();
|
|
$(".productCategorySelect").select2();
|
|
$(".serviceSelect").select2({
|
|
tags: true,
|
|
createTag: function (params) {
|
|
let term = $.trim(params.term);
|
|
|
|
if (term === '') {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
id: term,
|
|
text: term,
|
|
newTag: true // add additional parameters
|
|
}
|
|
}
|
|
});
|
|
|
|
//$(".profitCenterSelect").select2();
|
|
$("input[name=logoFile]").change(function(){
|
|
setImageFromLocal(this,Opts.containerCssSelector+' .imageLogo');
|
|
});
|
|
|
|
$('form.supplierForm .profitCenterSelectCheckboxAll').off('click');
|
|
$('form.supplierForm .profitCenterSelectCheckboxAll').on('click',function () {
|
|
//console.log();
|
|
//let checked=$(this).is(":checked")
|
|
$('form.supplierForm input.profitCenterSelectCheckbox').prop('checked',$(this).is(":checked"));
|
|
});
|
|
root.renderAttachment();
|
|
//Opts.onAfterInitViewDetails();
|
|
root.initFileAttachmentFeature();
|
|
debug('**end initViewDetails ');
|
|
}
|
|
|
|
this.selectedUploadFileToggle=function (fileInput){
|
|
/*
|
|
console.log(fileInput.attr('name'));
|
|
console.log(fileInput[0].files[0]);
|
|
console.log(fileInput[0].files[0].name);
|
|
*/
|
|
if(fileInput){
|
|
$('.containerFileUpload').addClass('d-none');
|
|
if(fileInput[0].files[0]){
|
|
$('.containerUploadedFileName').text(fileInput[0].files[0].name);
|
|
|
|
}
|
|
$('.containerFileUploadStarted').removeClass('d-none');
|
|
$('.containerUploadedSpinner').removeClass('d-none');
|
|
}else{
|
|
$('.containerUploadedFileName').text('');
|
|
$('.custom-file-label.selected').text('');
|
|
$('.containerFileUploadStarted').addClass('d-none');
|
|
$('.uploadStatusRow').addClass('d-none');
|
|
$('.containerFileUpload').removeClass('d-none');
|
|
}
|
|
}
|
|
|
|
this.initFileAttachmentFeature=function () {
|
|
console.log('-------initFileAttachmentFeature-----------');
|
|
if(root.Supplier.id){
|
|
$('.containerFileUpload').removeClass('d-none');
|
|
$('.containerFileUploadNone').addClass('d-none');
|
|
}
|
|
|
|
|
|
$(Opts.containerCssSelector+' .buttonUpload').off('click');
|
|
$(Opts.containerCssSelector+' .buttonUpload').on('click',function (){
|
|
console.group('-------buttonUpload-----------');
|
|
let fileInput=$('#inputGroupAttacheFile');
|
|
if(fileInput[0].files.length<1){
|
|
Toast.create("Hiba!", 'Vállaszon ki fájlt!', TOAST_STATUS.DANGER, 10000);
|
|
return;
|
|
}
|
|
console.log($(Opts.containerCssSelector).find('form.supplierForm')[0]);
|
|
let data= new FormData($(Opts.containerCssSelector).find('form.supplierForm')[0]);
|
|
data.append(fileInput.attr('name'),fileInput[0].files[0]);
|
|
|
|
root.selectedUploadFileToggle(fileInput);
|
|
let ajaxUrl=Opts.URL.attachFile.replace('%id%',root.Supplier.id);
|
|
|
|
console.groupEnd();
|
|
$.ajax({
|
|
url:ajaxUrl,
|
|
data:data,
|
|
type:'POST',
|
|
contentType:false,
|
|
processData: false,
|
|
beforeSend: function() {
|
|
|
|
},
|
|
success: function(data) {
|
|
console.log(data);
|
|
if(data.success==true){
|
|
root.addAttachment(data.data.attachment);
|
|
root.selectedUploadFileToggle();
|
|
}
|
|
},
|
|
error: function(data) {
|
|
console.log(data.responseJSON);
|
|
root.selectedUploadFileToggle();
|
|
ajaxErrorFieldHandler(data.responseJSON.error);
|
|
}
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.clickNew=function () {
|
|
debug('clickNew');
|
|
APP.loadMainContent(Opts.URL.create,root.clickNewCallBack);
|
|
}
|
|
|
|
this.clickNewCallBack=function () {
|
|
debug('callbackNew');
|
|
root.Supplier=new window.Supplier();
|
|
root.initViewDetails();
|
|
}
|
|
this.datatableRowActionEdit=function (rowData,node) {
|
|
console.log('datatableRowActionEdit Called');
|
|
//Opts.onAfterInitViewDetails=root.autofillDetails;
|
|
let ajaxUrl=Opts.URL.edit.replace('%id%',rowData.id);
|
|
APP.loadMainContent(ajaxUrl,root.initViewDetails);
|
|
console.log('datatableRowActionEdit End');
|
|
}
|
|
|
|
this.clickOrderDeleteConfirmed=function (event){
|
|
debug('clickSupplierDeleteConfirmed');
|
|
debug(event);
|
|
debug(event.data);
|
|
$('#dialogModal').modal('hide');
|
|
let ajaxData={};
|
|
ajaxData._token=Opts.token;
|
|
let ajaxUrl=Opts.URL.destroy.replace('%id%',event.data.id);
|
|
ajaxData._token=$('input[name=_token]').val();
|
|
console.log(ajaxUrl);
|
|
console.log(ajaxData);
|
|
let row=$(dataTableCSSSelector).DataTable().row(root.dadatatableRowActionCallerNode.parents('tr'));
|
|
$.ajax({
|
|
url:ajaxUrl,
|
|
data:ajaxData,
|
|
method:"DELETE",
|
|
success:function (data){
|
|
if(data.success==true){
|
|
row.remove().draw();
|
|
root.dadatatableRowActionCallerNode=false;
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
let datatableRowActionCallerNode=false;
|
|
|
|
this.datatableRowActionDelete=function (rowData,node) {
|
|
console.log('datatableRowActionDelete Called');
|
|
root.dadatatableRowActionCallerNode=node;
|
|
$('#dialogModal').on('show.bs.modal', function (event) {
|
|
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
|
|
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
|
|
var modal = $(this);
|
|
modal.find('.modal-title').text('Megerősítés ');
|
|
modal.find('.modal-body').text('Biztosan törli a beszállítót?');
|
|
modal.find('.buttonYes').off('click');
|
|
modal.find('.buttonYes').on('click',{id:rowData.id},root.clickOrderDeleteConfirmed);
|
|
});
|
|
$('#dialogModal').modal('show');
|
|
}
|
|
|
|
this.datatableRowActionButtonClick=function (event){
|
|
debug('datatableRowActionButtonClick');
|
|
let node=$(event[0].currentTarget);
|
|
let row=$(dataTableCSSSelector).DataTable().row(node.parents('tr'));
|
|
let rowData=row.data();
|
|
let actionName='datatableRowAction'+node.data('buttontype').capitalize();
|
|
if (typeof root[actionName] === "function") {
|
|
return root[actionName](rowData,node)
|
|
}
|
|
}
|
|
|
|
this.initViewList = function (options={}) {
|
|
debug('listview inicialization');
|
|
dataTableCSSSelector=Opts.containerCssSelector+' .dataTable'; //
|
|
|
|
let colNum=$(dataTableCSSSelector+' thead th').length; //buttons insert position need
|
|
APP.setOpts({
|
|
datatableActionButtonClickCallBack:root.clickNew,
|
|
datatableRowActionButtonClickCallBack:root.datatableRowActionButtonClick,
|
|
|
|
})
|
|
let orderDirective=Opts.dataTable.orderDirective;
|
|
if(typeof options['orderDirective']!='undefined'){
|
|
orderDirective=options['orderDirective'];
|
|
}
|
|
$(dataTableCSSSelector).DataTable( {
|
|
language: {
|
|
url: '//cdn.datatables.net/plug-ins/1.10.24/i18n/Hungarian.json'
|
|
},
|
|
|
|
//"ajax": "{{asset('exapmle2.json')}}",
|
|
"ajax": Opts.URL.getDataTableContent,
|
|
"columnDefs": [
|
|
{
|
|
"targets": colNum-1,
|
|
"render": function ( data, type, row ) {
|
|
let buttons=APP.datatableAddRowTrashButton(0,arguments);
|
|
buttons+=APP.datatableAddRowEditButton(0,arguments);
|
|
return buttons;
|
|
},
|
|
},
|
|
{
|
|
"targets": 1,
|
|
"render": function ( data, type, row ) {
|
|
return type === "sort" ? data.latinise() : data;
|
|
},
|
|
},
|
|
//{ "visible": false, "targets": [ 0 ] }
|
|
],
|
|
buttons:{
|
|
buttons: [
|
|
'excel','pdf',
|
|
{
|
|
extend: 'print',
|
|
//text: 'Print current page',
|
|
'title': 'title custom text',
|
|
'messageTop': 'Message On Top',
|
|
autoPrint: true
|
|
},
|
|
/**/
|
|
|
|
{
|
|
text: 'Új felvitele',
|
|
className: 'btn btn-success newItem',
|
|
attr:{
|
|
/*
|
|
data:{
|
|
a:1,
|
|
b:2
|
|
|
|
}
|
|
*/
|
|
'data':'newItem'
|
|
},
|
|
init: function(api, node, config) {
|
|
$(node).removeClass('ui-button')
|
|
},
|
|
action: function ( e, dt, node, config ) {
|
|
APP.datatableActionButtonClickCallBack(arguments);
|
|
/* console.log(e);
|
|
console.log(dt);
|
|
console.log(node);
|
|
console.log(config);*/
|
|
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"columns": [
|
|
{ "data": "id" },
|
|
{ "data": "name" },
|
|
{ "data": "hooreycaId" },
|
|
{ "data": "nameId" },
|
|
{ "data": "created_at" },
|
|
null,
|
|
],
|
|
"order": orderDirective,
|
|
"stateSave": true,
|
|
"drawCallback": function( settings ) {
|
|
APP.datatableAddRowAction(dataTableCSSSelector);
|
|
}
|
|
} );
|
|
debug('listview end');
|
|
}
|
|
|
|
this.autofillDetails=function (){
|
|
debug('nyeresre allunk');
|
|
let randomNumber=getRandomInt(9999);
|
|
$('input[name=name]').val('Beszalító'+randomNumber);
|
|
$('input[name=hooreycaId]').val('hb'+randomNumber);
|
|
$('input[name=nameId]').val('be'+randomNumber);
|
|
$('input[name=orderEmail]').val('kapcsolat'+randomNumber+'@beszallito.hu');
|
|
$('input[name=orderEmail2]').val('informacio'+randomNumber+'@beszallito.hu');
|
|
$('input[name=address]').val('8989 Supplier utca '+randomNumber);
|
|
$('input[name=mailingAddress]').val('8989 Postai út'+randomNumber);
|
|
$('input[name=phone]').val('+36301234567');
|
|
$('input[name=fax]').val('36308889999');
|
|
$('input[name=customerServicePhone]').val('+36761234444');
|
|
$('textarea[name=note]').val('Megjegyzem '+randomNumber);
|
|
|
|
}
|
|
this.testMode=function () {
|
|
console.debug('!!!!testmode !!!!');
|
|
root.Supplier = new window.Supplier({
|
|
'contact':[
|
|
{
|
|
id:2,
|
|
},
|
|
{
|
|
id:3,
|
|
},
|
|
/*
|
|
{
|
|
id:3,
|
|
name:'Kósa Veronika',
|
|
email:'szamlazas4@funkcio.hu',
|
|
phone:'{{formatterPhoneNumber("+36204589180")}}'
|
|
}
|
|
*/
|
|
|
|
]
|
|
});
|
|
Opts.onAfterInitViewDetails=root.autofillDetails;
|
|
APP.loadMainContent(Opts.URL.create,root.initViewDetails);
|
|
}
|
|
this.init=function (options,SupplierItem){
|
|
$.extend(Opts, options);
|
|
|
|
if(Opts.testMode){
|
|
return root.testMode();
|
|
}
|
|
if(SupplierItem){
|
|
root.Supplier=SupplierItem
|
|
}
|
|
root.initViewList();
|
|
}
|
|
|
|
this.renderAttachment=function (){
|
|
let rowNum=1;
|
|
console.log('renderingAttachment');
|
|
$.each(root.Supplier.getData('attachment'),function (){
|
|
let attachmentData=this;
|
|
attachmentData.rowNum=rowNum;
|
|
date=new Date(attachmentData.created_at);
|
|
attachmentData.date=date.toLocaleString();
|
|
attachmentData.link=attachmentData.PublicUrl+'/'+attachmentData.filename;
|
|
let template=$('template[data-name="supplierAttachmentTableRow"]').html()
|
|
let render=Mustache.render(template,attachmentData);
|
|
$('.attachmentTable tbody').append(render);
|
|
rowNum++;
|
|
});
|
|
root.bindAttachmentClickAction();
|
|
}
|
|
|
|
this.addAttachment=function (attachmentData){
|
|
console.log(attachmentData);
|
|
let CSSSelectorForm=Opts.containerCssSelector+' .supplierForm';
|
|
root.Supplier.attachment.push(attachmentData);
|
|
attachmentData.rowNum=root.Supplier.attachment.length;
|
|
let template=$('template[data-name="supplierAttachmentTableRow"]').html()
|
|
let render=Mustache.render(template,attachmentData);
|
|
$(CSSSelectorForm+' .attachmentTable tbody').append(render);
|
|
root.bindContactClickAction();
|
|
Toast.enableTimers(false);
|
|
Toast.create("Fájl hozzáadva!", attachmentData.original_filename+" fájl hozzáadva", TOAST_STATUS.SUCCESS,5000);
|
|
}
|
|
|
|
|
|
this.resetContactTable=function (){
|
|
$('.contactTable tbody tr').remove();
|
|
root.renderContact();
|
|
}
|
|
this.renderContact=function (){
|
|
let rowNum=1;
|
|
console.log('renderingContacts');
|
|
$.each(root.Supplier.getData('contact'),function (){
|
|
let contactData=this;
|
|
contactData.rowNum=rowNum;
|
|
//console.log(contactData);
|
|
let template=$('template[data-name="supplierContactTableRow"]').html()
|
|
let render=Mustache.render(template,contactData);
|
|
$('.contactTable tbody').append(render);
|
|
rowNum++;
|
|
});
|
|
root.bindContactClickAction();
|
|
}
|
|
|
|
this.bindContactClickAction =function (){
|
|
let node=$('.contactTable .buttonDelete');
|
|
node.unbind('click');
|
|
node.bind('click',root.contactDeleteClick);
|
|
|
|
node=$('.contactTable .buttonEdit');
|
|
node.unbind('click');
|
|
node.bind('click',root.contactEditClick);
|
|
|
|
}
|
|
|
|
this.bindAttachmentClickAction=function (){
|
|
let node=$('.attachmentTable .buttonDelete');
|
|
node.unbind('click');
|
|
node.bind('click',root.attachmentDeleteClick);
|
|
}
|
|
let currentAttachmentRow=false;
|
|
this.attachmentDeleteClick=function (event){
|
|
let row=$(this).closest('tr');
|
|
let id=row.find('input[name=attachmentId]').val();
|
|
let ajaxUrl=Opts.URL.detachFile.replace('%id%',root.Supplier.id);
|
|
//let data= new FormData($(Opts.containerCssSelector).find('form.supplierForm')[0]);
|
|
//data.append(fileInput.attr('name'),fileInput[0].files[0]);
|
|
let data={};
|
|
data._token=$('input[name="_token"]').val();
|
|
data.attachemntId=id;
|
|
$.ajax({
|
|
url:ajaxUrl,
|
|
data:data,
|
|
type:'POST',
|
|
//contentType:false,
|
|
//processData: false,
|
|
beforeSend: function() {
|
|
|
|
},
|
|
success: function(data) {
|
|
console.log(data);
|
|
if(data.success==true){
|
|
root.Supplier.attachment=root.Supplier.attachment.filter(
|
|
function (value,index,arr){
|
|
if (value.id!==data.data. attachment.id*1){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
);
|
|
/*
|
|
*/
|
|
//row.remove();
|
|
root.resetAttachmentTable();
|
|
}
|
|
},
|
|
error: function(data) {
|
|
console.log(data.responseJSON);
|
|
root.selectedUploadFileToggle();
|
|
ajaxErrorFieldHandler(data.responseJSON.error);
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
|
|
this.resetAttachmentTable=function (){
|
|
$('.attachmentTable tbody tr').remove();
|
|
root.renderAttachment();
|
|
}
|
|
|
|
this.contactDeleteClick=function (event){
|
|
let row=$(this).closest('tr');
|
|
let id=row.find('input[name=contactId]').val();
|
|
root.Supplier.contact=root.Supplier.contact.filter(
|
|
function (value,index,arr){
|
|
if (value.id!==id*1){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
);
|
|
row.remove();
|
|
root.resetContactTable();
|
|
}
|
|
root.getContactPopupWorkflow = function () {
|
|
return contactPopupWorkflow;
|
|
}
|
|
root.setContactPopupWorkflow = function (status) {
|
|
contactPopupWorkflow=status;
|
|
}
|
|
|
|
|
|
this.contactEditClick=function (event){
|
|
//console.log(this);
|
|
let row=$(this).closest('tr');
|
|
let id=row.find('input[name=contactId]').val();
|
|
root.setContactPopupWorkflow('edit');
|
|
APP.ContactPopUp.loadData(id);
|
|
}
|
|
|
|
this.getSupplier=function (){
|
|
return root.Supplier;
|
|
}
|
|
this.contactAction=function (contactData){
|
|
console.log('nah most kellene meg valamit csinalni.')
|
|
if(root.getContactPopupWorkflow()=='new'){
|
|
root.addContact(contactData);
|
|
}else if(root.getContactPopupWorkflow()=='edit'){
|
|
root.editContact(contactData.id,contactData);
|
|
}
|
|
}
|
|
|
|
this.editContact=function (id,contactData){
|
|
|
|
let newContacts=[];
|
|
$.each(root.Supplier.getData('contact'),function (index){
|
|
if(this.id==id){
|
|
newContacts.push(contactData);
|
|
}else{
|
|
newContacts.push(this);
|
|
}
|
|
});
|
|
root.Supplier.contact=newContacts;
|
|
root.resetContactTable();
|
|
Toast.create("Kapcsolat adatai módosítva!", contactData.name+" nevű kapocsolattartó módosítva", TOAST_STATUS.SUCCESS,5000);
|
|
}
|
|
this.addContact=function (contactData){
|
|
/*
|
|
fel kell venni a sorba
|
|
*/
|
|
root.Supplier.contact.push(contactData);
|
|
contactData.rowNum=root.Supplier.contact.length;
|
|
let template=$('template[data-name="supplierContactTableRow"]').html()
|
|
let render=Mustache.render(template,contactData);
|
|
$('.contactTable tbody').append(render);
|
|
root.bindContactClickAction();
|
|
Toast.enableTimers(false);
|
|
Toast.create("Kapcsolat tartó hozzáadva!", contactData.name+" nevű kapocsolattartó hozzáadva", TOAST_STATUS.SUCCESS,5000);
|
|
}
|
|
|
|
|
|
this.construct(options,SupplierItem);
|
|
};
|