offer fileupload and comments

This commit is contained in:
2018-01-10 21:09:08 +01:00
parent 6366bbc6a8
commit 665242eb4a
270 changed files with 35840 additions and 17 deletions
@@ -0,0 +1,40 @@
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/01/2018
* Time: 14:18
*/
dbo.commentsDataService = {
getComments: function ( foreignID, tablename, callback ) {
$.getJSON( 'index.php/projects/commentscontroller/getComments/' + foreignID + '/' + tablename )
.done( function ( data ) {
callback( data );
} );
},
getComment:function(commentID, callback){
$.getJSON( 'index.php/projects/commentscontroller/getComment/' + commentID )
.done( function ( data ) {
callback( data );
} );
},
addComment: function ( foreignID, tablename, callback ) {
$.getJSON( 'index.php/projects/commentscontroller/addcomment/' + foreignID + '/' + tablename )
.done( function (data) {
callback(data);
} );
},
saveComment:function(commentID, comment, callback){
$.post('index.php/projects/commentscontroller/savecomment/' + commentID, {comment:comment} )
.done(function(){
callback();
});
}
}
@@ -0,0 +1,25 @@
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/01/2018
* Time: 14:18
*/
dbo.documentsDataService = {
getdocuments: function ( foreignID, tablename, callback ) {
$.getJSON( 'index.php/projects/documentscontroller/getDocuments/' + foreignID + '/' + tablename )
.done( function ( data ) {
callback( data );
} );
},
removeDocument:function(documentID, callback){
$.getJSON( 'index.php/projects/documentscontroller/removeDocument/' + documentID )
.done( function ( data ) {
callback( data );
} );
}
}
+16 -1
View File
@@ -29,4 +29,19 @@ $( function () {
shouldDisplay ? $( element ).fadeIn( 750 ) : $( element ).fadeOut( 750 );
}
};
} );
} );
function uploadFile(file, foreignID, tablename, callback){
var url = 'index.php/utils/fileupload/upload/' + foreignID + '/' + tablename;
var xhr = new XMLHttpRequest();
var fd = new FormData();
xhr.open("POST", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
callback();
}
};
fd.append("userfile", file);
xhr.send(fd);
}
@@ -0,0 +1,48 @@
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/01/2018
* Time: 16:28
*/
dbo.commentModel = {
comment : ko.observable(),
commentID: null,
callback : null,
options : {
// disable wrapping content with paragraphs
// instead <br> will be used
enter : $.FroalaEditor.ENTER_DIV,
key : 'zc1QXIa2QZe1UOXATEX==',
// we like gray!
theme : 'gray',
toolbarButtons: ['bold', 'italic', 'underline']
},
showComment: function ( commentID, callback ) {
var vm = dbo.commentModel;
vm.callback = callback;
vm.commentID = commentID;
$( "#comment-modal" ).modal( 'show' );
dbo.commentsDataService.getComment( vm.commentID, function ( data ) {
vm.comment( data.comment );
} );
},
saveComment: function () {
var vm = dbo.commentModel;
dbo.commentsDataService.saveComment( vm.commentID, vm.comment(), function () {
$( "#comment-modal" ).modal( 'hide' );
vm.callback();
} );
}
}
ko.applyBindings( dbo.commentModel, document.getElementById( 'comment-modal' ) );
@@ -125,6 +125,6 @@ $( function () {
return true;
}, dbo.editCustomerModal )
ko.applyBindings( dbo.editCustomerModal, document.getElementById( 'customer-modal' ) );
ko.applyBindings( dbo.editCustomerModal, document.getElementById( 'customer-modal' ) );
} );
+118 -3
View File
@@ -13,9 +13,13 @@ dbo.offersInit = function () {
} else {
dbo.offersModel = {
offers : ko.observableArray( [] ),
offer : ko.observable(),
archive: ko.observable( false ),
tableName : 'OFFER',
offers : ko.observableArray( [] ),
offer : ko.observable(),
archive : ko.observable( false ),
comments : ko.observableArray( [] ),
documents : ko.observableArray( [] ),
selectedRowID: ko.observable(),
init: function () {
var vm = dbo.offersModel;
@@ -47,6 +51,43 @@ dbo.offersInit = function () {
} );
},
selectOffer: function () {
var vm = dbo.offersModel;
vm.selectedRowID( this.id );
vm.refreshComments();
vm.refreshDocuments();
},
addDocument: function ( data, evt ) {
var vm = dbo.offersModel;
uploadFile( evt.target.files[0], vm.selectedRowID(), vm.tableName, function () {
vm.refreshDocuments();
} );
},
addComment: function () {
var vm = dbo.offersModel;
dbo.commentsDataService.addComment( vm.selectedRowID(), vm.tableName, function ( commentID ) {
dbo.commentModel.showComment( commentID, function () {
vm.refreshComments();
} )
} );
},
editComment: function () {
var vm = dbo.offersModel;
dbo.commentModel.showComment( this.id, function () {
vm.refreshComments();
} );
},
downloadDocument: function () {
window.open( 'index.php/projects/documentscontroller/downloaddocument/' + this.id );
},
archiveOffer: function () {
var vm = dbo.offersModel;
var self = this;
@@ -93,6 +134,42 @@ dbo.offersInit = function () {
} );
},
removeFile: function () {
var vm = dbo.offersModel;
var self = this;
tellMe( {
title : 'verwijderen document',
message : 'weet u zeker dat u hjet document wilt verwijderen, dit kan niet ongedaan worden gemaakt',
notify : true,
noText : 'nee verwijder het document niet',
yesText : 'ja verwijder het document',
modalClass: 'modal-warning'
}, function ( response ) {
console.log( response );
if ( response ) {
dbo.documentsDataService.removeDocument( self.id, function ( data ) {
if ( data.result ) {
tellMe( {
title : 'document verwijderd',
message : 'het document is succesvol verwijderd',
modalClass: 'modal-success'
}, function () {
vm.refreshDocuments();
} );
} else {
tellMe( {
title : 'fout bij verwijderen document',
message : 'het document kan niet worden verwijderd',
modalClass: 'modal-danger'
} );
}
} );
}
} );
},
refreshOffers: function () {
var vm = dbo.offersModel;
@@ -104,6 +181,30 @@ dbo.offersInit = function () {
} );
},
refreshComments: function () {
var vm = dbo.offersModel;
dbo.commentsDataService.getComments( vm.selectedRowID(), vm.tableName, function ( data ) {
vm.comments.removeAll();
console.log( data );
$.each( data, function ( i, p ) {
vm.comments.push( new vm.Comment( p ) );
} );
} );
},
refreshDocuments: function () {
var vm = dbo.offersModel;
dbo.documentsDataService.getdocuments( vm.selectedRowID(), vm.tableName, function ( data ) {
vm.documents.removeAll();
$.each( data, function ( i, p ) {
vm.documents.push( new vm.Document( p ) );
} )
} )
},
Offer: function ( data ) {
this.id = data.id;
this.acceptance_chance = data.acceptance_chance;
@@ -115,6 +216,20 @@ dbo.offersInit = function () {
this.accepteddate = data.accepteddate ? dbo.helpers.mysql2date( data.accepteddate ) : null;
this.acceptance_chance = data.acceptance_chance ? data.acceptance_chance : 0;
this.archive = data.archive;
},
Comment: function ( data ) {
this.id = data.id;
this.comment_date = data.comment_date;
this.fullname = data.user.fullname;
this.comment = ko.observable( data.comment );
},
Document: function ( data ) {
this.id = data.id;
this.originalname = data.originalname;
this.uploaddate = data.uploaddate;
this.fullname = data.user.fullname;
}