/
rdf-schema-new-prefix-widget.js
113 lines (97 loc) · 3.9 KB
/
rdf-schema-new-prefix-widget.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
function NewPrefixWidget(manager){
this._prefixesManager = manager;
}
NewPrefixWidget.prototype.show = function(msg,def_prefix,onDone){
var self = this;
var frame = DialogSystem.createDialog();
frame.width("350px");
var html = $(DOM.loadHTML("rdf-extension","scripts/new-prefix-widget.html"));
var header = $('<div></div>').addClass("dialog-header").text("New Prefix").appendTo(frame);
var body = $('<div class="grid-layout layout-full"></div>').addClass("dialog-body").append(html).appendTo(frame);
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
self._elmts = DOM.bind(html);
if(msg){
self._elmts.message.addClass('message').html(msg);
}
if(def_prefix){
self._elmts.prefix.val(def_prefix);
self.suggestUri(def_prefix);
}
var importVocabulary = function(fetchOption,onDone){
var name = self._elmts.prefix.val();
var uri = self._elmts.uri.val();
if(self._prefixesManager._hasPrefix(name)){
alert('Prefix "' + name + '" is already defined');
return;
}
var dismissBusy;
if(fetchOption==='file'){
//prepare values
$('#vocab-hidden-prefix').val(name);
$('#vocab-hidden-uri').val(uri);
$('#vocab-hidden-project').val(theProject.id);
dismissBusy = DialogSystem.showBusy('Uploading vocabulary ');
self._elmts.file_upload_form.ajaxSubmit({
dataType: 'json',
success: function(data) {
if (data.code === "error"){
alert('Error:' + data.message)
}else{
DialogSystem.dismissUntil(level - 1);
if(onDone){
onDone(name,uri);
}
}
dismissBusy();
}
});
return;
}
dismissBusy = DialogSystem.showBusy('Trying to import vocabulary from ' + uri);
$.post("../command/rdf-extension/add-prefix",{name:name,uri:uri,"fetch-url":uri,project: theProject.id,fetch:fetchOption},function(data){
if (data.code === "error"){
alert('Error:' + data.message)
}else{
DialogSystem.dismissUntil(level - 1);
if(onDone){
onDone(name,uri);
}
}
dismissBusy();
});
};
$('<button></button>').addClass('button').html(" OK ").click(function() {
var fetchOption = self._elmts.fetching_options_table.find('input[name="vocab_fetch_method"]:checked').val();
importVocabulary(fetchOption,onDone);
}).appendTo(footer);
$('<button></button>').addClass('button').text("Cancel").click(function() {
DialogSystem.dismissUntil(level - 1);
}).appendTo(footer);
$('<button></button>').attr('id','advanced_options_button').attr("disabled","").attr("style","float:right").text("Advanced...").click(function() {
self._elmts.fetching_options_table.show();
$('#advanced_options_button').attr("disabled", "disabled");
}).appendTo(footer);
var level = DialogSystem.showDialog(frame);
self._elmts.fetching_options_table
.hide()
.find('input[name="vocab_fetch_method"]').click(function(){
var upload = $(this).val()!=='file';
self._elmts.fetching_options_table.find('.upload_file_inputs').attr('disabled',upload);
});
self._elmts.prefix.bind('change',function(){
self.suggestUri($(this).val());
}).focus();
};
NewPrefixWidget.prototype.suggestUri = function(prefix){
var self = this;
$.get("../command/rdf-extension/get-prefix-cc-uri",{prefix:prefix},function(data){
if(!self._elmts.uri.val() && data.uri){
self._elmts.uri.val(data.uri);
if(self._elmts.message.text()){
self._elmts.message.find('div').remove().end().append($('<span>(a suggestion from <em><a target="_blank" href="http://prefix.cc">prefix.cc</a></em> is provided)</span>'));
}else{
self._elmts.uri_note.html('(suggested by <a target="_blank" href="http://prefix.cc">prefix.cc</a>)');
}
}
},"json");
};