-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
plugin_editor.js
154 lines (131 loc) · 5.64 KB
/
plugin_editor.js
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
$(document).ready(function() {
$('span.add-plugin').click(function(){
var select = $(this).parent().children("select");
var pluginvalue = select.attr('value');
var placeholder = $(this).parent().parent().parent().children("label").attr("for").split("id_")[1];
var splits = window.location.href.split("/");
var page_id = splits[splits.length-2];
var language = $('input.language_button.selected').attr('name');
if (!language) {
language = $('input[name=language]').attr("value");
}
if (!language) {
alert("Unable to determine the correct language for this plugin! Please report the bug!");
}
var target_div = $(this).parent().parent().parent().children('div.plugin-editor');
if (pluginvalue) {
var pluginname = select.children('[selected]').text();
var ul_list = $(this).parent().parent().children("ul.plugin-list");
$.ajax({
url: "add-plugin/", dataType: "html", type: "POST",
data: { page_id:page_id, placeholder:placeholder, plugin_type:pluginvalue, language:language },
success: function(data) {
loadPluginForm(target_div, data);
ul_list.append('<li id="plugin_' + data + '" class="' + pluginvalue + ' active"><span class="drag"></span><span class="text">' + pluginname + '</span><span class="delete"></span></li>');
setclickfunctions();
},
error: function(xhr) {
if (xhr.status < 500) {
alert(xhr.responseText);
}
}
});
}
});
$('span.copy-plugins').click(function(){
var copy_from_language = $(this).parent().children("select[name=copy-plugins]").attr("value");
var placeholder = $(this).parent().parent().parent().children("label").attr("for").split("id_")[1];
var splits = window.location.href.split("/");
var page_id = splits[splits.length-2];
var to_language = $('input.language_button.selected').attr('name');
if (!to_language) {
to_language = $('input[name=language]').attr("value");
}
if (!to_language) {
alert("Unable to determine the correct language for this plugin! Please report the bug!");
}
var target_div = $(this).parent().parent().parent().children('div.plugin-editor');
if ((copy_from_language) && (copy_from_language != "")) {
$.ajax({
url: "copy-plugins/", dataType: "html", type: "POST",
data: { page_id: page_id, placeholder: placeholder, copy_from: copy_from_language, language: to_language },
success: function(data) {
// loadPluginForm(target_div, data);
// ul_list.append('<li id="plugin_' + data + '" class="' + pluginvalue + ' active"><span class="drag"></span><span class="text">' + pluginname + '</span><span class="delete"></span></li>');
// setclickfunctions();
},
error: function(xhr) {
if (xhr.status < 500) {
alert(xhr.responseText);
}
}
});
}
});
$('ul.plugin-list').sortable({
handle:'span.drag',
//appendTo:'body',
axis:'y',
opacity:0.9,
zIndex:2000,
update:function(event, ui){
var array = $(this).sortable('toArray');
var d = "";
for(var i=0;i<array.length;i++){
d += array[i].split("plugin_")[1];
if (i!=array.length-1){
d += "_";
}
}
$.post("move-plugin/", { ids:d }, function(data){}, "json");
}
});
setclickfunctions();
});
function plugin_select_click_handler(){
var target = $(this).parent().parent().parent().parent().children("div.plugin-editor");
var id = $(this).parent().attr("id").split("plugin_")[1];
loadPluginForm(target, id);
return false;
}
function plugin_delete_click_handler(){
var plugin_id = $(this).parent().attr("id").split("plugin_")[1];
var question = gettext("Are you sure you want to delete this plugin?")
var answer = confirm(question, true);
if(answer){
$.post("remove-plugin/", { plugin_id:plugin_id }, function(data){
var splits = data.split(",")
id = splits.shift()
$("#plugin_"+id).remove();
$("#iframe_"+id).parent().html("<p>" + splits.join(",") + "</p>")
}, "html");
}
}
function setclickfunctions(){
$('ul.plugin-list .text').unbind('click', plugin_select_click_handler);
$('ul.plugin-list span.delete').unbind('click', plugin_delete_click_handler);
$('ul.plugin-list .text').click(plugin_select_click_handler);
$('ul.plugin-list span.delete').click(plugin_delete_click_handler);
}
function load_plugin(li){
var target = li.parent().parent().parent().children("div.plugin-editor");
var id = li.attr("id").split("plugin_")[1];
loadPluginForm(target, id);
}
function setiframeheight(height, id){
$('#iframe_'+id).height(height+"px");
}
function hide_iframe(id, type, title, msg){
html = "<b>"+type+"</b>"
if( title != "" && title != null){
html += " [ "+title+ " ]"
}
$('#plugin_'+id+" span.text").html(html);
$('#iframe_'+id).parent().html("<p>"+msg+"</p>");
}
function loadPluginForm(target, id){
var object = '<iframe id="iframe_'+id+'" src="edit-plugin/'+id+'/" frameborder="0"></iframe>';
target.html(object);
$('ul.plugin-list .active').removeClass("active");
$('#plugin_'+id).addClass("active");
};