| 1 | # Lemonldap::NG::Manager forms |
| 2 | |
| 3 | This files contains the form used to expose configuration attributes. The form |
| 4 | is chosen by looking at the *type* property of the current data. |
| 5 | |
| 6 | This property is defined in `Lemonldap::NG::Manager::Build::Attributes` package. |
| 7 | By default, it is set to *text*. |
| 8 | |
| 9 | `Lemonldap::NG::Manager::Build::Attributes` is compiled into JSON/JS files by |
| 10 | `jsongenerator.pl`script. |
| 11 | |
| 12 | ## 1. Form file architecture |
| 13 | |
| 14 | Form files must be called `<type>.json` where *<type>* is the declared type of |
| 15 | configuration property to display. |
| 16 | |
| 17 | Form files must contain only HTML that will be included in the manager DOM |
| 18 | *(in `#form` div)*. It **must** consist of two blocks: |
| 19 | |
| 20 | * a `<div class="panel panel-default">` div that contains the form, |
| 21 | * a `<script type="text/menu">` script that defines which item to display |
| 22 | in context menu. |
| 23 | |
| 24 | Basic example: |
| 25 | |
| 26 | <div class="panel panel-default"> |
| 27 | <div class="panel-heading"> |
| 28 | <h3 class="panel-title">{{translate(currentNode)}}</h3> |
| 29 | </div> |
| 30 | <div class="panel-body"> |
| 31 | <div class="input-group"> |
| 32 | <label class="input-group-addon" for="textinput" trspan="value"></label> |
| 33 | <input id="textinput" class="form-control" ng-model="currentNode.data"/> |
| 34 | </div> |
| 35 | </div> |
| 36 | </div> |
| 37 | <script type="text/menu"> |
| 38 | [{ |
| 39 | "title": "cancel" |
| 40 | }] |
| 41 | </script> |
| 42 | |
| 43 | ## 2. Form main div |
| 44 | |
| 45 | Based on bootstrap CSS, the main div part may look like: |
| 46 | |
| 47 | If configuration item name is read-only: |
| 48 | |
| 49 | <div class="panel panel-default"> |
| 50 | <div class="panel-heading"> |
| 51 | <h3 class="panel-title">{{translate(currentNode)}}</h3> |
| 52 | </div> |
| 53 | <div class="panel-body"> |
| 54 | __ FORM INPUTS __ |
| 55 | </div> |
| 56 | </div> |
| 57 | |
| 58 | If configuration item name may be modified: |
| 59 | |
| 60 | <div class="panel panel-default"> |
| 61 | <div class="panel-heading"> <!-- optional --> |
| 62 | <h3 class="panel-title" trspan="OptionalTitle"></h3> |
| 63 | </div> |
| 64 | <div class="panel-body"> |
| 65 | __ FORM INPUTS __ |
| 66 | </div> |
| 67 | </div> |
| 68 | |
| 69 | > Note that keywords to translate must be set in all `languages/*.json` files. |
| 70 | |
| 71 | ### 2.1. AngularJS bindings |
| 72 | |
| 73 | Some AngularJS variables are available : |
| 74 | |
| 75 | * `currentNode`: the data subnode corresponding to the selected tree item |
| 76 | * `currentScope`: the AngularJS scope corresponding to the selected tree item |
| 77 | |
| 78 | You can simply used them as follow: |
| 79 | |
| 80 | <input class="form-control" ng-model="currentNode.data"/> |
| 81 | |
| 82 | ## 3. Script part |
| 83 | |
| 84 | Form div **must** define which item menu to display. It is done via the script part |
| 85 | of the file: |
| 86 | |
| 87 | Empty context menu: |
| 88 | |
| 89 | <script type="text/menu"> |
| 90 | [] |
| 91 | </script> |
| 92 | |
| 93 | Else: |
| 94 | |
| 95 | <script type="text/menu"> |
| 96 | [ |
| 97 | {<menu item1>}, |
| 98 | {<menu item2>}, |
| 99 | {<menu item3>} |
| 100 | ] |
| 101 | </script> |
| 102 | |
| 103 | ### 3.1. Menu item |
| 104 | |
| 105 | #### 3.1.1. Simple case |
| 106 | |
| 107 | Menu item is a javascript object with at least the key `title`. |
| 108 | |
| 109 | <script type="text/menu"> |
| 110 | [ |
| 111 | { "title": "cancel" } |
| 112 | ] |
| 113 | </script> |
| 114 | |
| 115 | In this case, the item will be displayed using the translation of *cancel*. It |
| 116 | will launch the function `$scope.cancel()` declared in AngularJS controller |
| 117 | *(`js/manager.js` file)* without any argument: functions in the controller can |
| 118 | access to controller properties and methods. |
| 119 | |
| 120 | #### 3.1.2. Dropdown item |
| 121 | |
| 122 | You can have sub items simply using `buttons` key which must then be an array |
| 123 | of menu items. |
| 124 | |
| 125 | <script type="text/menu"> |
| 126 | [{ |
| 127 | "title": "textToTranslate", |
| 128 | "buttons": [ |
| 129 | { "title": "cancel" }, |
| 130 | { "other": "item" } |
| 131 | ] |
| 132 | }] |
| 133 | </script> |
| 134 | |
| 135 | #### 3.1.3. Specify function to use |
| 136 | |
| 137 | <script type="text/menu"> |
| 138 | [{ |
| 139 | "title": "addVirtualHost", |
| 140 | "action": "addVhost" |
| 141 | }] |
| 142 | </script> |
| 143 | |
| 144 | Same as below except that it will launch `$scope.addVhost()`. |
| 145 | |
| 146 | ##### Tips |
| 147 | |
| 148 | You can access to the parent using this: |
| 149 | |
| 150 | * `currentScope.$parentNodeScope` for the parent scope |
| 151 | * `currentScope.$parentNodeScope.$modelValue` for the parent node |
| 152 | |
| 153 | #### 3.1.5 Icons |
| 154 | |
| 155 | <script type="text/menu"> |
| 156 | [{ |
| 157 | "title": "addVirtualHost", |
| 158 | "action": "addVhost", |
| 159 | "icon": "plus-sign", |
| 160 | }] |
| 161 | </script> |
| 162 | |
| 163 | The field `icon` can be set to define the Bootstrap glyphicon to use. |
| 164 | |
| 165 | ## 4. Modal window |
| 166 | |
| 167 | You can use a modal window to display a choice (look at forms/portalSkin.html |
| 168 | for a complete example): |
| 169 | |
| 170 | <button class="btn btn-info" ng-click="showModal('portalSkinChoice.html')"> |
| 171 | |
| 172 | A modal window will be displayed using `portalSkinChoice.html` template. This |
| 173 | template must be declared in the file: |
| 174 | |
| 175 | <script type="text/ng-template" id="portalSkinChoice.html"> |
| 176 | <div class="modal-header"> |
| 177 | <h3 class="modal-title" trspan="chooseSkin"></h3> |
| 178 | </div> |
| 179 | <div class="modal-body"> |
| 180 | <div class="btn-group"> |
| 181 | <button class="btn" ng-repeat="b in currentNode.select" ng-click="ok(currentNode.data=b.k)"> |
| 182 | {{b.v}} |
| 183 | </button> |
| 184 | </div> |
| 185 | </div> |
| 186 | <div class="modal-footer"> |
| 187 | <button class="btn btn-primary" ng-click="ok()" trspan="ok"></button> |
| 188 | <button class="btn btn-warning" ng-click="cancel()" trspan="cancel"></button> |
| 189 | </div> |
| 190 | </script> |
| 191 |