4 copyObjectToScope = function(object, scope) {
7 Copy object (ng-repeat="object in objects") to scope without `hashKey`.
12 if (key !== '$$hashKey') {
18 angular.module('builder.controller', ['builder.provider']).controller('fbFormObjectEditableController', [
19 '$scope', '$injector', function($scope, $injector) {
21 $builder = $injector.get('$builder');
22 $scope.setupScope = function(formObject) {
25 1. Copy origin formObject (ng-repeat="object in formObjects") to scope.
26 2. Setup optionsText with formObject.options.
27 3. Watch scope.label, .description, .placeholder, .required, .options then copy to origin formObject.
28 4. Watch scope.optionsText then convert to scope.options.
29 5. setup validationOptions
32 copyObjectToScope(formObject, $scope);
33 $scope.optionsText = formObject.options.join('\n');
34 $scope.$watch('[label, description, placeholder, required, options, validation]', function() {
35 formObject.label = $scope.label;
36 formObject.description = $scope.description;
37 formObject.placeholder = $scope.placeholder;
38 formObject.required = $scope.required;
39 formObject.options = $scope.options;
40 return formObject.validation = $scope.validation;
42 $scope.$watch('optionsText', function(text) {
44 $scope.options = (function() {
45 var _i, _len, _ref, _results;
46 _ref = text.split('\n');
48 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
56 return $scope.inputText = $scope.options[0];
58 component = $builder.components[formObject.component];
59 return $scope.validationOptions = component.validationOptions;
61 return $scope.data = {
70 description: $scope.description,
71 placeholder: $scope.placeholder,
72 required: $scope.required,
73 optionsText: $scope.optionsText,
74 validation: $scope.validation
77 rollback: function() {
85 $scope.label = this.model.label;
86 $scope.description = this.model.description;
87 $scope.placeholder = this.model.placeholder;
88 $scope.required = this.model.required;
89 $scope.optionsText = this.model.optionsText;
90 return $scope.validation = this.model.validation;
94 ]).controller('fbComponentsController', [
95 '$scope', '$injector', function($scope, $injector) {
97 $builder = $injector.get('$builder');
98 $scope.selectGroup = function($event, group) {
99 var component, name, _ref, _results;
100 if ($event != null) {
101 $event.preventDefault();
103 $scope.activeGroup = group;
104 $scope.components = [];
105 _ref = $builder.components;
108 component = _ref[name];
109 if (component.group === group) {
110 _results.push($scope.components.push(component));
115 $scope.groups = $builder.groups;
116 $scope.activeGroup = $scope.groups[0];
117 $scope.allComponents = $builder.components;
118 return $scope.$watch('allComponents', function() {
119 return $scope.selectGroup(null, $scope.activeGroup);
122 ]).controller('fbComponentController', [
123 '$scope', function($scope) {
124 return $scope.copyObjectToScope = function(object) {
125 return copyObjectToScope(object, $scope);
128 ]).controller('fbFormController', [
129 '$scope', '$injector', function($scope, $injector) {
130 var $builder, $timeout;
131 $builder = $injector.get('$builder');
132 $timeout = $injector.get('$timeout');
133 if ($scope.input == null) {
136 return $scope.$watch('form', function() {
137 if ($scope.input.length > $scope.form.length) {
138 $scope.input.splice($scope.form.length);
140 return $timeout(function() {
141 return $scope.$broadcast($builder.broadcastChannel.updateInput);
145 ]).controller('fbFormObjectController', [
146 '$scope', '$injector', function($scope, $injector) {
148 $builder = $injector.get('$builder');
149 $scope.copyObjectToScope = function(object) {
150 return copyObjectToScope(object, $scope);
152 return $scope.updateInput = function(value) {
155 Copy current scope.input[X] to $parent.input.
156 @param value: The input value.
160 id: $scope.formObject.id,
161 label: $scope.formObject.label,
162 value: value != null ? value : ''
164 return $scope.$parent.input.splice($scope.$index, 1, input);
172 angular.module('builder.directive', ['builder.provider', 'builder.controller', 'builder.drag', 'validator']).directive('fbBuilder', [
173 '$injector', function($injector) {
175 $builder = $injector.get('$builder');
176 $drag = $injector.get('$drag');
182 template: "<div class='form-horizontal'>\n <div class='fb-form-object-editable' ng-repeat=\"object in formObjects\"\n fb-form-object-editable=\"object\"></div>\n</div>",
183 link: function(scope, element, attrs) {
184 var beginMove, _base, _name;
185 scope.formName = attrs.fbBuilder;
186 if ((_base = $builder.forms)[_name = scope.formName] == null) {
189 scope.formObjects = $builder.forms[scope.formName];
191 $(element).addClass('fb-builder');
192 return $drag.droppable($(element), {
194 var $empty, $formObject, $formObjects, height, index, offset, positions, _i, _j, _ref, _ref1;
196 $("div.fb-form-object-editable").popover('hide');
199 $formObjects = $(element).find('.fb-form-object-editable:not(.empty,.dragging)');
200 if ($formObjects.length === 0) {
201 if ($(element).find('.fb-form-object-editable.empty').length === 0) {
202 $(element).find('>div:first').append($("<div class='fb-form-object-editable empty'></div>"));
207 positions.push(-1000);
208 for (index = _i = 0, _ref = $formObjects.length; _i < _ref; index = _i += 1) {
209 $formObject = $($formObjects[index]);
210 offset = $formObject.offset();
211 height = $formObject.height();
212 positions.push(offset.top + height / 2);
214 positions.push(positions[positions.length - 1] + 1000);
215 for (index = _j = 1, _ref1 = positions.length; _j < _ref1; index = _j += 1) {
216 if (e.pageY > positions[index - 1] && e.pageY <= positions[index]) {
217 $(element).find('.empty').remove();
218 $empty = $("<div class='fb-form-object-editable empty'></div>");
219 if (index - 1 < $formObjects.length) {
220 $empty.insertBefore($($formObjects[index - 1]));
222 $empty.insertAfter($($formObjects[index - 2]));
230 $("div.fb-form-object-editable").popover('hide');
233 return $(element).find('.empty').remove();
235 up: function(e, isHover, draggable) {
236 var formObject, newIndex, oldIndex;
238 if (!$drag.isMouseMoved()) {
239 $(element).find('.empty').remove();
242 if (!isHover && draggable.mode === 'drag') {
243 formObject = draggable.object.formObject;
244 if (formObject.editable) {
245 $builder.removeFormObject(attrs.fbBuilder, formObject.index);
247 } else if (isHover) {
248 if (draggable.mode === 'mirror') {
249 $builder.insertFormObject(scope.formName, $(element).find('.empty').index('.fb-form-object-editable'), {
250 component: draggable.object.componentName
253 if (draggable.mode === 'drag') {
254 oldIndex = draggable.object.formObject.index;
255 newIndex = $(element).find('.empty').index('.fb-form-object-editable');
256 if (oldIndex < newIndex) {
259 $builder.updateFormObjectIndex(scope.formName, oldIndex, newIndex);
262 return $(element).find('.empty').remove();
268 ]).directive('fbFormObjectEditable', [
269 '$injector', function($injector) {
270 var $builder, $compile, $drag, $validator;
271 $builder = $injector.get('$builder');
272 $drag = $injector.get('$drag');
273 $compile = $injector.get('$compile');
274 $validator = $injector.get('$validator');
277 controller: 'fbFormObjectEditableController',
279 formObject: '=fbFormObjectEditable'
281 link: function(scope, element) {
283 scope.inputArray = [];
284 scope.$component = $builder.components[scope.formObject.component];
285 scope.setupScope(scope.formObject);
286 scope.$watch('$component.template', function(template) {
291 view = $compile(template)(scope);
292 return $(element).html(view);
294 $(element).on('click', function() {
297 $drag.draggable($(element), {
299 formObject: scope.formObject
302 if (!scope.formObject.editable) {
306 scope.$watch('$component.popoverTemplate', function(template) {
310 $(element).removeClass(popover.id);
312 id: "fb-" + (Math.random().toString().substr(2)),
313 isClickedSave: false,
317 popover.html = $(popover.html).addClass(popover.id);
318 popover.view = $compile(popover.html)(scope);
319 $(element).addClass(popover.id);
320 return $(element).popover({
322 title: scope.$component.label,
323 content: popover.view,
328 save: function($event) {
331 The save event of the popover.
333 $event.preventDefault();
334 $validator.validate(scope).success(function() {
335 popover.isClickedSave = true;
336 return $(element).popover('hide');
339 remove: function($event) {
342 The delete event of the popover.
344 $event.preventDefault();
345 $builder.removeFormObject(scope.$parent.formName, scope.$parent.$index);
346 $(element).popover('hide');
351 The shown event of the popover.
354 return popover.isClickedSave = false;
356 cancel: function($event) {
359 The cancel event of the popover.
361 scope.data.rollback();
363 $event.preventDefault();
364 $(element).popover('hide');
368 $(element).on('show.bs.popover', function() {
369 var $popover, elementOrigin, popoverTop;
370 if ($drag.isMouseMoved()) {
373 $("div.fb-form-object-editable:not(." + popover.id + ")").popover('hide');
374 $popover = $("form." + popover.id).closest('.popover');
375 if ($popover.length > 0) {
376 elementOrigin = $(element).offset().top + $(element).height() / 2;
377 popoverTop = elementOrigin - $popover.height() / 2;
379 position: 'absolute',
383 setTimeout(function() {
384 $popover.addClass('in');
385 return $(element).triggerHandler('shown.bs.popover');
390 $(element).on('shown.bs.popover', function() {
391 $(".popover ." + popover.id + " input:first").select();
392 scope.$apply(function() {
393 return scope.popover.shown();
396 return $(element).on('hide.bs.popover', function() {
398 $popover = $("form." + popover.id).closest('.popover');
399 if (!popover.isClickedSave) {
400 if (scope.$$phase || scope.$root.$$phase) {
401 scope.popover.cancel();
403 scope.$apply(function() {
404 return scope.popover.cancel();
408 $popover.removeClass('in');
409 setTimeout(function() {
410 return $popover.hide();
417 ]).directive('fbComponents', function() {
420 template: "<ul ng-if=\"groups.length > 1\" class=\"nav nav-tabs nav-justified\">\n <li ng-repeat=\"group in groups\" ng-class=\"{active:activeGroup==group}\">\n <a href='#' ng-click=\"selectGroup($event, group)\">{{group}}</a>\n </li>\n</ul>\n<div class='form-horizontal'>\n <div class='fb-component' ng-repeat=\"component in components\"\n fb-component=\"component\"></div>\n</div>",
421 controller: 'fbComponentsController'
423 }).directive('fbComponent', [
424 '$injector', function($injector) {
425 var $builder, $compile, $drag;
426 $builder = $injector.get('$builder');
427 $drag = $injector.get('$drag');
428 $compile = $injector.get('$compile');
432 component: '=fbComponent'
434 controller: 'fbComponentController',
435 link: function(scope, element) {
436 scope.copyObjectToScope(scope.component);
437 $drag.draggable($(element), {
441 componentName: scope.component.name
444 return scope.$watch('component.template', function(template) {
449 view = $compile(template)(scope);
450 return $(element).html(view);
455 ]).directive('fbForm', [
456 '$injector', function($injector) {
463 "default": '=fbDefault'
465 template: "<div class='fb-form-object' ng-repeat=\"object in form\" fb-form-object=\"object\"></div>",
466 controller: 'fbFormController',
467 link: function(scope, element, attrs) {
468 var $builder, _base, _name;
469 $builder = $injector.get('$builder');
470 if ((_base = $builder.forms)[_name = scope.formName] == null) {
473 return scope.form = $builder.forms[scope.formName];
477 ]).directive('fbFormObject', [
478 '$injector', function($injector) {
479 var $builder, $compile, $parse;
480 $builder = $injector.get('$builder');
481 $compile = $injector.get('$compile');
482 $parse = $injector.get('$parse');
485 controller: 'fbFormObjectController',
486 link: function(scope, element, attrs) {
487 scope.formObject = $parse(attrs.fbFormObject)(scope);
488 scope.$component = $builder.components[scope.formObject.component];
489 scope.$on($builder.broadcastChannel.updateInput, function() {
490 return scope.updateInput(scope.inputText);
492 if (scope.$component.arrayToText) {
493 scope.inputArray = [];
494 scope.$watch('inputArray', function(newValue, oldValue) {
496 if (newValue === oldValue) {
500 for (index in scope.inputArray) {
501 if (scope.inputArray[index]) {
502 checked.push(scope.options[index]);
505 return scope.inputText = checked.join(', ');
508 scope.$watch('inputText', function() {
509 return scope.updateInput(scope.inputText);
511 scope.$watch(attrs.fbFormObject, function() {
512 return scope.copyObjectToScope(scope.formObject);
514 scope.$watch('$component.template', function(template) {
515 var $input, $template, view;
519 $template = $(template);
520 $input = $template.find("[ng-model='inputText']");
522 validator: '{{validation}}'
524 view = $compile($template)(scope);
525 return $(element).html(view);
527 if (!scope.$component.arrayToText && scope.formObject.options.length > 0) {
528 scope.inputText = scope.formObject.options[0];
530 return scope.$watch("default[" + scope.formObject.id + "]", function(value) {
534 if (scope.$component.arrayToText) {
535 return scope.inputArray = value;
537 return scope.inputText = value;
548 angular.module('builder.drag', []).provider('$drag', function() {
549 var $injector, $rootScope, delay;
556 this.mouseMoved = false;
557 this.isMouseMoved = (function(_this) {
559 return _this.mouseMoved;
567 this.eventMouseMove = function() {};
568 this.eventMouseUp = function() {};
571 $(document).on('mousedown', function(e) {
573 _this.mouseMoved = false;
574 _ref = _this.hooks.down;
580 $(document).on('mousemove', function(e) {
582 _this.mouseMoved = true;
583 _ref = _this.hooks.move;
589 return $(document).on('mouseup', function(e) {
591 _ref = _this.hooks.up;
600 this.getNewId = (function(_this) {
602 return "" + (_this.currentId++);
605 this.setupEasing = function() {
606 return jQuery.extend(jQuery.easing, {
607 easeOutQuad: function(x, t, b, c, d) {
608 return -c * (t /= d) * (t - 2) + b;
612 this.setupProviders = function(injector) {
617 $injector = injector;
618 return $rootScope = $injector.get('$rootScope');
620 this.isHover = (function(_this) {
621 return function($elementA, $elementB) {
624 Is element A hover on element B?
625 @param $elementA: jQuery object
626 @param $elementB: jQuery object
628 var isHover, offsetA, offsetB, sizeA, sizeB;
629 offsetA = $elementA.offset();
630 offsetB = $elementB.offset();
632 width: $elementA.width(),
633 height: $elementA.height()
636 width: $elementB.width(),
637 height: $elementB.height()
643 isHover.x = offsetA.left > offsetB.left && offsetA.left < offsetB.left + sizeB.width;
644 isHover.x = isHover.x || offsetA.left + sizeA.width > offsetB.left && offsetA.left + sizeA.width < offsetB.left + sizeB.width;
648 isHover.y = offsetA.top > offsetB.top && offsetA.top < offsetB.top + sizeB.height;
649 isHover.y = isHover.y || offsetA.top + sizeA.height > offsetB.top && offsetA.top + sizeA.height < offsetB.top + sizeB.height;
650 return isHover.x && isHover.y;
653 delay = function(ms, func) {
654 return setTimeout(function() {
662 scroll: (function(_this) {
664 _this.autoScroll.scrolling = true;
665 if (_this.autoScroll.up) {
666 $('html, body').dequeue().animate({
667 scrollTop: $(window).scrollTop() - 50
668 }, 100, 'easeOutQuad');
669 return delay(100, function() {
670 return _this.autoScroll.scroll();
672 } else if (_this.autoScroll.down) {
673 $('html, body').dequeue().animate({
674 scrollTop: $(window).scrollTop() + 50
675 }, 100, 'easeOutQuad');
676 return delay(100, function() {
677 return _this.autoScroll.scroll();
680 return _this.autoScroll.scrolling = false;
684 start: (function(_this) {
686 if (e.clientY < 50) {
687 _this.autoScroll.up = true;
688 _this.autoScroll.down = false;
689 if (!_this.autoScroll.scrolling) {
690 return _this.autoScroll.scroll();
692 } else if (e.clientY > $(window).innerHeight() - 50) {
693 _this.autoScroll.up = false;
694 _this.autoScroll.down = true;
695 if (!_this.autoScroll.scrolling) {
696 return _this.autoScroll.scroll();
699 _this.autoScroll.up = false;
700 return _this.autoScroll.down = false;
704 stop: (function(_this) {
706 _this.autoScroll.up = false;
707 return _this.autoScroll.down = false;
711 this.dragMirrorMode = (function(_this) {
712 return function($element, defer, object) {
718 id: _this.getNewId(),
720 maternal: $element[0],
724 $element.on('mousedown', function(e) {
727 $clone = $element.clone();
728 result.element = $clone[0];
729 $clone.addClass("fb-draggable form-horizontal prepare-dragging");
730 _this.hooks.move.drag = function(e, defer) {
731 var droppable, id, _ref, _results;
732 if ($clone.hasClass('prepare-dragging')) {
734 width: $element.width(),
735 height: $element.height()
737 $clone.removeClass('prepare-dragging');
738 $clone.addClass('dragging');
744 left: e.pageX - $clone.width() / 2,
745 top: e.pageY - $clone.height() / 2
747 _this.autoScroll.start(e);
748 _ref = _this.data.droppables;
751 droppable = _ref[id];
752 if (_this.isHover($clone, $(droppable.element))) {
753 _results.push(droppable.move(e, result));
755 _results.push(droppable.out(e, result));
760 _this.hooks.up.drag = function(e) {
761 var droppable, id, isHover, _ref;
762 _ref = _this.data.droppables;
764 droppable = _ref[id];
765 isHover = _this.isHover($clone, $(droppable.element));
766 droppable.up(e, isHover, result);
768 delete _this.hooks.move.drag;
769 delete _this.hooks.up.drag;
770 result.element = null;
772 return _this.autoScroll.stop();
774 $('body').append($clone);
776 return _this.hooks.move.drag(e, defer);
782 this.dragDragMode = (function(_this) {
783 return function($element, defer, object) {
789 id: _this.getNewId(),
792 element: $element[0],
795 $element.addClass('fb-draggable');
796 $element.on('mousedown', function(e) {
798 if ($element.hasClass('dragging')) {
801 $element.addClass('prepare-dragging');
802 _this.hooks.move.drag = function(e, defer) {
803 var droppable, id, _ref;
804 if ($element.hasClass('prepare-dragging')) {
806 width: $element.width(),
807 height: $element.height()
809 $element.removeClass('prepare-dragging');
810 $element.addClass('dragging');
816 left: e.pageX - $element.width() / 2,
817 top: e.pageY - $element.height() / 2
819 _this.autoScroll.start(e);
820 _ref = _this.data.droppables;
822 droppable = _ref[id];
823 if (_this.isHover($element, $(droppable.element))) {
824 droppable.move(e, result);
826 droppable.out(e, result);
830 _this.hooks.up.drag = function(e) {
831 var droppable, id, isHover, _ref;
832 _ref = _this.data.droppables;
834 droppable = _ref[id];
835 isHover = _this.isHover($element, $(droppable.element));
836 droppable.up(e, isHover, result);
838 delete _this.hooks.move.drag;
839 delete _this.hooks.up.drag;
846 $element.removeClass('dragging defer-dragging');
847 return _this.autoScroll.stop();
850 return _this.hooks.move.drag(e, defer);
856 this.dropMode = (function(_this) {
857 return function($element, options) {
860 id: _this.getNewId(),
861 element: $element[0],
862 move: function(e, draggable) {
863 return $rootScope.$apply(function() {
864 return typeof options.move === "function" ? options.move(e, draggable) : void 0;
867 up: function(e, isHover, draggable) {
868 return $rootScope.$apply(function() {
869 return typeof options.up === "function" ? options.up(e, isHover, draggable) : void 0;
872 out: function(e, draggable) {
873 return $rootScope.$apply(function() {
874 return typeof options.out === "function" ? options.out(e, draggable) : void 0;
881 this.draggable = (function(_this) {
882 return function($element, options) {
883 var draggable, element, result, _i, _j, _len, _len1;
884 if (options == null) {
889 Make the element could be drag.
890 @param element: The jQuery element.
891 @param options: Options
892 mode: 'drag' [default], 'mirror'
893 defer: yes/no. defer dragging
894 object: custom information
897 if (options.mode === 'mirror') {
898 for (_i = 0, _len = $element.length; _i < _len; _i++) {
899 element = $element[_i];
900 draggable = _this.dragMirrorMode($(element), options.defer, options.object);
901 result.push(draggable.id);
902 _this.data.draggables[draggable.id] = draggable;
905 for (_j = 0, _len1 = $element.length; _j < _len1; _j++) {
906 element = $element[_j];
907 draggable = _this.dragDragMode($(element), options.defer, options.object);
908 result.push(draggable.id);
909 _this.data.draggables[draggable.id] = draggable;
915 this.droppable = (function(_this) {
916 return function($element, options) {
917 var droppable, element, result, _i, _len;
918 if (options == null) {
923 Make the element coulde be drop.
924 @param $element: The jQuery element.
925 @param options: The droppable options.
926 move: The custom mouse move callback. (e, draggable)->
927 up: The custom mouse up callback. (e, isHover, draggable)->
928 out: The custom mouse out callback. (e, draggable)->
931 for (_i = 0, _len = $element.length; _i < _len; _i++) {
932 element = $element[_i];
933 droppable = _this.dropMode($(element), options);
934 result.push(droppable);
935 _this.data.droppables[droppable.id] = droppable;
940 this.get = function($injector) {
942 this.setupProviders($injector);
944 isMouseMoved: this.isMouseMoved,
946 draggable: this.draggable,
947 droppable: this.droppable
950 this.get.$inject = ['$injector'];
951 this.$get = this.get;
957 angular.module('builder', ['builder.directive']);
965 The base components are textInput, textArea, select, check, radio.
966 User can custom the form with components.
968 It is like an object (an instance of the component).
969 User can custom the label, description, required and validation of the input.
971 This is for end-user. There are form groups int the form.
972 They can input the value to the form.
976 var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
978 angular.module('builder.provider', []).provider('$builder', function() {
979 var $http, $injector, $templateCache;
982 $templateCache = null;
983 this.version = '0.0.2';
984 this.components = {};
986 this.broadcastChannel = {
987 updateInput: '$updateInput'
995 this.convertComponent = function(name, component) {
996 var result, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
999 group: (_ref = component.group) != null ? _ref : 'Default',
1000 label: (_ref1 = component.label) != null ? _ref1 : '',
1001 description: (_ref2 = component.description) != null ? _ref2 : '',
1002 placeholder: (_ref3 = component.placeholder) != null ? _ref3 : '',
1003 editable: (_ref4 = component.editable) != null ? _ref4 : true,
1004 required: (_ref5 = component.required) != null ? _ref5 : false,
1005 validation: (_ref6 = component.validation) != null ? _ref6 : '/.*/',
1006 validationOptions: (_ref7 = component.validationOptions) != null ? _ref7 : [],
1007 options: (_ref8 = component.options) != null ? _ref8 : [],
1008 arrayToText: (_ref9 = component.arrayToText) != null ? _ref9 : false,
1009 template: component.template,
1010 templateUrl: component.templateUrl,
1011 popoverTemplate: component.popoverTemplate,
1012 popoverTemplateUrl: component.popoverTemplateUrl
1014 if (!result.template && !result.templateUrl) {
1015 console.error("The template is empty.");
1017 if (!result.popoverTemplate && !result.popoverTemplateUrl) {
1018 console.error("The popoverTemplate is empty.");
1022 this.convertFormObject = function(name, formObject) {
1023 var component, exist, form, result, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
1024 if (formObject == null) {
1027 component = this.components[formObject.component];
1028 if (component == null) {
1029 throw "The component " + formObject.component + " was not registered.";
1031 if (formObject.id) {
1033 _ref = this.forms[name];
1034 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1036 if (!(formObject.id <= form.id)) {
1039 formObject.id = this.formsId[name]++;
1044 this.formsId[name] = formObject.id + 1;
1048 id: (_ref1 = formObject.id) != null ? _ref1 : this.formsId[name]++,
1049 component: formObject.component,
1050 editable: (_ref2 = formObject.editable) != null ? _ref2 : component.editable,
1051 index: (_ref3 = formObject.index) != null ? _ref3 : 0,
1052 label: (_ref4 = formObject.label) != null ? _ref4 : component.label,
1053 description: (_ref5 = formObject.description) != null ? _ref5 : component.description,
1054 placeholder: (_ref6 = formObject.placeholder) != null ? _ref6 : component.placeholder,
1055 options: (_ref7 = formObject.options) != null ? _ref7 : component.options,
1056 required: (_ref8 = formObject.required) != null ? _ref8 : component.required,
1057 validation: (_ref9 = formObject.validation) != null ? _ref9 : component.validation
1061 this.reindexFormObject = (function(_this) {
1062 return function(name) {
1063 var formObjects, index, _i, _ref;
1064 formObjects = _this.forms[name];
1065 for (index = _i = 0, _ref = formObjects.length; _i < _ref; index = _i += 1) {
1066 formObjects[index].index = index;
1070 this.setupProviders = (function(_this) {
1071 return function(injector) {
1072 $injector = injector;
1073 $http = $injector.get('$http');
1074 return $templateCache = $injector.get('$templateCache');
1077 this.loadTemplate = function(component) {
1080 Load template for components.
1081 @param component: {object} The component of $builder.
1083 if (component.template == null) {
1084 $http.get(component.templateUrl, {
1085 cache: $templateCache
1086 }).success(function(template) {
1087 return component.template = template;
1090 if (component.popoverTemplate == null) {
1091 return $http.get(component.popoverTemplateUrl, {
1092 cache: $templateCache
1093 }).success(function(template) {
1094 return component.popoverTemplate = template;
1098 this.registerComponent = (function(_this) {
1099 return function(name, component) {
1100 var newComponent, _ref;
1101 if (component == null) {
1106 Register the component for form-builder.
1107 @param name: The component name.
1108 @param component: The component object.
1109 group: {string} The component group.
1110 label: {string} The label of the input.
1111 description: {string} The description of the input.
1112 placeholder: {string} The placeholder of the input.
1113 editable: {bool} Is the form object editable?
1114 required: {bool} Is the form object required?
1115 validation: {string} angular-validator. "/regex/" or "[rule1, rule2]". (default is RegExp(.*))
1116 validationOptions: {array} [{rule: angular-validator, label: 'option label'}] the options for the validation. (default is [])
1117 options: {array} The input options.
1118 arrayToText: {bool} checkbox could use this to convert input (default is no)
1119 template: {string} html template
1120 templateUrl: {string} The url of the template.
1121 popoverTemplate: {string} html template
1122 popoverTemplateUrl: {string} The url of the popover template.
1124 if (_this.components[name] == null) {
1125 newComponent = _this.convertComponent(name, component);
1126 _this.components[name] = newComponent;
1127 if ($injector != null) {
1128 _this.loadTemplate(newComponent);
1130 if (_ref = newComponent.group, __indexOf.call(_this.groups, _ref) < 0) {
1131 _this.groups.push(newComponent.group);
1134 console.error("The component " + name + " was registered.");
1138 this.addFormObject = (function(_this) {
1139 return function(name, formObject) {
1141 if (formObject == null) {
1146 Insert the form object into the form at last.
1148 if ((_base = _this.forms)[name] == null) {
1151 return _this.insertFormObject(name, _this.forms[name].length, formObject);
1154 this.insertFormObject = (function(_this) {
1155 return function(name, index, formObject) {
1157 if (formObject == null) {
1162 Insert the form object into the form at {index}.
1163 @param name: The form name.
1164 @param index: The form object index.
1165 @param form: The form object.
1166 id: {int} The form object id. It will be generate by $builder if not asigned.
1167 component: {string} The component name
1168 editable: {bool} Is the form object editable? (default is yes)
1169 label: {string} The form object label.
1170 description: {string} The form object description.
1171 placeholder: {string} The form object placeholder.
1172 options: {array} The form object options.
1173 required: {bool} Is the form object required? (default is no)
1174 validation: {string} angular-validator. "/regex/" or "[rule1, rule2]".
1175 [index]: {int} The form object index. It will be updated by $builder.
1176 @return: The form object.
1178 if ((_base = _this.forms)[name] == null) {
1181 if ((_base1 = _this.formsId)[name] == null) {
1184 if (index > _this.forms[name].length) {
1185 index = _this.forms[name].length;
1186 } else if (index < 0) {
1189 _this.forms[name].splice(index, 0, _this.convertFormObject(name, formObject));
1190 _this.reindexFormObject(name);
1191 return _this.forms[name][index];
1194 this.removeFormObject = (function(_this) {
1195 return function(name, index) {
1198 Remove the form object by the index.
1199 @param name: The form name.
1200 @param index: The form object index.
1203 formObjects = _this.forms[name];
1204 formObjects.splice(index, 1);
1205 return _this.reindexFormObject(name);
1208 this.updateFormObjectIndex = (function(_this) {
1209 return function(name, oldIndex, newIndex) {
1212 Update the index of the form object.
1213 @param name: The form name.
1214 @param oldIndex: The old index.
1215 @param newIndex: The new index.
1217 var formObject, formObjects;
1218 if (oldIndex === newIndex) {
1221 formObjects = _this.forms[name];
1222 formObject = formObjects.splice(oldIndex, 1)[0];
1223 formObjects.splice(newIndex, 0, formObject);
1224 return _this.reindexFormObject(name);
1228 '$injector', (function(_this) {
1229 return function($injector) {
1230 var component, name, _ref;
1231 _this.setupProviders($injector);
1232 _ref = _this.components;
1233 for (name in _ref) {
1234 component = _ref[name];
1235 _this.loadTemplate(component);
1238 version: _this.version,
1239 components: _this.components,
1240 groups: _this.groups,
1242 broadcastChannel: _this.broadcastChannel,
1243 registerComponent: _this.registerComponent,
1244 addFormObject: _this.addFormObject,
1245 insertFormObject: _this.insertFormObject,
1246 removeFormObject: _this.removeFormObject,
1247 updateFormObjectIndex: _this.updateFormObjectIndex