UNPKG

@incdevco/framework

Version:
327 lines (309 loc) 10.3 kB
/* global angular */ angular.module('address', []) .directive('addressRead', [ function () { return { replace: true, restrict: 'E', scope: { address: '=' }, templateUrl: 'address/templates/read-directive.html' }; } ]) .directive('addressWrite', [ 'AddressService', function (AddressService) { return { link: function ($scope) { $scope.countries = AddressService.countries(); $scope.states = AddressService.states(); }, replace: true, restrict: 'E', scope: { address: '=' }, templateUrl: 'address/templates/write-directive.html' }; } ]) .factory('AddressService', [ function () { return { countries: () => { return [ { iso_2_code: 'US', iso_3_code: 'USA', iso_num_code: 840, name: 'United States' } ]; }, new: () => { return { city: null, country: { iso_2_code: 'US', iso_3_code: 'USA', iso_num_code: 840, name: 'United States' }, postal_code: null, state: null, street: null, unit: null }; }, states: () => { return [ { abbreviation:'AL', name:'Alabama' }, { abbreviation:'AK', name:'Alaska' }, { abbreviation:'AZ', name:'Arizona' }, { abbreviation:'AR', name:'Arkansas' }, { abbreviation:'CA', name:'California' }, { abbreviation:'CO', name:'Colorado' }, { abbreviation:'CT', name:'Connecticut' }, { abbreviation:'DE', name:'Delaware' }, { abbreviation:'FL', name:'Florida' }, { abbreviation:'GA', name:'Georgia' }, { abbreviation:'HI', name:'Hawaii' }, { abbreviation:'ID', name:'Idaho' }, { abbreviation:'IL', name:'Illinois' }, { abbreviation:'IN', name:'Indiana' }, { abbreviation:'IA', name:'Iowa' }, { abbreviation:'KS', name:'Kansas' }, { abbreviation:'KY', name:'Kentucky' }, { abbreviation:'LA', name:'Louisiana' }, { abbreviation:'ME', name:'Maine' }, { abbreviation:'MD', name:'Maryland' }, { abbreviation:'MA', name:'Massachusetts' }, { abbreviation:'MI', name:'Michigan' }, { abbreviation:'MN', name:'Minnesota' }, { abbreviation:'MS', name:'Mississippi' }, { abbreviation:'MO', name:'Missouri' }, { abbreviation:'MT', name:'Montana' }, { abbreviation:'NE', name:'Nebraska' }, { abbreviation:'NV', name:'Nevada' }, { abbreviation:'NH', name:'New Hampshire' }, { abbreviation:'NJ', name:'New Jersey' }, { abbreviation:'NM', name:'New Mexico' }, { abbreviation:'NY', name:'New York' }, { abbreviation:'NC', name:'North Carolina' }, { abbreviation:'ND', name:'North Dakota' }, { abbreviation:'OH', name:'Ohio' }, { abbreviation:'OK', name:'Oklahoma' }, { abbreviation:'OR', name:'Oregon' }, { abbreviation:'PA', name:'Pennsylvania' }, { abbreviation:'RI', name:'Rhode Island' }, { abbreviation:'SC', name:'South Carolina' }, { abbreviation:'SD', name:'South Dakota' }, { abbreviation:'TN', name:'Tennesee' }, { abbreviation:'TX', name:'Texas' }, { abbreviation:'UT', name:'Utah' }, { abbreviation:'VT', name:'Vermont' }, { abbreviation:'VA', name:'Virginia' }, { abbreviation:'WA', name:'Washington' }, { abbreviation:'WV', name:'West Virginia' }, { abbreviation:'WI', name:'Wisconsin' }, { abbreviation:'WY', name:'Wyoming' }, { abbreviation:'AS', name:'American Somoa' }, { abbreviation:'DC', name:'District of Columbia' }, { abbreviation:'FM', name:'Federated States of Micronesia' }, { abbreviation:'GU', name:'Guam' }, { abbreviation:'MH', name:'Marshall Island' }, { abbreviation:'MP', name:'Northern Mariana Islands' }, { abbreviation:'PW', name:'Palau' }, { abbreviation:'PR', name:'Puerto Rico' }, { abbreviation:'VI', name:'Virgin Islands' } ]; } }; } ]); angular.module('address') .run([ '$templateCache', function ($templateCache) { $templateCache.put('address/templates/read-directive.html', '<div class="address-read"> <div>{{address.street}}</div> <div>{{address.unit}}</div> <div> <span>{{address.city}}</span> <span>{{address.state.name}}</span> <span>{{address.postal_code}}</span> <span>{{address.country.name}}</span> </div></div>'); $templateCache.put('address/templates/write-directive.html', '<div class="address-write" ng-form="address_form"> <div layout="column"> <md-input-container> <label for="country">Country</label> <md-select name="country" ng-model="address.country" ng-model-options="{trackBy:\'$value.iso_2_code\'}" ng-required="true"> <md-option ng-repeat="country in countries" ng-value="country">United States</md-option> </md-select> <ng-messages for="address_form.country.$invalid" role="alert"> <ng-message when="required">The name of the country is required. (United States) </ng-message> </ng-messages> </md-input-container> </div> <div layout="column"> <md-input-container> <label for="street">Street</label> <input type="text" name="street" ng-model="address.street" ng-required="required" /> <ng-messages for="address_form.street.$invalid" role="alert"> <ng-message when="required">The street address is required. (580 Main St)</ng-message> </ng-messages> </md-input-container> </div> <div layout="column"> <md-input-container> <label for="unit">Unit</label> <input type="text" name="unit" ng-model="address.unit" ng-required="false" /> <ng-messages for="address_form.unit.$invalid" role="alert"> <ng-message when="required">The unit is required. (#300) </ng-message> </ng-messages> </md-input-container> </div> <div layout="column" layout-gt-md="row"> <div flex> <md-input-container> <label for="city">City</label> <input type="text" name="city" ng-model="address.city" ng-required="required" /> <ng-messages for="address_form.city.$invalid" role="alert"> <ng-message when="required">The name of the city is required. (Carbondale) </ng-message> </ng-messages> </md-input-container> </div> <div flex> <md-input-container> <label for="state">State</label> <md-select name="state" ng-model="address.state" ng-model-options="{trackBy:\'$value.abbreviation\'}"> <md-option ng-repeat="state in states" ng-value="state">{{state.name}}</md-option> </md-select> <ng-messages for="address_form.state.$invalid" role="alert"> <ng-message when="required">Please select a state for the address. (Colorado)</ng-message> </ng-messages> </md-input-container> </div> <div flex> <md-input-container> <label for="postal_code" ng-if="address.country.iso_2_code !== \'US\'">Postal Code</label> <label for="postal_code" ng-if="address.country.iso_2_code === \'US\'">Zip Code</label> <input type="text" name="postal_code" ng-model="address.postal_code" ng-required="required" /> <ng-messages for="address_form.postal_code.$invalid" role="alert"> <ng-message when="required" ng-if="address.country.iso_2_code !== \'US\'">The postal code is required. (81623) </ng-message> <ng-message when="required" ng-if="address.country.iso_2_code === \'US\'">The zip code is required. (81623) </ng-message> </ng-messages> </md-input-container> </div> </div></div>');} ]);