Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5190 dpurdie 1
//  Vix specific Javascript for jquery use
2
//
3
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4
//  Generate a confirmation dialog
5
//  Args:   text - Body of the message
6
//          parms - A simple object of options - see defaults
7
//  Note: will return BEFORE the user makes a selection
8
//        Can call a function and/or a URL if confirmed
9
//        Can 'show' a progress element
10
//        See 'defaults' below for bits that can be modified
11
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12
function vixConfirm(text, parms){
13
     var defaults = {
14
        resizable: true,
15
        height: 'auto',
16
        width : 'auto',
17
        modal: true,
18
        position: { my: "top", at: "top+100", of: window },
19
        title: "Confirm",
20
        icon: "images/i_warning.gif",
21
        url : null,
22
        ok : null,
23
        post : null,
24
        button : "Confirm",
25
        progress : "#ProgressBar",
26
     };
27
     $.extend( defaults, parms);
28
 
29
     defaults.open = function() {
30
        $(this).siblings('.ui-dialog-buttonpane').find('button:eq(1)').focus(); 
31
        var markup = '<img src="'+defaults.icon+'" style="float:left; margin:0 7px 20px 0;">' + text;
32
        $(this).html(markup);
33
     };
34
 
35
    defaults.close = function() {
36
        $(this).remove();
37
    };
38
 
39
    defaults.buttons = [
40
        {
41
        text : defaults.button,
42
        click : function (){
43
                if (defaults.ok != null ){
44
                    defaults.ok(defaults);
45
                }
46
                if ( defaults.progress != null) {
47
                    $(defaults.progress).show().css("visibility", "visible");    
48
                }
49
                if (defaults.url != null ) {
50
                    window.location.href = defaults.url;
51
                }
52
                if (defaults.post != null ) {
53
                    $('form[name="'+defaults.post+'"]').submit();    
54
                }
55
                $(this).dialog("close");
56
            }
57
        },
58
        {
59
        text : 'Cancel',
60
        click : function (){
61
            $(this).dialog("close");
62
            }
63
        }];
64
 
65
     var dd = $( "<div>Confirm</div>" ).dialog(defaults);
66
     // Once the dialog has been instantiated the autosize dimensions are known
67
     // and the dislog can be correctly positioned
68
     dd.dialog("widget").position(defaults.position);
69
 
70
     // Return false incase this is used as an onClick
71
     return false;
72
}
73
 
74
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75
// Compatability function
76
//      Confirm Deletion of an item
77
//      Assumes that the item is within an 'anchor' and that an href can be located
78
//      Uses VixConfirm to do the heavy lifting
79
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
80
function vixConfirmDelete (txt)
81
{
82
    var href = window.event.currentTarget.href;
83
    vixConfirm('Are you sure you want to delete '+ txt +'?', {url : href})
84
    return false;
85
}
86
 
87
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88
//  Similar to 'alert', but uses the jquery dialog mechnaism
89
//  Note: will return BEFORE the user makes a selection
90
//  Returns a Defereed object that will be rejected when the dialog is closed.
91
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
92
function vixAlert(text){
93
     var dbo = $.Deferred();
5207 dpurdie 94
     var dd = $( "<div>Alert</div>" ).dialog({
5190 dpurdie 95
        resizable: true,
96
        height: 'auto',
97
        width : 'auto',
98
        modal: true,
99
        title:'Alert',
5227 dpurdie 100
        position: { my: "top", at: "top+100", of: window },
5190 dpurdie 101
        open: function() {
102
            $(this).html('<img src="images/i_critical.gif" style="float:left; margin:0 7px 20px 0;">' + text);
103
        },
104
        close : function() {
105
            $(this).remove();
106
            dbo.reject();
107
        },
108
        buttons: {
109
            "Ok": function() {
110
                $(this).dialog("close");
111
            }
112
        }
113
     });
5207 dpurdie 114
     // Once the dialog has been instantiated the autosize dimensions are known
115
     // and the dislog can be correctly positioned
5227 dpurdie 116
     // Note: Appears that we need to position it twice
117
     //       Once in the dialog creation, and once here
5207 dpurdie 118
     dd.dialog("widget").position({ my: "top", at: "top+100", of: window });
119
 
120
     return dbo;
5190 dpurdie 121
}
122
 
123