forked from feediron/ttrss_plugin-feediron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrefTab.php
117 lines (104 loc) · 5.9 KB
/
PrefTab.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
<?php
class Feediron_PrefTab{
public static function get_pref_tab($json_conf, $test_conf){
$tab = '';
$rm = new RecipeManager();
$rm->loadAvailableRecipes();
$tab .= '<div data-dojo-type="dijit/layout/TabContainer" style="width: 100%; height:100%">';
/* Config tab */
$tab .= '<div data-dojo-type="dijit/layout/ContentPane" title="Configuration" data-dojo-props="selected:true" id="config">';
$tab .= '<h3>Configuration</h3>';
$tab .= '<a href="https://github.com/m42e/ttrss_plugin-feediron/blob/master/README.md">Configuration help</a>';
$tab .= self::get_form_start('save');
$tab .= self::get_script(' notify_info(transport.responseJSON.message); dojo.query("#json_conf").attr("value",transport.responseJSON.json_conf); dojo.query("#json_error").attr("innerHTML", "").attr("class",""); ','dojo.query("#json_error").attr("innerHTML", transport.responseJSON.json_error).attr("class","error");');
$tab .= '<textarea dojoType="dijit.form.SimpleTextarea" id="json_conf" name="json_conf" style="font-size: 12px; width: 99%; height: 400px;">'.$json_conf.'</textarea>';
$tab .= '<p /><button dojoType="dijit.form.Button" type="submit">'.__("Save").'</button>';
$tab .= '</form>';
$tab .= '<h3>Add predefined rules</h3>';
$tab .= self::get_form_start('add');
$tab .= self::get_script('notify_info(transport.responseJSON.message); dojo.query("#json_conf").attr("value",transport.responseJSON.json_conf); ');
$tab .= '<label for="addrecipe">'.__("Add recipe").': </label>';
$tab .= '<select dojoType="dijit.form.Select" name="addrecipe">';
foreach($rm->getRecipes() as $key => $recipe){
$tab .= '<option value="'.$recipe.'">'.$key.'</option>';
}
$tab .= '</select> ';
$tab .= '<button dojoType="dijit.form.Button" type="submit">'.__("Add").'</button>';
$tab .= '</form><p /><div id="json_error"></div><br />';
$tab .= __("Save after adding config!").'<br />';
$tab .= '<h3>Export rules</h3>';
$tab .= self::get_form_start('export');
$tab .= self::get_script('notify_info(transport.responseJSON.message); console.log(transport); dojo.query("#json_export").attr("innerHTML",transport.responseJSON.json_export);
dojo.query("#json_export_wrapper").attr("class","notice"); ');
$tab .= '<label for="recipe">'.__("Export").': </label>';
$tab .= '<select dojoType="dijit.form.Select" name="recipe">';
foreach(json_decode($json_conf,true) as $key => $config){
if($key != 'debug'){
$tab .= '<option value="'.$key.'">'.(isset($config['name'])?$config['name']:$key).'</option>';
}
}
$tab .= '</select> ';
$tab .= '<button dojoType="dijit.form.Button" type="submit">'.__("Export").'</button>';
$tab .= '</form><p />';
$tab .= '<div id="json_export_wrapper"><pre id="json_export"></pre></div>';
$tab .= '</div>';
/* Testing tab */
$tab .= '<div data-dojo-type="dijit/layout/ContentPane" title="Testing" data-dojo-props="selected:true" id="testing">';
$tab .= self::get_form_start('test');
$tab .= self::get_script('notify_info("Updated"); dojo.query("#test_url").attr("innerHTML", "<pre>"+transport.responseJSON.url+"</pre>"); dojo.query("#test_result").attr("innerHTML", transport.responseJSON.content); dojo.query("#test_log").attr("innerHTML", transport.responseJSON.log.join("\n")); dojo.query("#test_conf").attr("value", transport.responseJSON.config);');
$tab .= __("Save before you test!").'<br />';
$tab .= '<table width="100%">';
$tab .= '<tr><td>';
$tab .= 'URL:';
$tab .= '</td></tr>';
$tab .= '<tr><td>';
$tab .= '<input dojoType="dijit.form.TextBox" name="test_url" style="font-size: 12px; width: 99%;" />';
$tab .= '</td></tr>';
$tab .= '<tr><td>';
$tab .= 'Config (optional, will override default configuration):<button dojoType="dijit.form.Button" type="button">'.__("Restore last config").'<script type="dojo/on" event="click" args="evt">
evt.preventDefault();
dojo.query("#test_conf").attr("value", '.json_encode($test_conf).');
</script>
</button>';
$tab .= '</td></tr>';
$tab .= '<tr><td><textarea dojoType="dijit.form.SimpleTextarea" id="test_conf" name="test_conf" style="font-size: 12px; width: 99%; height: 150px;"></textarea>';
$tab .= '</td></tr>';
$tab .= '</table>';
$tab .= '<p><button dojoType="dijit.form.Button" type="submit">'.__("Test").'</button> <input id="verbose" dojoType="dijit.form.CheckBox" name="verbose" /><label for="verbose">'.__("Show every step").'</label> </p>';
$tab .= '</form>';
$tab .= '<div data-dojo-type="dijit/layout/TabContainer" style="width: 100%; height: 75%">';
$tab .= '<div data-dojo-type="dijit/layout/ContentPane" title="log" data-dojo-props="selected:true" id="test_log"></div>';
$tab .= '<div data-dojo-type="dijit/layout/ContentPane" title="result" data-dojo-props="selected:true" id="test_result"></div>';
$tab .= '<div data-dojo-type="dijit/layout/ContentPane" title="url" data-dojo-props="selected:true" id="test_url"></div>';
$tab .= '</div>';
$tab .= '</div>';
$tab .= '</div>';
return $tab;
}
private static function get_script($successaction,$failaction=''){
$script = '<script type="dojo/method" event="onSubmit" args="evt">
evt.preventDefault();
dojo.query("#test_result").attr("innerHTML", "");
new Ajax.Request("backend.php", {
parameters: dojo.objectToQuery(this.getValues()),
onComplete: function(transport) {
if (transport.responseJSON.success == false){
notify_error(transport.responseJSON.errormessage);
'.$failaction.'
}else{
'.$successaction.'
}
}
}
);
</script>';
return $script;
}
private static function get_form_start($method){
$form = '<form dojoType="dijit.form.Form">';
$form .='<input dojoType="dijit.form.TextBox" style="display : none" name="op" value="pluginhandler">';
$form .= '<input dojoType="dijit.form.TextBox" style="display : none" name="method" value="'.$method.'">';
$form .= '<input dojoType="dijit.form.TextBox" style="display : none" name="plugin" value="feediron">';
return $form;
}
}