diff --git a/application/controllers/beheer/CustomersController.php b/application/controllers/beheer/CustomersController.php index fe40206..0fd8500 100644 --- a/application/controllers/beheer/CustomersController.php +++ b/application/controllers/beheer/CustomersController.php @@ -12,6 +12,8 @@ class customersController extends MY_Controller { { parent::__construct(); + if( AUTHENTICATED == FALSE ) + $models = []; $libraries = []; diff --git a/application/controllers/beheer/ExternalsController.php b/application/controllers/beheer/ExternalsController.php index 949a8fd..28712cb 100644 --- a/application/controllers/beheer/ExternalsController.php +++ b/application/controllers/beheer/ExternalsController.php @@ -1,12 +1,12 @@ json( $users ); + $this->json( $externals ); } - public function saveCustomer() + public function saveExternal() { - $userValidation = new CustomerValidation(); + $externalValidation = new ExternalValidation(); - if ( ! $userValidation->getValidationResult() ) + if ( ! $externalValidation->getValidationResult() ) return $this->json( [ - 'success' => FALSE, 'messages' => $userValidation->getErrorMessages()] ); + 'success' => FALSE, 'messages' => $externalValidation->getErrorMessages()] ); - $user = $this->input->post(); + $external = $this->input->post(); - $userID = $user['id']; - unset( $user['id'] ); + $externalID = $external['id']; + unset( $external['id'] ); - $userID = Customer::saveCustomer( $userID, $user ); + $externalID = External::saveExternal( $externalID, $external ); - $this->json( ['success' => TRUE, 'userID' => $userID] ); + $this->json( ['success' => TRUE, 'externalID' => $externalID] ); } - public function archiveCustomer( $userID, $status ) + public function archiveExternal( $externalID, $status ) { - Customer::whereId( $userID )->update( ['archive' => $status] ); + External::whereId( $externalID )->update( ['archive' => $status] ); } - public function removeCustomer( $userID ) + public function removeExternal( $externalID ) { - $removeCustomer = new RemoveCustomer( $userID ); + $removeExternal = new RemoveExternal( $externalID ); - if ( $removeCustomer->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); + if ( $removeExternal->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); - Customer::removeCustomer( $userID ); + External::removeExternal( $externalID ); $this->json( ['result' => TRUE] ); } diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 87dd1eb..a2ae545 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -38,7 +38,14 @@ class MY_Controller extends CI_Controller { public function json( $data ) { - echo json_encode( $data ); + $this->output + ->set_content_type( 'application/json' ) + ->set_output( json_encode( $data ) ); + } + + public function unAuthorized() + { + } } \ No newline at end of file diff --git a/application/libraries/beheer/externals/RemoveExternal.php b/application/libraries/beheer/externals/RemoveExternal.php new file mode 100644 index 0000000..88dd9fd --- /dev/null +++ b/application/libraries/beheer/externals/RemoveExternal.php @@ -0,0 +1,36 @@ +setExternalID( $userID ); + + $this->handle(); + } + + public function getAllowDelete() + { + return $this->allowDelete; + } + + private function setExternalID( $externalID ) + { + $this->externalID = $externalID; + } + + private function handle() + { + + } + +} \ No newline at end of file diff --git a/application/libraries/validation/inputValidations/ExternalValidation.php b/application/libraries/validation/inputValidations/ExternalValidation.php new file mode 100644 index 0000000..9c29b90 --- /dev/null +++ b/application/libraries/validation/inputValidations/ExternalValidation.php @@ -0,0 +1,36 @@ + [ + 'validations' => 'required|alphaNumericSpaces', + 'fieldname' => 'contact' + ], + 'email' => [ + 'validations' => 'email', + 'fieldname' => 'email' + ], + 'rate' => [ + 'validations' => 'numeric', + 'fieldname' => 'tarief' + ] + ]; + + public function __construct() + { + parent::__construct(); + + $this->ci =& get_instance(); + } +} \ No newline at end of file diff --git a/application/models/beheer/External_model.php b/application/models/beheer/External_model.php new file mode 100644 index 0000000..c754af1 --- /dev/null +++ b/application/models/beheer/External_model.php @@ -0,0 +1,18 @@ +whereArchive( 'F' ); + + $externals = $externals->get(); + + return $externals; + } + + public static function saveExternal( $externalID, $external ) + { + $external = (array)$external; + + if( $externalID == 0) + { + $external = External::create($external); + } + else + { + $external = External::whereId($externalID)->update($external); + } + + return $external['id']; + } + + public static function removeExternal($externalID) + { + External::whereId($externalID)->delete(); + } + + +} \ No newline at end of file diff --git a/application/views/modals/customer_modal.php b/application/views/modals/customer_modal.php index 8f5fb26..106ec3f 100644 --- a/application/views/modals/customer_modal.php +++ b/application/views/modals/customer_modal.php @@ -21,7 +21,7 @@ diff --git a/application/views/modals/external_modal.php b/application/views/modals/external_modal.php new file mode 100644 index 0000000..91f2727 --- /dev/null +++ b/application/views/modals/external_modal.php @@ -0,0 +1,190 @@ + \ No newline at end of file diff --git a/application/views/pages/externals_view.php b/application/views/pages/externals_view.php index eaca882..7e0eb1f 100644 --- a/application/views/pages/externals_view.php +++ b/application/views/pages/externals_view.php @@ -13,7 +13,7 @@   - + @@ -22,25 +22,25 @@ - + + data-bind="click:$root.archiveExternal"> + data-bind="click:$root.archiveExternal"> + data-bind="click:$root.removeExternal"> - diff --git a/application/views/partials/_js.php b/application/views/partials/_js.php index ef21f1e..a2da039 100644 --- a/application/views/partials/_js.php +++ b/application/views/partials/_js.php @@ -54,12 +54,15 @@ + + + \ No newline at end of file diff --git a/application/views/partials/_modals.php b/application/views/partials/_modals.php index 3c78f53..c9486de 100644 --- a/application/views/partials/_modals.php +++ b/application/views/partials/_modals.php @@ -2,6 +2,7 @@ $this->load->view('modals/user_modal'); $this->load->view('modals/customer_modal'); +$this->load->view('modals/external_modal'); $this->load->view('specials/tellme_modal'); diff --git a/public/css/main.css b/public/css/main.css index b68a097..b887362 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -10,6 +10,9 @@ .pointer{ cursor:pointer; } +.align-right{ + text-align:right; +} .site-menu-sub > li{ margin-left:30px; diff --git a/public/js/lib/dataservices/externalDataservice.js b/public/js/lib/dataservices/externalDataservice.js new file mode 100644 index 0000000..65af585 --- /dev/null +++ b/public/js/lib/dataservices/externalDataservice.js @@ -0,0 +1,55 @@ +/** + * Created by Pensare Software. + * External: Theo Weijmer + * Date: 25/12/2017 + * Time: 09:50 + */ + +dbo.externalDataService = { + + getAllExternals: function ( archive = 'F', callback ) { + $.getJSON( 'index.php/beheer/externalsController/getAllExternals/' + archive ) + .done( function ( data ) { + callback( data ); + } ); + }, + + getExternal: function ( userID, callback ) { + $.getJSON( 'index.php/beheer/externalsController/getExternal/' + userID ) + .done( function ( data ) { + callback( data ); + } ); + }, + + checkExternalname: function ( username, callback ) { + $.post( 'index.php/beheer/userController/checkExternalname', 'json' ) + .done( function ( data ) { + console.log( data ); + callback( data ); + } ); + }, + + saveExternal: function ( submitDATA, callback ) { + $.post( 'index.php/beheer/externalsController/saveExternal', submitDATA, function () { + }, 'json' ) + .done( function ( data ) { + callback( data ); + } ); + }, + + archiveExternal: function(userID, status, callback){ + $.get('index.php/beheer/externalsController/archiveExternal/' + userID + '/' + status) + .done(function(){ + callback(); + }); + }, + + removeExternal: function ( userID, callback ) { + $.getJSON( 'index.php/beheer/externalsController/removeExternal/' + userID ) + .done( function ( data ) { + callback( data ); + } ); + } + + +} \ No newline at end of file diff --git a/public/js/lib/helpers.js b/public/js/lib/helpers.js index 03d6190..884414e 100644 --- a/public/js/lib/helpers.js +++ b/public/js/lib/helpers.js @@ -9,5 +9,51 @@ dbo.helpers = { validateEmail: function ( email ) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test( email.toLowerCase() ); + }, + + validateNumber: function ( input, point = true ) { + var validNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', ',']; + var pointTaken = false; + var pointedString = ''; + + // convert to comma or point number + if ( point ) { + input = input.replace( ',', '' ); + } else { + input = input.replace( '.', '' ); + } + + //remain only last comma or point and remove all non numbers + var reverse = dbo.helpers.reverseString( input ).toString(); + for ( let character of reverse ) { + if ( character == ',' || character == '.' ) { + if ( pointTaken == false ) pointedString += character + pointTaken = true; + } else { + if ( dbo.helpers.inArray( character, validNumbers ) ) { + pointedString += character; + } + } + } + + pointedString = dbo.helpers.reverseString( pointedString ); + + return pointedString; + }, + + inArray: function ( needle, hayStack ) { + var valid = false; + + $.each( hayStack, function ( i, p ) { + if ( p == needle ) valid = true; + } ); + + return valid; + }, + + reverseString: function ( string = '' ) { + string = string.toString(); + if ( string.length == 0 ) return ''; + return string.split( '' ).reverse().join( '' ); } } \ No newline at end of file diff --git a/public/js/lib/modules/beheer/externalsModule.js b/public/js/lib/modules/beheer/externalsModule.js new file mode 100644 index 0000000..37e3de0 --- /dev/null +++ b/public/js/lib/modules/beheer/externalsModule.js @@ -0,0 +1,111 @@ +/** + * Created by Pensare Software. + * User: Theo Weijmer + * Date: 29/12/2017 + * Time: 14:19 + */ + +dbo.externalsInit = function () { + + if ( dbo.externalsModel !== undefined ) { + + } else { + dbo.externalsModel = { + + externals: ko.observableArray( [] ), + external : ko.observable(), + archive : ko.observable( false ), + + init: function () { + var vm = dbo.externalsModel; + + vm.refreshExternals(); + }, + + newExternal: function () { + var vm = dbo.externalsModel; + dbo.editExternalModal.newEditExternal( false, function () { + vm.refreshExternals(); + } ); + }, + + toggleArchive: function () { + var vm = dbo.externalsModel; + + vm.archive( !vm.archive() ); + + vm.refreshExternals(); + }, + + editExternal: function () { + var external = this; + var vm = dbo.externalsModel; + + dbo.editExternalModal.newEditExternal( external, function () { + vm.refreshExternals(); + } ); + }, + + archiveExternal: function () { + var vm = dbo.externalsModel; + var self = this; + + var status = self.archive == 'F' ? 'T' : 'F'; + + dbo.externalDataService.archiveExternal( self.id, status, function () { + vm.refreshExternals(); + } ); + }, + + removeExternal: function () { + var vm = dbo.externalsModel; + var self = this; + + tellMe( { + title : 'verwijderen externe', + message : 'weet u zeker dat u de externe wilt verwijderen, dit kan niet ongedaan worden gemaakt', + notify : true, + noText : 'nee verwijder de externe niet', + yesText : 'ja verwijder de externe', + modalClass: 'modal-warning' + }, function ( response ) { + if ( response ) { + dbo.externalDataService.removeExternal( self.id, function ( data ) { + if ( data.result ) { + tellMe( { + title : 'externe verwijderd', + message : 'de externe is succesvol verwijderd', + modalClass: 'modal-success' + }, function () { + vm.refreshExternals(); + } ); + } else { + tellMe( { + title : 'fout bij verwijderen externe', + message : 'de externe kan niet worden verwijderd', + modalClass: 'modal-danger' + } ); + } + } ); + } + } ); + }, + + refreshExternals: function () { + var vm = dbo.externalsModel; + + dbo.externalDataService.getAllExternals( vm.archive() ? 'T' : 'F', function ( data ) { + vm.externals( data ); + } ); + } + + + }; + + dbo.externalsModel.init(); + + ko.applyBindings( dbo.externalsModel, document.getElementById( 'EXTERNALS' ) ); + } + +} + diff --git a/public/js/lib/modules/modals/externalModal.js b/public/js/lib/modules/modals/externalModal.js new file mode 100644 index 0000000..f1b2b43 --- /dev/null +++ b/public/js/lib/modules/modals/externalModal.js @@ -0,0 +1,142 @@ +/** + * Created by Pensare Software. + * External: Theo Weijmer + * Date: 25/12/2017 + * Time: 17:32 + */ + +$( function () { + dbo.editExternalModal = { + + id : null, + name : ko.observable(), + address : ko.observable(), + postcode : ko.observable(), + place : ko.observable(), + contactperson: ko.observable(), + email : ko.observable(), + website : ko.observable(), + remarks : ko.observable(), + rate : ko.observable(), + kvk_number : ko.observable(), + callback : null, + + init: function () { + + }, + + newEditExternal: function ( external, callback ) { + var vm = dbo.editExternalModal; + vm.callback = typeof(callback) == 'function' ? callback : null; + + vm.showExternalModal(); + + vm.setExternal( external ); + }, + + saveExternal: function () { + var vm = dbo.editExternalModal; + + if ( vm.formValid == false ) return; + + var submitDATA = { + id : vm.id, + name : vm.name(), + address : vm.address(), + postcode : vm.postcode(), + place : vm.place(), + contactperson: vm.contactperson(), + email : vm.email(), + website : vm.website(), + remarks : vm.remarks(), + rate : vm.rate(), + kvk_number : vm.kvk_number() + } + + dbo.externalDataService.saveExternal( submitDATA, function ( data ) { + if ( data.success ) { + tellMe( { + title : 'externe aangemaakt', + message : 'externe is succesvol opgeslagen', + modalClass: 'modal-success' + }, function () { + vm.hideExternalModal(); + + if ( typeof(vm.callback) == 'function' ) vm.callback(); + } ); + + return; + } + + var errorMessage = ''; + tellMe( { + title : 'fout aanmaken externe', + message : errorMessage, + modalClass: 'modal-danger' + } ); + } ); + }, + + setExternal: function ( external ) { + var vm = dbo.editExternalModal; + + vm.id = (external.id || 0); + vm.name( external.name || '' ); + vm.address( external.address || '' ); + vm.postcode( external.postcode || '' ); + vm.place( external.place || '' ); + vm.contactperson( external.contactperson || '' ); + vm.email( external.email || '' ); + vm.website( external.website || '' ); + vm.remarks( external.remarks || '' ); + vm.rate( external.rate || 0 ); + vm.kvk_number( external.kvk_number || '' ); + }, + + showExternalModal: function () { + $( "#external-modal" ).modal( 'show' ); + }, + + hideExternalModal: function () { + $( "#external-modal" ).modal( 'hide' ); + }, + + validateNumber : function ( ) { + var vm = dbo.editExternalModal; + vm.rate( dbo.helpers.validateNumber( vm.rate(), false ) ); + } + +}; + + dbo.editExternalModal.init(); + + dbo.editExternalModal.contactpersonInvalid = ko.pureComputed( function () { + if ( !this.contactperson() ) return true; + + if ( this.contactperson().length < 2 ) return true; + + return false; + }, dbo.editExternalModal ); + + dbo.editExternalModal.emailInvalid = ko.pureComputed( function () { + if ( !this.email() ) return false; + + return !dbo.helpers.validateEmail( this.email() ); + }, dbo.editExternalModal ); + + dbo.editExternalModal.formValid = ko.pureComputed( function () { + if ( this.contactpersonInvalid() ) return false; + if ( this.emailInvalid() ) return false; + + return true; + }, dbo.editExternalModal ) + + ko.applyBindings( dbo.editExternalModal, document.getElementById( 'external-modal' ) ); + +} ); \ No newline at end of file