aboutsummaryrefslogtreecommitdiff
path: root/js/components/ui/modalDialog/modal-dialog-manager.js
blob: c06b35d6ad20c566f72c90382be2e7a08d72876b (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
</copyright> */

var Popup =	require("js/components/popup.reel").Popup;
var popupManagerModule = require("js/components/popup-manager.reel");
var modalDialogHeader = require("js/components/ui/modalDialog/modalDialogHeader");

exports.ModalDialogMananger = (require("montage/core/core").Montage).create(require("montage/ui/component").Component, {

    _container: {
    	enumerable: false,
    	value: null
    },

    _blockScreen: {
    	enumerable: false,
    	value: null
    },

    /**
     * Assign a container to be the block screen
     *
     * @param {Element} container
     */
    init: {
    	enumerable: true,
    	value: function (blockScreen, container) {
    		container.style.position = 'absolute';
    		container.style.top = 0;
    		container.style.left = 0;
    		container.style.width = '100%';
    		container.style.height = '100%';
            container.style.display = "none";
            this._container = container;

            blockScreen.style.position = 'absolute';
    		blockScreen.style.top = 0;
    		blockScreen.style.left = 0;
    		blockScreen.style.width = '100%';
    		blockScreen.style.height = '100%';
            blockScreen.style.backgroundColor = "#8c8c8c";
            blockScreen.style.opacity = "0.8";
            blockScreen.style.display = "none";
            this._blockScreen = blockScreen;
    	}
    },

    /**
     * Show a modal dialog at the center of the browser
     */
    showModalDialog:{
        writable:false,
        enumerable:true,
        value: function(title, popupBackgroundColor, contentDiv){
            //place block screen on top of everything
            this._blockScreen.style.zIndex = popupManagerModule.PopupMananger._getNextHighestZindex(document.body);
            this._blockScreen.style.display = "block";
            this._container.style.zIndex = parseInt(this._blockScreen.style.zIndex) +1;


            var modalContent = document.createElement("div");

            //hack (elements needs to be on DOM to be drawn)
            //add modal dialog header
            var headerEl = document.createElement('div');
            var header = modalDialogHeader.ModalDialogHeader.create();
            header.element = headerEl;
            if((typeof title === "undefined") || (title === null)){
                header.showTitle = false;
            }else{
                header.title = title;
            }
            this._container.appendChild(headerEl);
            header.needsDraw = true;

            //add dialog content
            
            modalContent.appendChild(contentDiv);

//            var that = this;
//            setTimeout(function(){that.closeModalDialog()}, 5000);//test

            var popupEl = document.createElement('div');
    		var pop = Popup.create();
    		//Setting container and content
    		pop.element = popupEl;
    		pop.content = modalContent;
    		pop.position = {x:"30%", y:"15%"};//pass in real calculated center position
            pop.zIndex = popupManagerModule.PopupMananger._getNextHighestZindex(this._container);
            this._container.appendChild(popupEl);
            popupEl.style.opacity = 1;
            pop.needsDraw = true;

            //overrride modal dialog background color
            if((typeof popupBackgroundColor !== "undefined") || (popupBackgroundColor !== null)){
                pop.element.style.backgroundColor = popupBackgroundColor;
            }
            //hack - place the rendered header in the right place now
            this._container.removeChild(headerEl);
            modalContent.insertBefore(headerEl, modalContent.firstChild);


            this._container.style.display = "block";

        }
    },

    closeModalDialog:{
        writable:false,
        enumerable:true,
        value: function(){
            //remove dialog
            while(this._container.hasChildNodes()){
                this._container.removeChild(this._container.lastChild);
            }
            this._container.style.display = "none";
            this._blockScreen.style.display ="none";
        }
    }
});