~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to lib/helioviewer/ScreenshotBuilder.js

  • Committer: V. Keith Hughitt
  • Date: 2009-03-26 19:20:57 UTC
  • Revision ID: hughitt1@kore-20090326192057-u0x8rf8sf5lmmnwh
nightly build 03-26-2009: Using alpha-channel JPEG 2000 dataset

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * @author Jaclyn Beck
3
 
 * @fileoverview Contains the code for the Screenshot Builder class. Handles event listeners for the screenshot button and
4
 
 *                  screenshot creation.
5
 
 */
6
 
/*jslint browser: true, white: true, onevar: true, undef: true, nomen: false, eqeqeq: true, plusplus: true, 
7
 
bitwise: true, regexp: true, strict: true, newcap: true, immed: true, maxlen: 120, sub: true */
8
 
/*global document, $, Class, window */
9
 
"use strict";
10
 
var ScreenshotBuilder = Class.extend(
11
 
    /** @lends ScreenshotBuilder.prototype */
12
 
    {
13
 
 
14
 
    /**
15
 
     * @constructs
16
 
     * @description Loads default options, grabs mediaSettings, sets up event listener for the screenshot button
17
 
     * @param {Object} controller -- the helioviewer class 
18
 
     */    
19
 
    init: function (controller) {
20
 
        $.extend(this); //?
21
 
        this.button        = $("#screenshot-button");
22
 
        this.building     = false;
23
 
        this.viewport    = controller.viewport;
24
 
        this.controller = controller;
25
 
        
26
 
        this.mediaSettings = this.controller.mediaSettings;
27
 
        
28
 
        var self = this, visibleCoords;
29
 
        this.button.click(function () {
30
 
            if (self.building) {
31
 
                self.messageConsole.info("A link to your screenshot will be available shortly.");
32
 
            }
33
 
            else {
34
 
                visibleCoords = self.viewport.getHCViewportPixelCoords();
35
 
                self.takeScreenshot(visibleCoords);
36
 
            }
37
 
        });
38
 
    },
39
 
    
40
 
    /**
41
 
     * @description Gathers all necessary information to generate a screenshot, and then displays the
42
 
     *              image when it is ready.
43
 
     * @param {Object} visibleCoords -- array containing the heliocentric top, left, bottom, and right 
44
 
     *                 coordinates of the visible region 
45
 
     */
46
 
    takeScreenshot: function (visibleCoords) {
47
 
        var self, callback, params, imgWidth, imgHeight, url, mediaSettings, download, options, filename,        
48
 
        helioviewer = this.controller;
49
 
        
50
 
        // Refresh the settings in case something has changed.
51
 
        mediaSettings     = this.mediaSettings;
52
 
        mediaSettings.getSettings(visibleCoords);
53
 
 
54
 
        this.building = true;
55
 
 
56
 
        imgWidth  = mediaSettings.width; 
57
 
        imgHeight = mediaSettings.height; 
58
 
 
59
 
        self = this;
60
 
        
61
 
        params = {
62
 
            action        : "takeScreenshot",
63
 
            layers        : (mediaSettings.layerNames).join("/"),
64
 
            obsDate        : mediaSettings.startTime,
65
 
            zoomLevel    : mediaSettings.zoomLevel,
66
 
            edges        : mediaSettings.edgeEnhance,
67
 
            sharpen        : mediaSettings.sharpen,
68
 
            imageSize    : imgWidth + "," + imgHeight,
69
 
            filename    : mediaSettings.filename,
70
 
            quality        : mediaSettings.quality
71
 
        };
72
 
        
73
 
        callback = function (url) {
74
 
            self.building = false;
75
 
 
76
 
            // If the response is an error message instead of a url, show the message
77
 
            if (url === null) {
78
 
                //mediaSettings.shadowboxWarn(transport.responseText);
79
 
            }
80
 
            
81
 
            else {        
82
 
                // Options for the jGrowl notification. Clicking on the notification will 
83
 
                // let the user download the file.                        
84
 
                options = {
85
 
                    sticky: true,
86
 
                    header: "Your screenshot is ready!",
87
 
                    open:    function (e, m) {
88
 
                        download = $('#screenshot-' + filename);
89
 
                        
90
 
                        download.click(function () {
91
 
                            window.open('api/index.php?action=downloadFile&url=' + url, '_parent');
92
 
                        });
93
 
                    }
94
 
                };
95
 
 
96
 
                // Create the jGrowl notification.
97
 
                helioviewer.messageConsole.info("<div id='screenshot-" + filename +
98
 
                "' style='cursor: pointer'>Click here to download. </div>", options);
99
 
            }
100
 
        };
101
 
 
102
 
        $.post('api/index.php', params, callback, 'json');
103
 
    }
104
 
});
 
 
b'\\ No newline at end of file'