Skip to content
Permalink
Browse files

remoting search and create

  • Loading branch information...
michmech committed Apr 8, 2017
1 parent 26d1329 commit 46cdb6cb209b4bc49ad84c143deb6f5fc9aa4f88
Showing with 64 additions and 45 deletions.
  1. BIN add.png
  2. BIN magnifier.png
  3. +11 −1 xonomy.css
  4. +53 −44 xonomy.js
BIN +733 Bytes add.png
Binary file not shown.
BIN +615 Bytes magnifier.png
Binary file not shown.
@@ -164,6 +164,7 @@

/*When the pop-up box takes input from the user*/
#xonomyBubble.nerd #xonomyBubbleContent form { margin: -5px; padding: 5px; background-color: #eeeeee; }
#xonomyBubble.nerd #xonomyBubbleContent form.overmenu { margin-bottom: 5px; }
#xonomyBubble.nerd #xonomyBubbleContent form.undermenu { margin-top: 5px; }
#xonomyBubble.nerd #xonomyBubbleContent div.submitline { text-align: right; margin-top: 5px; }
#xonomyBubble.nerd #xonomyBubbleContent input { border-width: 1px; padding: 3px; color: #333333; font: inherit; }
@@ -174,6 +175,10 @@
/*When the pop-up is a list of warnings*/
#xonomyBubble.nerd #xonomyBubbleContent .warning { padding: 5px 10px; }

#xonomyBubble.nerd button.buttonSearch { background-image: url(magnifier.png); background-position: center center; background-repeat: no-repeat; padding: 2px 15px; border-width: 1px; border-radius: 2px; }
#xonomyBubble.nerd button.buttonCreate { background-image: url(add.png); background-position: center center; background-repeat: no-repeat; padding: 2px 15px; border-width: 1px; border-radius: 2px; }


