OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 YUI.add('juju-view-utils', function(Y) { | 3 YUI.add('juju-view-utils', function(Y) { |
4 | 4 |
5 var views = Y.namespace('juju.views'), | 5 var views = Y.namespace('juju.views'), |
6 utils = Y.namespace('juju.views.utils'); | 6 utils = Y.namespace('juju.views.utils'); |
7 | 7 |
8 var timestrings = { | 8 var timestrings = { |
9 prefixAgo: null, | 9 prefixAgo: null, |
10 prefixFromNow: null, | 10 prefixFromNow: null, |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 } else if (!isFloat(value)) { | 600 } else if (!isFloat(value)) { |
601 errors[name] = 'The value "' + value + '" is not a float.'; | 601 errors[name] = 'The value "' + value + '" is not a float.'; |
602 } | 602 } |
603 } | 603 } |
604 | 604 |
605 }); | 605 }); |
606 return errors; | 606 return errors; |
607 }; | 607 }; |
608 | 608 |
609 | 609 |
610 /* | 610 /** |
611 * Utility class that encapsulates Y.Models and keeps their position | 611 * Utility object that encapsulates Y.Models and keeps their position |
612 * state within an svg canvas. | 612 * state within an SVG canvas. |
613 * | 613 * |
614 * As a convenience attributes of the encapsulated model are exposed | 614 * As a convenience attributes of the encapsulated model are exposed |
615 * directly as attributes. | 615 * directly as attributes. |
616 */ | 616 * |
| 617 * @class BoundingBox |
| 618 * @param {Module} module Service module. |
| 619 * @param {Model} model Service model. |
| 620 **/ |
| 621 |
| 622 // Internal base object |
617 var _box = {}; | 623 var _box = {}; |
| 624 |
| 625 // Internal descriptor generator. |
618 function positionProp(name) { | 626 function positionProp(name) { |
619 return { | 627 return { |
620 get: function() {return this['_' + name];}, | 628 get: function() {return this['_' + name];}, |
621 set: function(value) { | 629 set: function(value) { |
622 this['p' + name] = this['_' + name]; | 630 this['p' + name] = this['_' + name]; |
623 this['_' + name] = value; | 631 this['_' + name] = value; |
624 } | 632 } |
625 }; | 633 }; |
626 } | 634 } |
627 | 635 |
| 636 // Box Properties (and methods). |
628 Object.defineProperties(_box, { | 637 Object.defineProperties(_box, { |
629 x: positionProp('x'), | 638 x: positionProp('x'), |
630 y: positionProp('y'), | 639 y: positionProp('y'), |
631 w: positionProp('w'), | 640 w: positionProp('w'), |
632 h: positionProp('h'), | 641 h: positionProp('h'), |
633 | 642 |
634 pos: { | 643 pos: { |
635 get: function() { return {x: this.x, y: this.y, w: this.w, h: this.h};}, | 644 get: function() { return {x: this.x, y: this.y, w: this.w, h: this.h};}, |
636 set: function(value) { | 645 set: function(value) { |
637 Y.mix(this, value, true, ['x', 'y', 'w', 'h']); | 646 Y.mix(this, value, true, ['x', 'y', 'w', 'h']); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 return result; | 843 return result; |
835 } | 844 } |
836 } | 845 } |
837 }); | 846 }); |
838 | 847 |
839 /** | 848 /** |
840 * @method BoundingBox | 849 * @method BoundingBox |
841 * @param {Module} module Typically service module. | 850 * @param {Module} module Typically service module. |
842 * @param {Model} model Model object. | 851 * @param {Model} model Model object. |
843 * @return {BoundingBox} A Box model. | 852 * @return {BoundingBox} A Box model. |
844 */ | 853 **/ |
845 function BoundingBox(module, model) { | 854 function BoundingBox(module, model) { |
846 var b = Object.create(_box); | 855 var b = Object.create(_box); |
847 b.module = module; | 856 b.module = module; |
848 b.model = model; | 857 b.model = model; |
849 | 858 |
850 return b; | 859 return b; |
851 } | 860 } |
852 | 861 |
853 views.BoundingBox = BoundingBox; | 862 views.BoundingBox = BoundingBox; |
854 | 863 |
855 /** | 864 /** |
856 * Covert an Array of services into BoundingBoxes. If | 865 * Covert an Array of services into BoundingBoxes. If |
857 * existing is supplied it should be a map of {id: box} | 866 * existing is supplied it should be a map of {id: box} |
858 * and will be updated in place by merging changed attribute | 867 * and will be updated in place by merging changed attribute |
859 * into the index. | 868 * into the index. |
860 * | 869 * |
| 870 * @method toBoundingBoxes |
861 * @param {ServiceModule} Module holding box canvas and context. | 871 * @param {ServiceModule} Module holding box canvas and context. |
862 * @param {ModelList} services Service modellist. | 872 * @param {ModelList} services Service modellist. |
863 * @param {Object} existing id:box mapping. | 873 * @param {Object} existing id:box mapping. |
864 * @return {Object} id:box mapping. | 874 * @return {Object} id:box mapping. |
865 **/ | 875 **/ |
866 views.toBoundingBoxes = function(module, services, existing) { | 876 views.toBoundingBoxes = function(module, services, existing) { |
867 var result = existing || {}; | 877 var result = existing || {}; |
868 Y.each(services, function() { | 878 Y.each(services, function() { |
869 var id = this.get('id'); | 879 var id = this.get('id'); |
870 if (result[id] !== undefined) { | 880 if (result[id] !== undefined) { |
871 result[id].model = this; | 881 result[id].model = this; |
872 } else { | 882 } else { |
873 result[id] = new BoundingBox(module, this); | 883 result[id] = new BoundingBox(module, this); |
874 } | 884 } |
875 }); | 885 }); |
876 return result; | 886 return result; |
877 }; | 887 }; |
878 | 888 |
879 | 889 |
880 | |
881 /** | 890 /** |
882 * Decorate a relation with some related/derived data. | 891 * Decorate a relation with some related/derived data. |
883 * | 892 * |
884 * @method DecoratedRelation | 893 * @method DecoratedRelation |
885 * @param {Object} relation The model object we will be based on. | 894 * @param {Object} relation The model object we will be based on. |
886 * @param {Object} source The service from which the relation originates. | 895 * @param {Object} source The service from which the relation originates. |
887 * @param {Object} target The service at which the relation terminates. | 896 * @param {Object} target The service at which the relation terminates. |
888 * @return {Object} An object with attributes matching the result of | 897 * @return {Object} An object with attributes matching the result of |
889 * relation.getAttrs() plus "source", "target", and other convenience data. | 898 * relation.getAttrs() plus "source", "target", |
| 899 * and other convenience data. |
890 */ | 900 */ |
891 views.DecoratedRelation = function(relation, source, target) { | 901 views.DecoratedRelation = function(relation, source, target) { |
892 var hasRelations = Y.Lang.isValue(relation.endpoints); | 902 var hasRelations = Y.Lang.isValue(relation.endpoints); |
893 var decorated = { | 903 var decorated = { |
894 source: source, | 904 source: source, |
895 target: target, | 905 target: target, |
896 compositeId: ( | 906 compositeId: ( |
897 source.modelId + | 907 source.modelId + |
898 (hasRelations ? ':' + relation.endpoints[0][1].name : '') + | 908 (hasRelations ? ':' + relation.endpoints[0][1].name : '') + |
899 '-' + target.modelId + | 909 '-' + target.modelId + |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 }, '0.1.0', { | 1095 }, '0.1.0', { |
1086 requires: ['base-build', | 1096 requires: ['base-build', |
1087 'handlebars', | 1097 'handlebars', |
1088 'node', | 1098 'node', |
1089 'view', | 1099 'view', |
1090 'panel', | 1100 'panel', |
1091 'json-stringify', | 1101 'json-stringify', |
1092 'gallery-markdown', | 1102 'gallery-markdown', |
1093 'datatype-date-format'] | 1103 'datatype-date-format'] |
1094 }); | 1104 }); |
OLD | NEW |