/
dashboard_config.php
155 lines (132 loc) · 8.27 KB
/
dashboard_config.php
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/*
All Emoncms code is released under the GNU Affero General Public License.
See COPYRIGHT.txt and LICENSE.txt.
---------------------------------------------------------------------
Emoncms - open source energy visualisation
Part of the OpenEnergyMonitor project:
http://openenergymonitor.org
*/
global $path;
defined('EMONCMS_EXEC') or die('Restricted access');
?>
<div id="dashConfigModal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="dashConfigModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="dashConfigModalLabel"><?php echo dgettext('dashboard_messages','Dashboard Configuration'); ?></h3>
</div>
<div class="modal-body">
<label><?php echo dgettext('dashboard_messages','Dashboard name: '); ?></label>
<input type="text" name="name" value="<?php echo $dashboard['name']; ?>" />
<label><?php echo dgettext('dashboard_messages','Alias name: '); ?></label>
<input type="text" name="alias" value="<?php echo $dashboard['alias']; ?>" />
<label><?php echo dgettext('dashboard_messages','Background color: '); ?></label>
<input type="color" name="backgroundcolor" value="#<?php echo $dashboard['backgroundcolor']; ?>" />
<label><?php echo dgettext('dashboard_messages','Description: '); ?></label>
<textarea name="description"><?php echo $dashboard['description']; ?></textarea>
<label><?php echo dgettext('dashboard_messages','Grid size: '); ?></label>
<input type="text" name="gridsize" value="<?php echo $dashboard['gridsize']; ?>" />
<label><?php echo dgettext('dashboard_messages','Feed selection mode: '); ?></label>
<i style="font-size:12px"><?php echo dgettext('dashboard_messages','Note: Reset feeds in all widgets in dashboard if changing'); ?><br><?php echo dgettext('dashboard_messages','this part way through a dashboard build'); ?></i><br>
<select name="feedmode">
<option value="tagname" <?php if ($dashboard['feedmode'] == "tagname") echo 'selected'; ?>><?php echo dgettext('dashboard_messages','By tag:name'); ?></option>
<option value="feedid" <?php if ($dashboard['feedmode'] == "feedid") echo 'selected'; ?>><?php echo dgettext('dashboard_messages','By feedid'); ?></option>
</select>
<label class="checkbox">
<input type="checkbox" name="main" id="chk_main" value="1" <?php if ($dashboard['main'] == true) echo 'checked'; ?> />
<abbr title="<?php echo dgettext('dashboard_messages','Make this dashboard the first shown'); ?>"><?php echo dgettext('dashboard_messages','Main'); ?></abbr>
</label>
<label class="checkbox">
<input type="checkbox" name="published" id="chk_published" value="1" <?php if ($dashboard['published'] == true) echo 'checked'; ?> />
<abbr title="<?php echo dgettext('dashboard_messages','Activate this dashboard'); ?>"><?php echo dgettext('dashboard_messages','Published'); ?></abbr>
</label>
<label class="checkbox">
<input type="checkbox" name="public" id="chk_public" value="1" <?php if ($dashboard['public'] == true) echo 'checked'; ?> />
<abbr title="<?php echo dgettext('dashboard_messages','Anyone with the URL can see this dashboard'); ?>"><?php echo dgettext('dashboard_messages','Public'); ?></abbr>
</label>
<label class="checkbox">
<input type="checkbox" name="showdescription" id="chk_showdescription" value="1" <?php if ($dashboard['showdescription'] == true) echo 'checked'; ?> />
<abbr title="<?php echo dgettext('dashboard_messages','Shows dashboard description on mouse over dashboard name in menu project'); ?>"><?php echo dgettext('dashboard_messages','Show description'); ?></abbr>
</label>
<label class="checkbox">
<input type="checkbox" name="fullscreen" id="chk_fullscreen" value="1" <?php if ($dashboard['fullscreen'] == true) echo 'checked'; ?> />
<abbr title="<?php echo dgettext('dashboard_messages','Hide menus on dashboard. Make full screen.'); ?>"><?php echo dgettext('dashboard_messages','Hide Menus'); ?></abbr>
</label>
<label><?php echo dgettext('dashboard_messages','Content: '); ?></label>
<i style="font-size:12px"><?php echo dgettext('dashboard_messages','To view content changes reload editor after saving');?></i>
<textarea name="content" style="width:100%; height:200px;"><?php echo $dashboard['content']; ?></textarea>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo dgettext('dashboard_messages','Close'); ?></button>
<button id="configure-save" class="btn btn-primary"><?php echo dgettext('dashboard_messages','Save changes'); ?></button>
</div>
</div>
<script type="application/javascript">
var dashid = <?php echo $dashboard['id']; ?>;
var height = <?php echo $dashboard['height']; ?>;
$("#dashboard-config-button").click(function (){
$("textarea[name=content]").val($("#page").html());
$("textarea[name=content]").data('original', $("#page").html());// used to test for changes
});
$("#configure-save").click(function (){
var fields = {};
fields['name'] =$("input[name=name]").val();
fields['alias'] = $("input[name=alias]").val();
fields['description'] = $("textarea[name=description]").val();
fields['backgroundcolor'] = $("input[name=backgroundcolor]").val().replace('#','');
fields['feedmode'] = $("select[name=feedmode]").val();
var gridsize = parseInt($("input[name=gridsize]").val());
gridsize = Math.max(gridsize, 0);
fields['gridsize'] = gridsize;
if ($("#chk_main").is(":checked")) fields['main'] = true; else fields['main'] = false;
if ($("#chk_public").is(":checked")) fields['public'] = true; else fields['public'] = false;
if ($("#chk_published").is(":checked")) fields['published'] = true; else fields['published'] = false;
if ($("#chk_showdescription").is(":checked")) fields['showdescription'] = true; else fields['showdescription'] = false;
fields['fullscreen'] = $("#chk_fullscreen").is(":checked");
$.ajax({
type: "POST",
url : path+"dashboard/set.json",
data : "&id="+dashid+"&fields="+encodeURIComponent(JSON.stringify(fields)),
dataType : 'json',
async: true,
success : function(result) {
if (result.success!=undefined) {
if (result.alias===fields.alias) {
$('#dashConfigModal').modal('hide');
} else {
$("input[name=alias]").val(result.alias);
alert("Dashboard alias altered. Too long or not URL friendly." +
"\nYou sent: \n "+
fields.alias +
"\nAltered to : \n " +
result.alias);
}
}
}
});
var contentChanged = $("textarea[name=content]").val() != $("textarea[name=content]").data('original');
if (contentChanged) {
$.ajax({
type: "POST",
url : path+"dashboard/setcontent.json",
data : "&id="+dashid+'&content='+encodeURIComponent($("textarea[name=content]").val())+'&height='+height,
dataType: 'json',
async: true,
success : function(result) {
if (!result.success) {
alert(result.message);
} else {
$("#page").html($("textarea[name=content]").val());
redraw = 1;
reloadiframe = 0; // dont re-calculate vis iframe urls
$('#dashConfigModal').modal('hide');
}
}
});
}
$('#page-container').css("background-color","#"+fields['backgroundcolor']);
designer.feedmode = fields['feedmode'];
designer.grid_size = gridsize;
designer.draw();
});
</script>