/*LAIC MODE*/
.xonomy.laic { font-family: Verdana, sans-serif; font-size: 1rem; cursor: default; background-color: #ffffff;
-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
@@ -350,7 +355,8 @@

/*When the pop-up box takes input from the user*/
#xonomyBubble.laic #xonomyBubbleContent form { margin: -5px; padding: 5px; background-color: #eeeeee; }
#xonomyBubble.laic #xonomyBubbleContent form.undermenu { margin-top: 5px; }
#xonomyBubble.laic #xonomyBubbleContent form.overmenu { margin-bottom: 15px; }
#xonomyBubble.laic #xonomyBubbleContent form.undermenu { margin-top: 15px; }
#xonomyBubble.laic #xonomyBubbleContent div.submitline { text-align: right; margin-top: 5px; }
#xonomyBubble.laic #xonomyBubbleContent input { border-width: 1px; padding: 6px; color: #333333; font: inherit; font-size: 0.95rem; }
#xonomyBubble.laic #xonomyBubbleContent textarea { border-width: 1px; padding: 6px; color: #333333; font: inherit; font-size: 0.95rem; }
@@ -360,6 +366,10 @@
/*When the pop-up is a list of warnings*/
#xonomyBubble.laic #xonomyBubbleContent .warning { padding: 5px 10px; }

#xonomyBubble.laic button.buttonSearch { background-image: url(magnifier.png); background-position: center center; background-repeat: no-repeat; padding: 4px 15px; border-width: 1px; border-radius: 2px; }
#xonomyBubble.laic button.buttonCreate { background-image: url(add.png); background-position: center center; background-repeat: no-repeat; padding: 4px 15px; border-width: 1px; border-radius: 2px; }


#xonomyBubble .wyc { display: inline-block; background-image: url(loader.gif); background-position: center center; background-repeat: no-repeat; width: 100%; height: 30px; margin: 5px 0px 0px 0px; }
.xonomy .wyc { display: inline-block; background-image: url(loader.gif); background-position: center center; background-repeat: no-repeat; width: 30px; height: 10px; }
.xonomy .inlinecaption a { color: inherit; text-decoration: none; border-bottom: 1px dotted; padding: 3px 0px;}
@@ -8,8 +8,14 @@ Xonomy.setMode=function(mode) {
if(mode=="laic") $(".xonomy").removeClass("nerd").addClass("laic");
}

Xonomy.xmlEscape=function(str) {
return String(str)
Xonomy.jsEscape=function(str) {
return String(str)
.replace(/\"/g, '\\\"')
.replace(/\'/g, '\\\'')
};
Xonomy.xmlEscape=function(str, jsEscape) {
if(jsEscape) str=Xonomy.jsEscape(str);
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
@@ -889,60 +895,63 @@ Xonomy.askLongString=function(defaultString, askerParameter, jsMe) {
};
Xonomy.askPicklist=function(defaultString, picklist, jsMe) {
var html="";
html+="<div class='menu'>";
for(var i=0; i<picklist.length; i++) {
var item=picklist[i];
if(typeof(item)=="string") item={value: item, caption: ""};
html+="<div class='menuItem techno"+(item.value==defaultString?" current":"")+"' onclick='Xonomy.answer(\""+Xonomy.xmlEscape(item.value)+"\")'>";
html+="<span class='punc'>\"</span>";
if(item.displayValue) html+=Xonomy.textByLang(item.displayValue); else html+=Xonomy.xmlEscape(item.value);
html+="<span class='punc'>\"</span>";
if(item.caption!="") html+=" <span class='explainer'>"+Xonomy.xmlEscape(Xonomy.textByLang(item.caption))+"</span>";
html+="</div>";
}
html+="</div>";
html+=Xonomy.pickerMenu(picklist, defaultString);
return html;
};
Xonomy.askOpenPicklist=function(defaultString, picklist) {
var isInPicklist=false;
var html="";
html+="<div class='menu'>";
for(var i=0; i<picklist.length; i++) {
html+=Xonomy.pickerMenu(picklist, defaultString);
html+="<form class='undermenu' onsubmit='Xonomy.answer(this.val.value); return false'>";
html+="<input name='val' class='textbox focusme' value='"+(!isInPicklist ? Xonomy.xmlEscape(defaultString) : "")+"'/>";
html+=" <input type='submit' value='OK'>";
html+="</form>";
return html;
};
Xonomy.askRemote=function(defaultString, param, jsMe) {
var html="";
if(param.searchUrl || param.createUrl) {
html+="<form class='overmenu' onsubmit='return Xonomy.remoteSearch(\""+Xonomy.xmlEscape(param.searchUrl, true)+"\", \""+Xonomy.xmlEscape(param.urlPlaceholder, true)+"\", \""+Xonomy.xmlEscape(Xonomy.jsEscape(defaultString))+"\")'>";
html+="<input name='val' class='textbox focusme' value=''/>";
if(param.searchUrl) html+=" <button class='buttonSearch' onclick='return Xonomy.remoteSearch(\""+Xonomy.xmlEscape(param.searchUrl, true)+"\", \""+Xonomy.xmlEscape(param.urlPlaceholder, true)+"\", \""+Xonomy.xmlEscape(Xonomy.jsEscape(defaultString))+"\")'>&nbsp;</button>";
if(param.createUrl) html+=" <button class='buttonCreate' onclick='return Xonomy.remoteCreate(\""+Xonomy.xmlEscape(param.createUrl, true)+"\", \""+Xonomy.xmlEscape( (param.searchUrl?param.searchUrl:param.url) , true)+"\", \""+Xonomy.xmlEscape(param.urlPlaceholder, true)+"\", \""+Xonomy.xmlEscape(Xonomy.jsEscape(defaultString))+"\")'>&nbsp;</button>";
html+="</form>";
}
html+=Xonomy.wyc(param.url, function(picklist){ return Xonomy.pickerMenu(picklist, defaultString); });
return html;
};
Xonomy.remoteSearch=function(searchUrl, urlPlaceholder, defaultString){
var text=$("#xonomyBubble input.textbox").val();
searchUrl=searchUrl.replace(urlPlaceholder, encodeURIComponent(text));
$("#xonomyBubble .menu").replaceWith( Xonomy.wyc(searchUrl, function(picklist){ return Xonomy.pickerMenu(picklist, defaultString); }) );
return false;
};
Xonomy.remoteCreate=function(createUrl, searchUrl, urlPlaceholder, defaultString){
var text=$.trim($("#xonomyBubble input.textbox").val());
if(text!="") {
createUrl=createUrl.replace(urlPlaceholder, encodeURIComponent(text));
searchUrl=searchUrl.replace(urlPlaceholder, encodeURIComponent(text));
$.ajax({url: createUrl, dataType: "text", method: "POST"}).done(function(data){
if(Xonomy.wycCache[searchUrl]) delete Xonomy.wycCache[searchUrl];
$("#xonomyBubble .menu").replaceWith( Xonomy.wyc(searchUrl, function(picklist){ return Xonomy.pickerMenu(picklist, defaultString); }) );
});
}
return false;
};
Xonomy.pickerMenu=function(picklist, defaultString){
var html="";
html+="<div class='menu'>";
for(var i=0; i<picklist.length; i++) {
var item=picklist[i];
if(typeof(item)=="string") item={value: item, caption: ""};
if(item.value==defaultString) isInPicklist=true;
html+="<div class='menuItem techno"+(item.value==defaultString?" current":"")+"' onclick='Xonomy.answer(\""+Xonomy.xmlEscape(item.value)+"\")'>";
html+="<span class='punc'>\"</span>";
html+=Xonomy.xmlEscape(item.value);
if(item.displayValue) html+=Xonomy.textByLang(item.displayValue); else html+=Xonomy.xmlEscape(item.value);
html+="<span class='punc'>\"</span>";
if(item.caption!="") html+=" <span class='explainer'>"+Xonomy.xmlEscape(Xonomy.textByLang(item.caption))+"</span>";
html+="</div>";
}
html+="</div>";

html+="<form class='undermenu' onsubmit='Xonomy.answer(this.val.value); return false'>";
html+="<input name='val' class='textbox focusme' value='"+(!isInPicklist ? Xonomy.xmlEscape(defaultString) : "")+"'/>";
html+=" <input type='submit' value='OK'>";
html+="</form>";
return html;
};
Xonomy.askRemote=function(defaultString, param, jsMe) {
var html=Xonomy.wyc(param.url, function(picklist){
var html="";
html+="<div class='menu'>";
for(var i=0; i<picklist.length; i++) {
var item=picklist[i];
if(typeof(item)=="string") item={value: item, caption: ""};
html+="<div class='menuItem techno"+(item.value==defaultString?" current":"")+"' onclick='Xonomy.answer(\""+Xonomy.xmlEscape(item.value)+"\")'>";
html+="<span class='punc'>\"</span>";
if(item.displayValue) html+=Xonomy.textByLang(item.displayValue); else html+=Xonomy.xmlEscape(item.value);
html+="<span class='punc'>\"</span>";
if(item.caption!="") html+=" <span class='explainer'>"+Xonomy.xmlEscape(Xonomy.textByLang(item.caption))+"</span>";
html+="</div>";
}
html+="</div>";
return html;
});
}
html+="</div>";
return html;
};

0 comments on commit 46cdb6c

Please sign in to comment.
You can’t perform that action at this time.