prisme-flow
Version:
prisme platform flow engine
181 lines (155 loc) • 7.18 kB
HTML
<!--
Created by prisme.io on 09/06/2017.
@author <a href="mailto:hello@prisme.io">savane vamara</a> (prisme.io)
-->
<script type="text/x-red" data-template-name="firebase-getit">
<div class="form-row">
<label for="node-input-firebaseConfig"><i class="fa fa-database"></i> Firebase Config</label>
<input type="text" id="node-input-firebaseConfig">
</div>
<div class="form-row">
<label for="node-input-childpath"><i class="fa fa-sitemap"></i> Child Path</label>
<input class="input-append-left" type="text" id="node-input-childpath" placeholder="path-to/the/data">
</div>
<div class="form-row">
<label for="eventType-select"><i class="fa fa-terminal"></i> Event Type</label>
.getit("
<select id="eventType-select" style="width:35%">
<option value="value">value</option>
<option value="child_added">child_added</option>
<option value="child_changed">child_changed</option>
<option value="child_removed">child_removed</option>
<option value="child_moved">child_moved</option>
</select>
")
<input type="hidden" id="node-input-eventType">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="firebase-getit">
<p>Allows get it to a Firebase database.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('firebase-getit',{
category: 'storage',
defaults: {
name: {value:''},
firebaseConfig: {type:'firebase-config',required:true},
childpath: {value: '', required: false},
eventType: {value: "value", required: true},
},
color: '#ffb37a',
inputs:1,
outputs:1,
icon: 'firebase.png',
paletteLabel: "firebase getit",
label: function() {
var config = RED.nodes.node(this.firebaseConfig);
var childpath = (this.childpath.indexOf("/") == 0) ? this.childpath : "/" + this.childpath;
childpath = childpath.substr(-1) == "/" ? childpath.slice(0,-1) : childpath
return this.name ||
(config ? "https://"+config.firebaseurl+".firebaseio.com"+(childpath||"") + ".getit(\""+this.eventType+"\")" : childpath + ".getit(\""+this.eventType+"\")") ||
"firebase.getit(\""+this.eventType+"\")";
},
labelStyle: function() {
return this.name?'node_label_italic':'';
},
oneditprepare: function() {
$('#eventType-select').change(function () {
$("#node-input-eventType").val($(this).find('option:selected').val())
});
$("#eventType-select").val($("#node-input-eventType").val())
$('#eventType-select').trigger('change');
var defaultChildpathValues = [
"msg.childpath",
];
$('#node-input-childpath').autocomplete({
source: defaultChildpathValues,
minLength: 0
});
var illegalCombinationShown = false;
$('#eventType-select').on('change', function(){
if ($(this).val() == "shallow_query"){
$('#node-input-query-illegal-combination-container').fadeOut(300);
$('#node-input-query-container-overall').fadeOut(300);
$('#query-parameters-name-container').fadeOut(300, function(){
$('#eventType-select-info-container').show();
});
$('#node-dialog-ok').prop('disabled', false);
} else {
$('#eventType-select-info-container').fadeOut(300, function(){
$('#query-parameters-name-container').fadeIn(300)
var queries = $('#node-input-query-container').children();
if (queries.length > 0) $('#node-input-query-container-overall').fadeIn(300)
if (checkInputsNotEmpty() && checkSelectsValid()) $('#node-dialog-ok').prop('disabled', false);
else {
var selectsLegal = checkSelectsNotIllegal();
if (!selectsLegal) $('#node-input-query-illegal-combination-container').fadeIn(300);
}
});
}
})
function checkSelectsValid(){
return checkSelectsNotIllegal() && checkSelectsNotEmpty();
}
function checkSelectsNotEmpty(){
var valid = true;
$('#node-input-query-container select').each(function(idx){
if ($(this).val() == null || $(this).val() == ""){
valid = false;
return;
}
});
return valid;
}
function checkSelectsNotIllegal(){
return ($('#node-input-query-illegal-combination-container > p').length > 1 ? false : true)
}
function checkInputsNotEmpty(){
var valid = true;
$('#node-input-query-container input').each(function(idx){
if ($(this).is(':visible') && $(this).val().length == 0){
valid = false;
return;
}
})
return valid;
}
$("#node-input-add-query").click(function() {
var queries = $('#node-input-query-container').children();
if (queries.length < operators.length) generatequery();
$("#node-input-query-container-div").scrollTop($("#node-input-query-container-div").get(0).scrollHeight);
});
if(this.queries){
for (i in this.queries){
generatequery(this.queries[i]);
}
}
function switchDialogResize() {
var rows = $("#dialog-form>div:not(.node-input-query-container-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-query-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-query-container-div").css("height",height+"px");
};
$( "#dialog" ).on("dialogresize", switchDialogResize);
$( "#dialog" ).one("dialogopen", function(ev) {
var size = $( "#dialog" ).dialog('option','sizeCache-switch');
if (size) {
$("#dialog").dialog('option','width',size.width);
$("#dialog").dialog('option','height',size.height);
switchDialogResize();
}
});
$( "#dialog" ).one("dialogclose", function(ev,ui) {
$( "#dialog" ).off("dialogresize",switchDialogResize);
});
}
});
</script>