all files / montage/core/ document-part.js

48% Statements 12/25
20% Branches 2/10
50% Functions 3/6
48% Lines 12/25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                           37× 37× 37× 37× 37×           36× 36×               36× 36×                                                                                                      
var Montage = require("./core").Montage,
    logger = require("./logger").logger("document-part"),
    Promise = require("./promise").Promise,
    defaultEventManager = require("./event/event-manager").defaultEventManager;
 
var DocumentPart = Montage.specialize({
    parentDocumentPart: {value: null},
    template: {value: null},
    fragment: {value: null},
    objects: {value: null},
    childComponents: {value: null},
    parameters: {value: null},
 
    initWithTemplateAndFragment: {
        value: function (template, fragment) {
            this.template = template;
            this.fragment = fragment;
            this.objects = null;
            this.childComponents = [];
            this.parameters = null;
        }
    },
 
    startActingAsTopComponent: {
        value: function () {
            Eif (this.fragment) {
                defaultEventManager.registerEventHandlerForElement(
                    this, this.fragment);
            }
        }
    },
 
    stopActingAsTopComponent: {
        value: function () {
            Eif (this.fragment) {
                defaultEventManager.unregisterEventHandlerForElement(
                    this.fragment);
            }
        }
    },
 
    addChildComponent: {
        value: function (childComponent) {
            if (this.childComponents.indexOf(childComponent) == -1) {
                this.childComponents.push(childComponent);
            }
        }
    },
 
    removeChildComponent: {
        value: function (childComponent) {
            var childComponents = this.childComponents,
                ix = childComponents.indexOf(childComponent);
 
            if (ix > -1) {
                childComponents.splice(ix, 1);
                childComponent._parentComponent = null;
                childComponent._alternateParentComponent = null;
            }
        }
    },
 
    _addToDrawList: {
        value: Function.noop
    },
 
    _componentTreeLoadedDeferred: {value: null},
    loadComponentTree: {
        value: function() {
            if (!this._componentTreeLoadedDeferred) {
                var promises = [],
                    childComponents = this.childComponents;
 
                for (var i = 0, length = childComponents.length; i < length; i++) {
                    promises.push(childComponents[i].loadComponentTree());
                }
 
                this._componentTreeLoadedDeferred = Promise.all(promises);
            }
 
            return this._componentTreeLoadedDeferred;
        }
    }
});
 
exports.DocumentPart = DocumentPart;