index_easyFormViewer.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <!DOCTYPE html>
  2. <html lang="en" ng-app="appDemo">
  3. <head>
  4. <title>Easy form generator</title>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <meta name="description" content="create amazing forms without coding : form editor based on angular formly">
  9. <meta name="author" content="Erwan Datin (MacKentoch)">
  10. <!-- IMPORTANT : angular js lib (here for better result with ng-cloak) -->
  11. <script type="text/javascript" src="./public/lib/js/angular.min.js"></script>
  12. <!-- Bootstrap core CSS -->
  13. <link href="./public/lib/css/bootstrap.min.css" rel="stylesheet">
  14. <!-- font-awesome -->
  15. <link href="./public/lib/css/font-awesome.min.css" rel="stylesheet">
  16. <!-- animate -->
  17. <link href="./public/lib/css/animate.min.css" rel="stylesheet">
  18. <!-- textAngular -->
  19. <link rel='stylesheet' href='./public/lib/css/textAngular.min.css'>
  20. <!-- nya select bootstrap -->
  21. <link rel='stylesheet' href='./public/lib/css/nya-bs-select.min.css'>
  22. <!-- Custom styles for this template -->
  23. <link href="./public/css/eda.easyFormViewer.css" rel="stylesheet">
  24. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  25. <!--[if lt IE 9]>
  26. <script src="./public/lib/html5shiv/dist/html5shiv.min.js"></script>
  27. <script src="./public/lib/respondJS/dest/respond.min.js"></script>
  28. <![endif]-->
  29. </head>
  30. <!-- NOTE : ng-cloak here is not optimal solution : better to use it only where it is needed (I just take a shortcut as this an example not a production sample) -->
  31. <body ng-controller="demoController as demoCtrl" ng-cloak>
  32. <div>
  33. <!-- Easy Form viewer
  34. =============================================================-->
  35. <eda-easy-form-viewer
  36. eda-easy-form-viewer-data-model="demoCtrl.dataModel"
  37. eda-easy-form-viewer-easy-form-generator-fields-model="demoCtrl.fieldsModel"
  38. eda-easy-form-viewer-submit-button-text="{{demoCtrl.submitButtonText}}"
  39. eda-easy-form-viewer-cancel-button-text="{{demoCtrl.cancelButtonText}}"
  40. eda-easy-form-viewer-submit-form-event="demoCtrl.submitFormEvent(dataModelSubmitted)"
  41. eda-easy-form-viewer-cancel-form-event="demoCtrl.cancelFormEvent()">
  42. </eda-easy-form-viewer>
  43. <!--demo purpose : no use apart from that-->
  44. <div ng-if="demoCtrl.showDataModel" class="row">
  45. <div class="col-md-12">
  46. <pre>
  47. {{demoCtrl.dataModel}}
  48. </pre>
  49. </div>
  50. </div>
  51. </div>
  52. <script type="text/javascript">
  53. //demo purpose : here should be your app
  54. //just inject easy form generator and bind properties
  55. //then,
  56. (function(){
  57. 'use strict';
  58. angular
  59. .module('appDemo', [
  60. 'eda.easyFormViewer' //injects easy form viewer
  61. ])
  62. .controller('demoController', demoController);
  63. demoController.$inject = ['$timeout'];
  64. function demoController($timeout){
  65. var demoCtrl = this;
  66. demoCtrl.showDataModel = true; //demo purpose only : to show data model in html
  67. demoCtrl.fieldsModel = testACompleteForm();
  68. demoCtrl.dataModel = {};
  69. demoCtrl.submitButtonText = 'Submit this form';
  70. demoCtrl.cancelButtonText = 'Cancel all';
  71. demoCtrl.submitFormEvent = submitFormEvent;
  72. demoCtrl.cancelFormEvent = cancelFormEvent;
  73. //demo purpose only :
  74. //in 3 seconds a new form will be bound to easy form generator :
  75. timedModelChanged();
  76. /**
  77. * when click on save form, will call your save form function :
  78. */
  79. function submitFormEvent(dataModelSubmitted){
  80. console.info('-> Submit Event (in your controller) : you can save form data entered by user.');
  81. console.dir( {'dataModel' : dataModelSubmitted} );
  82. /**
  83. *
  84. * MORE DETAILS ON 'easyFormGeneratorModel'
  85. * ----------------------------------------
  86. *
  87. * easy form generator model properties:
  88. *
  89. * - formName : {string} (at save step you name your form)
  90. * - btnSubmitText : {string} (if 'Submit' does not suits to you change submit button name)
  91. * - btnCancelText : {string} (if 'Cancel' does not suits to you change cancel button name)
  92. * - edaFieldsModel : {array} - easy form generator model that describe form
  93. * - edaFieldsModelStringified : {string} - exactly same as edaFieldsModel it is just stringified
  94. * - formlyFieldsModel : {object} - easy form generator model translate by itself 'edaFieldsModel' to 'angular formly fields model' -> usefull is you just need a formly directive
  95. * - dataModel : {object} - this object is filled when filling form.
  96. */
  97. }
  98. function cancelFormEvent(){
  99. console.info('-> Cancel Event (in your controller) : you can add behaviours if you need to.');
  100. }
  101. /**
  102. * to simulate server async load of a form model (3 seconds is eternity I hope your server won't take so much time)
  103. *
  104. * easy form generator will render it when timer done
  105. */
  106. function timedModelChanged(){
  107. $timeout(function(){
  108. demoCtrl.fieldsModel = testACompleteForm();
  109. console.info('timeout in demo controller : fields model changed');
  110. console.dir(demoCtrl.fieldsModel);
  111. }, 3000);
  112. }
  113. /**
  114. * an easy form generator model as demo
  115. *
  116. * here as a demo, it could be retrieved from a database
  117. */
  118. function testACompleteForm(){
  119. var _testACompleteForm = [
  120. {
  121. "line": 1,
  122. "activeColumn": 1,
  123. "columns": [
  124. {
  125. "numColumn": 1,
  126. "exist": true,
  127. "control": {
  128. "type": "header",
  129. "key": "header-1441426238190",
  130. "selectedControl": "Header",
  131. "subtype": "",
  132. "templateOptions": {
  133. "label": "",
  134. "required": false,
  135. "description": "EasyFormViewer : Loaded Form",
  136. "placeholder": "",
  137. "options": []
  138. },
  139. "formlyExpressionProperties": {},
  140. "formlyValidators": {},
  141. "formlyValidation": {},
  142. "edited": true
  143. }
  144. }
  145. ]
  146. },
  147. {
  148. "line": -1,
  149. "activeColumn": 1,
  150. "columns": [
  151. {
  152. "numColumn": 1,
  153. "exist": true,
  154. "control": {
  155. "type": "input",
  156. "key": "input-1441426278314",
  157. "selectedControl": "TextInput",
  158. "subtype": "",
  159. "templateOptions": {
  160. "label": "text input",
  161. "required": true,
  162. "description": "text input",
  163. "placeholder": "text input",
  164. "options": []
  165. },
  166. "formlyExpressionProperties": {},
  167. "formlyValidators": {},
  168. "formlyValidation": {
  169. "messages": {}
  170. },
  171. "edited": true
  172. }
  173. },
  174. {
  175. "numColumn": 2,
  176. "exist": true,
  177. "control": {
  178. "type": "input",
  179. "key": "input-1441426295927",
  180. "selectedControl": "Password",
  181. "subtype": "password",
  182. "templateOptions": {
  183. "label": "password",
  184. "required": true,
  185. "description": "password",
  186. "placeholder": "password",
  187. "options": []
  188. },
  189. "formlyExpressionProperties": {},
  190. "formlyValidators": {},
  191. "formlyValidation": {
  192. "messages": {}
  193. },
  194. "edited": true
  195. }
  196. },
  197. {
  198. "numColumn": 3,
  199. "exist": true,
  200. "control": {
  201. "type": "input",
  202. "key": "input-1441426313388",
  203. "selectedControl": "Email",
  204. "subtype": "email",
  205. "templateOptions": {
  206. "label": "email",
  207. "required": true,
  208. "description": "email",
  209. "placeholder": "email",
  210. "options": []
  211. },
  212. "formlyExpressionProperties": {},
  213. "formlyValidators": {
  214. "emailShape": {
  215. "message": "$viewValue + ' is not a valid email'"
  216. }
  217. },
  218. "formlyValidation": {
  219. "messages": {}
  220. },
  221. "edited": true
  222. }
  223. }
  224. ]
  225. },
  226. {
  227. "line": -1,
  228. "activeColumn": 1,
  229. "columns": [
  230. {
  231. "numColumn": 1,
  232. "exist": true,
  233. "control": {
  234. "type": "datepicker",
  235. "key": "datepicker-1441426325143",
  236. "selectedControl": "Date",
  237. "subtype": "",
  238. "templateOptions": {
  239. "label": "date",
  240. "required": true,
  241. "description": "date",
  242. "placeholder": "",
  243. "options": [],
  244. "datepickerOptions": {
  245. "format": "dd.MM.yyyy"
  246. },
  247. "datepickerPopup": "dd-MMMM-yyyy"
  248. },
  249. "formlyExpressionProperties": {},
  250. "formlyValidators": {},
  251. "formlyValidation": {
  252. "messages": {}
  253. },
  254. "edited": true
  255. }
  256. },
  257. {
  258. "numColumn": 2,
  259. "exist": true,
  260. "control": {
  261. "type": "basicSelect",
  262. "key": "basicSelect-1441426346817",
  263. "selectedControl": "BasicSelect",
  264. "subtype": "",
  265. "templateOptions": {
  266. "label": "",
  267. "required": false,
  268. "description": "",
  269. "placeholder": "",
  270. "options": [
  271. {
  272. "name": "opt1",
  273. "value": 0,
  274. "group": ""
  275. },
  276. {
  277. "name": "opt2",
  278. "value": 1,
  279. "group": ""
  280. },
  281. {
  282. "name": "opt3",
  283. "value": 2,
  284. "group": ""
  285. }
  286. ]
  287. },
  288. "formlyExpressionProperties": {},
  289. "formlyValidators": {},
  290. "formlyValidation": {
  291. "messages": {}
  292. },
  293. "edited": true
  294. }
  295. }
  296. ]
  297. },
  298. {
  299. "line": -1,
  300. "activeColumn": 1,
  301. "columns": [
  302. {
  303. "numColumn": 1,
  304. "exist": true,
  305. "control": {
  306. "type": "richEditor",
  307. "key": "richEditor-1441426365355",
  308. "selectedControl": "RichTextEditor",
  309. "subtype": "",
  310. "templateOptions": {
  311. "label": "",
  312. "required": false,
  313. "description": "",
  314. "placeholder": "",
  315. "options": []
  316. },
  317. "formlyExpressionProperties": {},
  318. "formlyValidators": {},
  319. "formlyValidation": {
  320. "messages": {}
  321. },
  322. "edited": true
  323. }
  324. }
  325. ]
  326. }
  327. ]
  328. return _testACompleteForm;
  329. }
  330. }
  331. })();
  332. </script>
  333. <!-- footer : declare JS dependencies
  334. =============================================================-->
  335. <footer id="pageFooter">
  336. <!-- jquery framework : top 1 priority -->
  337. <script type="text/javascript" src="./public/lib/js/jquery.min.js"></script>
  338. <!-- bootstrap framework scripts -->
  339. <script type="text/javascript" src="./public/lib/js/bootstrap.min.js"></script>
  340. <!-- angular ui bootstrap -->
  341. <script type="text/javascript" src="./public/lib/js/ui-bootstrap-tpls.min.js"></script>
  342. <!-- angular app all concatenated here (app, controllers directives, containers ...) -->
  343. <script type="text/javascript" src="./public/js/eda.easyFormViewer.js"></script>
  344. <!-- textAngular Includes -->
  345. <script src='./public/lib/js/textAngular-rangy.min.js'></script>
  346. <script src='./public/lib/js/textAngular-sanitize.min.js'></script>
  347. <script src='./public/lib/js/textAngular.min.js'></script>
  348. <!-- lodash -->
  349. <script src='./public/lib/js/lodash.min.js'></script>
  350. <!-- angular animate -->
  351. <script type="text/javascript" src="./public/lib/js/angular-animate.min.js"></script>
  352. <!-- nya select bootstrap -->
  353. <script type="text/javascript" src="./public/lib/js/nya-bs-select.min.js"></script>
  354. <!-- api-check = formly needed : IMPORTANT : always before formly -->
  355. <script type="text/javascript" src="./public/lib/js/api-check.min.js"></script>
  356. <!-- angular formly -->
  357. <script type="text/javascript" src="./public/lib/js/formly.min.js"></script>
  358. <!-- angular formly template bootstrap -->
  359. <script type="text/javascript" src="./public/lib/js/angular-formly-templates-bootstrap.min.js"></script>
  360. </footer>
  361. </body>
  362. </html>