Skip to content

Instantly share code, notes, and snippets.

@luniki
Created April 26, 2013 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luniki/5466967 to your computer and use it in GitHub Desktop.
Save luniki/5466967 to your computer and use it in GitHub Desktop.
// Generated by CoffeeScript 1.5.0
(function() {
var $, dialog, dialog_template, getCid, getWikiPages, intermap, openLinkDialog, url;
$ = jQuery;
dialog_template = _.template("<div title='Stud.IP-Link einf&uuml;gen'>\n <select>\n <% _.each(keywords, function(keyword) { %>\n <option><%= keyword %></option> <% }); %>\n </select>\n <button class=submit>Einf&uuml;gen</button>\n</div>");
url = function(cid) {
return STUDIP.ABSOLUTE_URI_STUDIP + ("plugins.php/restipplugin/api/courses/" + cid + "/wiki");
};
getCid = function() {
return document.location.search.match(/cid=([a-f0-9]{32})/)[1];
};
getWikiPages = function(cid) {
return $.getJSON(url(getCid()));
};
dialog = false;
openLinkDialog = function(selection, textarea, button) {
if (dialog) {
dialog.dialog("open");
} else {
$(button).showAjaxNotification();
getWikiPages().always(function() {
return $(button).hideAjaxNotification();
}).then(function(pages) {
dialog = $(dialog_template(pages)).dialog();
return dialog.on("click", "button.submit", function() {
var selected_page;
selected_page = dialog.find("select").val();
dialog.dialog("close");
return textarea.replaceSelection("{{wiki:" + selected_page + "}}");
});
});
}
return false;
};
intermap = {
label: "Stud.IP-Link",
evaluate: openLinkDialog
};
STUDIP.Toolbar.buttonSet.right = _.extend({
intermap: intermap
}, STUDIP.Toolbar.buttonSet.right);
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment