From 49bd541cb8b89ecb3ed14873195199259d5814a8 Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Fri, 6 Apr 2018 10:48:39 +0200 Subject: [PATCH] upload --- .../projects/DocumentsController.php | 4 +- application/models/eloquent/Document.php | 3 +- .../views/modals/partials/_projectfiles.php | 87 ++++++++++--------- application/views/partials/_modals.php | 1 + application/views/specials/upload_modal.php | 20 +++++ public/css/main.css | 24 +++++ .../lib/dataservices/documentsDataservice.js | 4 +- public/js/lib/main.js | 4 +- public/js/lib/modals/projectModal.js | 70 +++++++++++++++ public/js/lib/services/documentService.js | 1 - 10 files changed, 169 insertions(+), 49 deletions(-) create mode 100644 application/views/specials/upload_modal.php diff --git a/application/controllers/projects/DocumentsController.php b/application/controllers/projects/DocumentsController.php index 4f94feb..ae77cab 100644 --- a/application/controllers/projects/DocumentsController.php +++ b/application/controllers/projects/DocumentsController.php @@ -21,9 +21,9 @@ class DocumentsController extends MY_Controller { $this->load->library( $libraries ); } - public function getDocuments( $foreignID, $tablename ) + public function getDocuments( $foreignID ) { - $documents = Document::getDocuments( $foreignID, $tablename ); + $documents = Document::getDocuments( $foreignID ); $this->json( $documents ); } diff --git a/application/models/eloquent/Document.php b/application/models/eloquent/Document.php index 60c5e3c..5339564 100644 --- a/application/models/eloquent/Document.php +++ b/application/models/eloquent/Document.php @@ -15,7 +15,7 @@ class Document extends BaseModel { return $this->belongsTo( 'User' ); } - public static function getDocuments( $foreignID, $tablename ) + public static function getDocuments( $foreignID) { $documents = Document::orderBy( 'uploaddate', 'desc' ) ->with( [ @@ -23,7 +23,6 @@ class Document extends BaseModel { $q->selectRaw( "CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname, id" ); }] ) ->whereForeignId( $foreignID ) - ->whereForeignTable( $tablename ) ->get(); return $documents; diff --git a/application/views/modals/partials/_projectfiles.php b/application/views/modals/partials/_projectfiles.php index f22ee0d..f70bb43 100644 --- a/application/views/modals/partials/_projectfiles.php +++ b/application/views/modals/partials/_projectfiles.php @@ -1,43 +1,50 @@ -
-
-

- bestanden -

+
+ + + + + + + + + + + + + + + + + + + +
doordatumbestandsnaam 
+ + + + + + + + +
+
+ +
-
- - - - - - - - - - - - - - - - - - - - - -
- offerte bestanden -
- - - - -
- project bestanden -
- -
+
+
+
+ + + + +
+ + | + +
+
+
\ No newline at end of file diff --git a/application/views/partials/_modals.php b/application/views/partials/_modals.php index 4c64e81..c4881f0 100644 --- a/application/views/partials/_modals.php +++ b/application/views/partials/_modals.php @@ -8,6 +8,7 @@ $this->load->view('modals/project_modal'); $this->load->view('modals/comment_modal'); $this->load->view('specials/tellme_modal'); +$this->load->view('specials/upload_modal'); diff --git a/application/views/specials/upload_modal.php b/application/views/specials/upload_modal.php new file mode 100644 index 0000000..339604a --- /dev/null +++ b/application/views/specials/upload_modal.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/public/css/main.css b/public/css/main.css index 480700d..cbba3df 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -317,3 +317,27 @@ th.focus-green{ color:#666; } + +.upload-btn-wrapper { + position: relative; + overflow: hidden; + display: inline-block; +} + +.upload-btn { + border: 2px solid gray; + color: gray; + background-color: white; + padding: 8px 20px; + border-radius: 8px; + font-size: 20px; + font-weight: bold; +} + +.upload-btn-wrapper input[type=file] { + font-size: 100px; + position: absolute; + left: 0; + top: 0; + opacity: 0; +} diff --git a/public/js/lib/dataservices/documentsDataservice.js b/public/js/lib/dataservices/documentsDataservice.js index 7bbc294..0f9972f 100644 --- a/public/js/lib/dataservices/documentsDataservice.js +++ b/public/js/lib/dataservices/documentsDataservice.js @@ -8,8 +8,8 @@ dbo.documentsDataService = { - getdocuments: function ( foreignID, tablename, callback ) { - $.getJSON( 'index.php/projects/documentsController/getDocuments/' + foreignID + '/' + tablename ) + getdocuments: function ( foreignID, callback ) { + $.getJSON( 'index.php/projects/documentsController/getDocuments/' + foreignID ) .done( function ( data ) { callback( data ); } ); diff --git a/public/js/lib/main.js b/public/js/lib/main.js index 2a19a9b..d7aadfd 100644 --- a/public/js/lib/main.js +++ b/public/js/lib/main.js @@ -33,8 +33,8 @@ $( function () { $('body').delay(500).fadeIn(1500); } ); -function uploadFile( file, foreignID, tablename, callback ) { - var url = 'index.php/utils/fileUpload/upload/' + foreignID + '/' + tablename; +function uploadFile( file, foreignID, callback ) { + var url = 'index.php/utils/fileUpload/upload/' + foreignID; var xhr = new XMLHttpRequest(); var fd = new FormData(); xhr.open( "POST", url, true ); diff --git a/public/js/lib/modals/projectModal.js b/public/js/lib/modals/projectModal.js index c006d4b..c8a78a3 100644 --- a/public/js/lib/modals/projectModal.js +++ b/public/js/lib/modals/projectModal.js @@ -44,6 +44,8 @@ $( function () { outstanding : ko.observable(), toForecast : ko.observable(), totalForecast : ko.observable(), + documents : ko.observableArray( [] ), + comments : ko.observableArray( [] ), init: function () { var vm = dbo.editProjectModal; @@ -747,6 +749,8 @@ $( function () { vm.reservations.push( new vm.Reservation( p ) ); } ); + vm.refreshDocuments(); + vm.busy = false; dbo.charts.drawHoursVsBudget( 340, 230, 'hours-vs-budget' ); @@ -879,7 +883,73 @@ $( function () { this.reservationamount = ko.observable( data.reservationamount ); this.payed = ko.observable( data.payed ); this.inEdit = ko.observable( data.inEdit || false ); + }, + + addDocument: function ( data, evt ) { + var vm = dbo.editProjectModal; + uploadFile( evt.target.files[0], vm.projectID, function () { + vm.refreshDocuments(); + } ); + }, + + addComment: function () { + var vm = dbo.editProjectModal; + dbo.commentsDataService.addComment( vm.selectedRowID(), vm.tableName, function ( commentID ) { + dbo.commentModel.showComment( commentID, function () { + vm.refreshComments(); + } ) + } ); + }, + + editComment: function () { + var vm = dbo.editProjectModal; + dbo.commentModel.showComment( this.id, function () { + vm.refreshComments(); + } ); + }, + + downloadDocument: function () { + window.open( 'index.php/projects/documentscontroller/downloaddocument/' + this.id ); + }, + + refreshComments: function () { + var vm = dbo.editProjectModal; + + 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.editProjectModal; + + dbo.documentsDataService.getdocuments( vm.projectID, function ( data ) { + vm.documents.removeAll(); + + $.each( data, function ( i, p ) { + vm.documents.push( new vm.Document( p ) ); + } ) + } ); + }, + + 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; } + }; dbo.editProjectModal.totalHours = ko.pureComputed( function () { diff --git a/public/js/lib/services/documentService.js b/public/js/lib/services/documentService.js index 802a815..0f681b8 100644 --- a/public/js/lib/services/documentService.js +++ b/public/js/lib/services/documentService.js @@ -10,7 +10,6 @@ dbo.documentService = { tableName: 'OFFER', - removeFile: function (that) { var vm = dbo.offersService.vm;