Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few improvements to calendar node #265

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 83 additions & 46 deletions google/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
<div class="form-row">
<label for="node-input-calendar"><i class="fa fa-tag"></i> <span data-i18n="calendar.label.calendar"></span></label>
<input type="text" id="node-input-calendar">
<select id="node-input-calendar" style="width: 70%"></select>
</div>
<div class="form-row">
<span data-i18n="calendar.label.inject-message"></span>
Expand Down Expand Up @@ -80,40 +80,51 @@
</script>

<script type="text/javascript">
RED.nodes.registerType('google calendar in',{
RED.nodes.registerType('google calendar in', {
category: 'Google',
color:"#C0DEED",
color: "#C0DEED",
defaults: {
google: {type:"google-credentials",required:true},
name: {value:""},
calendar: {value:""},
offsetType: {value:"at"},
offsetFrom: {value:"start"},
offset: {value:"10"},
offsetUnits: {value:"minutes"}
google: { type: "google-credentials", required: true },
name: { value: "" },
calendar: { value: "" },
offsetType: { value: "at" },
offsetFrom: { value: "start" },
offset: { value: "10" },
offsetUnits: { value: "minutes" }
},
inputs:0,
outputs:1,
inputs: 0,
outputs: 1,
icon: "google-calendar.png",
label: function() {
return this.name||this._("calendar.label.google-calendar");
label: function () {
return this.name || this._("calendar.label.google-calendar");
},
oneditprepare: function() {
oneditprepare: function () {
var type = this.offsetType || "at";
$("#node-input-offsetType option").filter(function() {
var node = this;
$("#node-input-offsetType option").filter(function () {
return $(this).val() == type;
}).attr('selected', true);
var from = this.offsetFrom || "start";
$("#node-input-offsetFrom option").filter(function() {
$("#node-input-offsetFrom option").filter(function () {
return $(this).val() == from;
}).attr('selected', true);
$("#node-input-offset").val(this.offset || "0");
var units = this.offsetUnits || "minutes";
$("#node-input-offsetUnits option").filter(function() {
$("#node-input-offsetUnits option").filter(function () {
return $(this).val() == units;
}).attr('selected', true);

var updateOptions = function() {
var google = $("#node-input-google").val() || ""
$.getJSON('cal?id=' + google, function (data) {
data.forEach(function (el) {
$("#node-input-calendar").append('<option value=' + el.id + '>' + el.summary + '</option>');
if (node.calendar == el) {
$('#node-input-calendar option[value="' + node.calendar + '"]').prop('selected', true)
}
})
})

var updateOptions = function () {
var type = $("#node-input-offsetType option:selected").val();
var from = $("#node-input-offsetFrom option:selected").val();
if (type === "at") {
Expand All @@ -123,10 +134,10 @@
$("#node-input-from").html(from);
$("#node-row-offset").show();
}
};
updateOptions();
$("#node-input-offsetType").change(updateOptions);
$("#node-input-offsetFrom").change(updateOptions);
};
updateOptions();
$("#node-input-offsetType").change(updateOptions);
$("#node-input-offsetFrom").change(updateOptions);
},
});
</script>
Expand All @@ -138,7 +149,7 @@
</div>
<div class="form-row">
<label for="node-input-calendar"><i class="fa fa-tag"></i> <span data-i18n="calendar.label.calendar"></span></label>
<input type="text" id="node-input-calendar">
<select id="node-input-calendar" style="width: 70%"></select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="calendar.label.name"></span></label>
Expand All @@ -160,6 +171,7 @@
<ul>
<li><b>payload</b> - a text search string used to select relevant events</li>
<li><b>calendar</b> - the calendar to retrieve the event from (optional, defaults to the node calendar property or the users primary calendar)</li>
<li><b>list</b> - string used to filter list of existing calendars (if used the node will return only the list)</li>
<li><b>count</b> - the number of events to retrieve (Accepted values are [1-10]. If larger than 1, an array will be returned)</li>
</ul>
</p>
Expand All @@ -181,30 +193,43 @@
<li><b>attendees</b> - list of objects containing name and email properties</li>
</ul>
</li>
<li><b>calendars</b> - list of existing calendars</li>
</ul>
</p>
</script>

<script type="text/javascript">
RED.nodes.registerType('google calendar',{
RED.nodes.registerType('google calendar', {
category: 'social',
color:"#C0DEED",
color: "#C0DEED",
defaults: {
google: {type:"google-credentials",required:true},
name: {value:""},
calendar: {value:""},
ongoing: {value: false},
google: { type: "google-credentials", required: true },
name: { value: "" },
calendar: { value: "" },
ongoing: { value: false },
count: {value: 1, validate: function(n) {
return +n >= 1 && +n <= 10;
}}
},
inputs:1,
outputs:1,
inputs: 1,
outputs: 1,
icon: "google-calendar.png",
align: "right",
label: function() {
return this.name||this._("calendar.label.google-calendar");
}
label: function () {
return this.name || this._("calendar.label.google-calendar");
},
oneditprepare: function () {
var node = this;
var google = $("#node-input-google").val() || ""
$.getJSON('cal?id=' + google, function (data) {
data.forEach(function (el) {
$("#node-input-calendar").append('<option value=' + el.id + '>' + el.summary + '</option>');
if (node.calendar == el) {
$('#node-input-calendar option[value="' + node.calendar + '"]').prop('selected', true)
}
})
})
},
});
</script>

Expand All @@ -215,7 +240,7 @@
</div>
<div class="form-row">
<label for="node-input-calendar"><i class="fa fa-tag"></i> <span data-i18n="calendar.label.calendar"></span></label>
<input type="text" id="node-input-calendar">
<select id="node-input-calendar" style="width: 70%"></select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="calendar.label.name"></span></label>
Expand All @@ -235,20 +260,32 @@
</script>

<script type="text/javascript">
RED.nodes.registerType('google calendar out',{
RED.nodes.registerType('google calendar out', {
category: 'Google',
color:"#C0DEED",
color: "#C0DEED",
defaults: {
google: {type:"google-credentials",required:true},
name: {value:""},
calendar: {value:""}
google: { type: "google-credentials", required: true },
name: { value: "" },
calendar: { value: "" }
},
inputs:1,
outputs:0,
inputs: 1,
outputs: 0,
icon: "google-calendar.png",
align: "right",
label: function() {
return this.name||this._("calendar.label.google-calendar");
}
label: function () {
return this.name || this._("calendar.label.google-calendar");
},
oneditprepare: function () {
var node = this;
var google = $("#node-input-google").val() || ""
$.getJSON('cal?id=' + google, function (data) {
data.forEach(function (el) {
$("#node-input-calendar").append('<option value=' + el.id + '>' + el.summary + '</option>');
if (node.calendar == el) {
$('#node-input-calendar option[value="' + node.calendar + '"]').prop('selected', true)
}
})
})
},
});
</script>
Loading