This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 247
/
schema.php
110 lines (94 loc) · 4.81 KB
/
schema.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
<?php
$selected = "tables";
if (in_array($this->_action, array("tables", "views"))) {
$selected = $this->_action;
}
?>
<h2><?php echo __('Database schema'); ?></h2>
<div class="log"></div>
<?php if (isset($this->schema) && count($this->schema)) { ?>
<form method="post" action="" class="nomargin" id="schema">
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th style="width: 13px;"><input type="checkbox" style="margin-top: 0;" /></th>
<th><?php echo __('Schema object'); ?></th>
<th style="text-align: center; width: 50px;"><?php echo __('In DB'); ?></th>
<th style="text-align: center; width: 50px;"><?php echo __('On disk'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($this->schema as $name => $flags) { ?>
<tr>
<td class="center">
<input type="checkbox" name="schema[]" value="<?php echo $name; ?>" id="object-<?php echo $name; ?>" style="margin-top: 0;" />
</td>
<td class="object-label">
<label for="object-<?php echo $name; ?>">
<?php echo $name; ?>
</label>
</td>
<td style="text-align: center;" data-role="database">
<?php if (isset($flags['database'])) { ?>
<span class="label label-success"><?php echo __('YES'); ?></span>
<?php } else { ?>
<span class="label label-important"><?php echo __('NO'); ?></span>
<?php } ?>
</td>
<td style="text-align: center;" data-role="disk">
<?php if (isset($flags['disk'])) { ?>
<span class="label label-success"><?php echo __('YES'); ?></span>
<?php } else { ?>
<span class="label label-important"><?php echo __('NO'); ?></span>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<button data-role="create" class="btn btn-primary btn-mini"><?php echo __('Push to database'); ?></button>
<button data-role="export" class="btn btn-primary btn-mini"><?php echo __('Export to disk'); ?></button>
</form>
<script type="text/javascript">
$('schema').select('button[data-role]').invoke('observe', 'click', function (event) {
event.stop();
var form = this.up('form');
var data = form.serialize(true);
form.disable();
clear_messages('left');
data.action = this.getAttribute('data-role');
new Ajax.Request('index.php?a=schema', {
parameters: data,
onSuccess: function (transport) {
form.enable();
var response = transport.responseText.evalJSON();
if (typeof response.error != 'undefined') {
return APP.growler.error('<?php echo __('Error!'); ?>', response.error);
}
if (response.messages.error) {
render_messages('error', 'left', response.messages.error, '<?php echo __('The following errors occured:'); ?>');
}
if (response.messages.success) {
render_messages('success', 'left', response.messages.success, '<?php echo __('The following actions completed successfuly:'); ?>');
}
var items = response.items;
for (var name in items) {
var row = $('object-' + name).up('tr');
for (var key in items[name]) {
var label = row.down('[data-role="' + key + '"]').down('.label');
label.removeClassName('label-success').removeClassName('label-important');
if (items[name][key]) {
label.addClassName('label-success').update('YES');
} else {
label.addClassName('label-important').update('NO');
}
}
}
Effect.ScrollTo('log', {duration: 0.2});
}
});
});
</script>
<?php } else { ?>
<div class="alert alert-info nomargin"><?php echo __('No schema objects found on disk or in the database.'); ?></div>
<?php } ?>