Last active
July 2, 2017 17:50
-
-
Save gotthardp/eedbd85b5304f562fca555a7d6a7d491 to your computer and use it in GitHub Desktop.
Tabs with ng-admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myApp = angular.module('myApp', ['ng-admin']); | |
| myApp.config(['NgAdminConfigurationProvider', function (nga) { | |
| ... | |
| nodes.creationView().fields([ | |
| nga.field('field1'), | |
| nga.field('field2'), | |
| ... | |
| nga.field('field20') | |
| ]); | |
| nodes.creationView().template(createWithTabsTemplate([ | |
| {name:"Tab1", min:0, max:10}, | |
| {name:"Tab2", min:10, max:20} | |
| ])); | |
| nodes.editionView().fields([ | |
| nga.field('field1'), | |
| nga.field('field2'), | |
| ... | |
| nga.field('field20') | |
| ]); | |
| nodes.editionView().template(editWithTabsTemplate([ | |
| {name:"Tab1", min:0, max:10}, | |
| {name:"Tab2", min:10, max:20} | |
| ])); | |
| ... | |
| nga.configure(admin); | |
| }]); | |
| function createWithTabsTemplate(list) { | |
| var R = ` | |
| <div class="row"> | |
| <div class="col-lg-12"> | |
| <div class="tab-header"> | |
| <ma-view-actions override="::formController.actions" entry="entry" entity="::formController.entity"> | |
| <ma-list-button ng-if="::entity.listView().enabled" entity="::entity"></ma-list-button> | |
| </ma-view-actions> | |
| <h1 compile="::formController.title"> | |
| {{ 'CREATE_NEW' | translate }} {{ ::formController.view.entity.label() | humanize:true | singularize | translate }} | |
| </h1> | |
| <p class="lead" ng-if="::formController.description" compile="::formController.description">{{ ::formController.description }}</p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="row" id="create-view" ng-class="::'ng-admin-entity-' + formController.entity.name()"> | |
| <form class="col-lg-12 form-horizontal" name="formController.form" ng-submit="formController.submitCreation($event)"> | |
| <uib-tabset active="active"> | |
| `; | |
| for(var i = 0; i < list.length; ++i) | |
| { | |
| R += '<uib-tab index="' +i+ '" heading="' +list[i].name+ '">' | |
| + '<div ng-repeat="field in ::formController.fields.slice(' +list[i].min+ ',' +list[i].max+ ' ) track by $index" compile="::field.getTemplateValueWithLabel(entry)">' | |
| + '<ma-field field="::field" value="entry.values[field.name()]" entry="entry" entity="::entity" form="formController.form" datastore="::formController.dataStore"></ma-field>' | |
| + '</div>' | |
| + '</uib-tab>'; | |
| } | |
| R += ` | |
| </uib-tabset> | |
| <div class="form-group"> | |
| <div class="col-sm-offset-2 col-sm-10"> | |
| <ma-submit-button label="SUBMIT"></ma-submit-button> | |
| </div> | |
| </div> | |
| </form> | |
| </div> | |
| `; | |
| return R; | |
| } | |
| function editWithTabsTemplate(list) { | |
| var R = ` | |
| <div class="row"> | |
| <div class="col-lg-12"> | |
| <div class="tab-header"> | |
| <ma-view-actions override="::formController.actions" entry="entry" entity="::formController.entity"> | |
| <ma-list-button ng-if="::entity.listView().enabled" entity="::entity"></ma-list-button> | |
| <ma-delete-button ng-if="::entity.deletionView().enabled" entry="entry" entity="::entity"></ma-delete-button> | |
| </ma-view-actions> | |
| <h1 compile="::formController.title"> | |
| {{ 'EDIT' | translate }} {{ ::formController.entity.label() | humanize:true | singularize | translate }} #{{ ::entry.identifierValue }} | |
| </h1> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="row" id="edit-view" ng-class="::'ng-admin-entity-' + formController.entity.name()"> | |
| <form class="col-lg-12 form-horizontal" name="formController.form" ng-submit="formController.submitEdition($event)"> | |
| <uib-tabset active="active"> | |
| `; | |
| for(var i = 0; i < list.length; ++i) | |
| { | |
| R += '<uib-tab index="' +i+ '" heading="' +list[i].name+ '">' | |
| + '<div ng-repeat="field in ::formController.fields.slice(' +list[i].min+ ',' +list[i].max+ ' ) track by $index" compile="::field.getTemplateValueWithLabel(entry)">' | |
| + '<ma-field field="::field" value="entry.values[field.name()]" entry="entry" entity="::entity" form="formController.form" datastore="::formController.dataStore"></ma-field>' | |
| + '</div>' | |
| + '</uib-tab>'; | |
| } | |
| R += ` | |
| </uib-tabset> | |
| <div class="form-group"> | |
| <div class="col-sm-offset-2 col-sm-10"> | |
| <ma-submit-button label="SAVE_CHANGES"></ma-submit-button> | |
| </div> | |
| </div> | |
| </form> | |
| </div> | |
| `; | |
| return R; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment