Add reminder on google calendar with golang - go

I want to add a custom reminder to Google Calendar with golang:
event := &calendar.Event{
Summary: "Test GG calendar",
Location: "31 AAA",
Description: "Test google calendar",
Start: &calendar.EventDateTime{
DateTime: "2016-12-27T17:30:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
End: &calendar.EventDateTime{
DateTime: "2016-12-27T17:40:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
Reminders: &calendar.EventReminders{
Overrides: []*calendar.EventReminder{
{Method: "email", Minutes: 30},
{Method: "popup", Minutes: 10},
},
UseDefault: false,
},
}
When I run this code, google could not add event. I received this error: Unable to create event. googleapi: Error 400: Cannot specify both default reminders and overrides at the same time., cannotUseDefaultRemindersAndSpecifyOverride
Thanks

Based on my reading of google-apps/calendar/concepts/reminders, it seems that you should not specify the UseDefault: false, at the same time as setting the Overrides. Do not put the UseDefault: false, part, and it will be defaulting to false as its only required to set when wanting to remove overrides that are in place already.
So the expected code is:
event := &calendar.Event{
Summary: "Test GG calendar",
Location: "31 AAA",
Description: "Test google calendar",
Start: &calendar.EventDateTime{
DateTime: "2016-12-27T17:30:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
End: &calendar.EventDateTime{
DateTime: "2016-12-27T17:40:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
Reminders: &calendar.EventReminders{
Overrides: []*calendar.EventReminder{
{Method: "email", Minutes: 30},
{Method: "popup", Minutes: 10},
},
},
}

You should send ForceSendFields with UseDefault and set UseDefault to false
&calendar.EventReminders{
Overrides: []*calendar.EventReminder{
{
Method: "email",
Minutes: 12,
},
},
UseDefault: false,
ForceSendFields: []string{"UseDefault"},
}

Related

Validate datetime in Strapi

I create DateTime picker in Strapi with the required field validation but can't save. occurring following error.
apI Parametr
components: []
contentType: {name: "Events", description: "", connection: "default", collectionName: "events",…}
name: "Events"
description: ""
connection: "default"
collectionName: "events"
attributes: {title: {type: "string", required: true},…}
title: {type: "string", required: true}
created_by: {nature: "oneWay", target: "plugins::users-permissions.user", dominant: false, unique: false}
image: {type: "media", multiple: false, required: true}
seo_description: {type: "text"}
seo_title: {type: "string"}
description: {type: "richtext", required: true}
calendly_url: {type: "string"}
start_date: {type: "datetime", required: true}
type: "datetime"
required: true
end_date: {type: "datetime"}
PUT http://localhost:1337/content-type-builder/content-types/application::events.events 400 (Bad Request)```

Kendo ui grid date field, updates day before

I have seen this on "Wannes" comment and it´s exactly what it´s happening to me, but i don´t know how to resolve it because i don´t understand the problem. What i have is a simple grid working with CRUD.
The grid is a client table, whenever one wants to add a new client, he hits the new button and a popover appears. In this popover there are many fields, two of them are:
DataCriacao (the date when the client was created)
DataUpdate (the date when the client was updated)
This is my grid initialization code:
var dataSource = new kendo.data.DataSource({
transport:
{
read:
{
url: "data/clientes.php",
},
update:
{
url: "data/clientes.php?type=update",
type:"POST",
complete: function (e)
{
$("#gridClientes").data("kendoGrid").dataSource.read();
}
},
destroy:
{
url: "data/clientes.php?type=destroy",
type: "POST"
},
create:
{
url: "data/clientes.php?type=create",
type: "POST",
complete: function (e)
{
$("#gridClientes").data("kendoGrid").dataSource.read();
}
},
parameterMap: function(options, operation)
{
if (operation !== "read" && options.models)
{
return {models: kendo.stringify(options.models)};
}
}
},
error:function(e)
{
console.log(e);
},
batch: true,
pageSize: 8,
schema:
{
data: "data",
total: function(response)
{
return $(response.data).length;
},
model:
{
id: "idCliente",
fields:
{
**(other fields here)**
NomeUtilizadorCriador: {editable: false,validation: { required: false } },
DataCriacao: {type:"date", editable: false},
NomeUtilizadorUpdate: {editable: false, validation: { required: false } },
DataUpdate: {type:"date", editable: false},
}
}
}
});
$("#gridClientes").kendoGrid({
dataSource: dataSource,
pageable:
{
messages:
{
display: "{0} - {1} / {2} items",
empty: "0 items",
page: "Page",
of: "of {0}", //{0} is total amount of pages
itemsPerPage: "items per page",
first: "Go to the first page",
previous: "Go to the previous page",
next: "Go to the next page",
last: "Go to the last page",
refresh: "Refresh"
}
},
serverPaging: true,
height: 550,
toolbar:[{name: "create",text: $varGridQuartosBtnNovoPT},{name: "close",text: "X"}],
columns: [
**(other fields here)**
{ field: "NomeUtilizadorCriador", title: "Criado por", hidden: true},
{ field: "DataCriacao", title: "Criado em",format:"{0:yyyy-MM-dd}", hidden: true, width: "10px"},
{ field: "NomeUtilizadorUpdate", title: "Atualizado por", hidden: true},
{ field: "DataUpdate", title: "Atualizado em",format:"{0:yyyy-MM-dd}", hidden: true, width: "10px"},
{command:[{ text: "Detalhes", click: showDetails },{ name: "edit",text:
{edit:$varGridQuartosBtnEditarPT,update:$varGridQuartosBtnActualizarPT,cancel:$varGridQuartosBtnCancelarPT}},
{ name: "destroy",text:$varGridQuartosBtnApagarPT }],title:" ",width: "30px"}],
editable: {
mode:"popup",
template:kendo.template($("#popupGridClientes").html())
}
So, for example if i wanted to create a new client today, this is what appears in those two fields:
DataCriacao: Wed Apr 22 2015 10:46:02 GMT+0100 (WEST) (creation date)
DataUpdate: Wed Apr 22 2015 10:46:02 GMT+0100 (WEST) (update date)
Now if i want to update the client information, the problem appears:
DataUpdate: Wed Apr 22 2015 00:00:00 GMT+0100 (WEST) (update date)
These two fields are type DATE on my database. I don´t know what to do because i don´t understand where to start, does this helps?.
I don't know if I understand you correctly, but as you said, you store data in database in DATE format. That's why time part is zero in your example.
Check what data is in your database. It shouldn't have time.
Problem is in your backend/database side.

Kendo Grid Date Sort not working properly with M/d/yy

I have scoured the interwebs and have not been able to conclude why this is not working as I see in so many demos. I must be missing something simple... except most examples don't use the M/d/yy format for the dates. When I use this format, my data ends up with a column like:
1/19/14
10/05/14
2/02/14
5/15/14
Any ideas? You can see I have my date column template commented out because it wasn't actually doing anything that made a difference.
Here's my Grid:
$("#mygiving-details-grid").kendoGrid({
dataSource: {
schema: {
model: {
fields:{
date: {type: "date"},
fund: {type: "string"},
desc: {type: "string"},
name: {type: "string"},
type: {type: "string"},
amt: {type: "number"}
}
}
}
},
sortable: true,
toolbar: "<span>Filter goes here</span>",
columns: [{
field: "date",
title: myGivingModel.local.giving.date,
// format: "{0:"+systemDateFormat+"}",
// template: "#= kendo.toString(date, '"+systemDateFormat+"') #",
width: 100
}, {
field: "fund",
title: myGivingModel.local.giving.fund
}, {
field: "desc",
title: myGivingModel.local.giving.description
}, {
field: "name",
title: myGivingModel.local.giving.name
}, {
field: "type",
title: myGivingModel.local.giving.type
}, {
field: "amt",
title: myGivingModel.local.giving.amount,
attributes:{
style:"text-align:right;"
},
format: "{0:c}"
}]
});
When using https://github.com/StefH/KendoGridBinderEx this should just work fine. I just changed in the Scripts\common.js this code:
var _DefaultDateFormat = "MM/dd/yyyy";
// into this
var _DefaultDateFormat = "M/dd/yy";
and the sorting works as expected.

Adding multiple series to Chart

I'm currently trying to build a chart showing number of downloads of a product per date.
A sample of the current code is as follows:
var downloads = [
{ value: 48, date: new Date("2013/11/01") },
{ value: 50, date: new Date("2013/11/02") },
{ value: 55, date: new Date("2013/11/03") },
{ value: 35, date: new Date("2013/11/04") }
];
$("#chart").kendoChart({
dataSource: {
data: downloads
},
series: [{
type: "line",
aggregate: "avg",
field: "value",
categoryField: "date"
}],
categoryAxis: {
baseUnit: "days",
min: new Date("2013/10/31"),
max: new Date("2013/11/10"),
labels: {
dateFormats: {
days: "dd/MM"
}
}
}
});
It works fine if I have to display data for one product only. How would I proceed to display download data for another product, i.e. adding another series to the chart?
Right! I figured it out myself. Here it is:
$("#chart").kendoChart({
seriesDefaults: {
tooltip: {
visible: true,
},
type:"line",
aggregate:"avg",
field:"value",
categoryField:"date"
},
series: [{
name: "Product 1",
data: [{ value: 48, date: new Date("2013/11/01") }, { value: 50, date: new Date("2013/11/02") }]
},
{
name: "Product 2",
data: [{ value: 55, date: new Date("2013/11/03") }, { value: 35, date: new Date("2013/11/04") }]
}],
categoryAxis: {
baseUnit: "days",
min: new Date("2013/10/31"),
max: new Date("2013/11/10"),
labels: {
dateFormats: {
days: "dd/MM"
}
}
}
});

Detecting server-side error when editing or creating Kendo Grid entries

I have an editable Kendo Grid to manage (create/modify) user accounts. Editing is done in a popup (versus inline or batch). I have client-side validation to help ensure that valid data is provided to the server, however I cannot figure out how to handle the response from the server in the event that the create/update fails server-side. I'm not talking 'failed' as in the request failed with a HTTP 404 or 500, for example; I'm talking failed as in the script on the server didn't like something about the data and refuses to oblige.
Can someone please show me how I can accomplish this? What I would like to be able to do is after the update is sent to the server, wait for the response. If the response says everything is OK, then great. If the response says something didn't go so well, I'd like to be able to (A) keep the popup editing window open and populated and (B) provide feedback to the user regarding the reason for the rejection. The data should not be committed to the grid unless the response says everything is OK. Likewise, the edit popup should remain open until the server says OK.
I'm flexible with how the server's response should be formatted, as long as I can accomplish what I want.
Before you direct me to the Kendo official API documentation, I am already well aware of it and refer to it daily. However, to say the least, it is incomplete and I cannot find anything relating to this topic. If you have found something in the documentation that you think could help me then by all means point me to the documentation =)
As requested, below is the code I have for creating the grid.
$("#kendo_user_grid").kendoGrid({
columns: [{
title: "Last name",
field: "lName"
},{
title: "First name",
field: "fName"
},{
title: "Business unit",
field: "businessUnit"
},{
title: "Username",
field: "loginId"
},{
title: "Email address",
field: "email"
},{
title: "Phone",
field: "phone"
},{
title: "Address",
field: "address"
},{
title: "City",
field: "city"
},{
title: "State",
field: "state"
},{
title: "Zip code",
field: "zipcode"
},{
title: "Country",
field: "country"
},{
title: "Time zone",
field: "timezone"
},{
title: "Privileges",
field: "privs"
},{
command: ["edit","destroy"],
title: " "
}],
scrollable: false,
dataSource: {
transport: {
read: {
url: "manageUsers.phtml",
data: { mode: "fetch" },
dataType: "json",
type: "POST"
},
update: {
url: "manageUsers.phtml",
data: { mode: "update" },
type: "POST"
},
destroy: {
url: "manageUsers.phtml",
data: { mode: "destroy" },
type: "POST"
},
create: {
url: "manageUsers.phtml",
data: { mode: "create" },
type: "POST"
},
batch: false
},
schema: {
data: "records",
total: "total",
model: {
id: "userId",
fields: {
userId: { editable: false, nullable: true },
lName: { type: "string", editable: true, validation: { required: true } },
fName: { type: "string", editable: true, validation: { required: true } },
businessUnit: { type: "string", editable: true, validation: { required: true } },
loginId: { type: "string", validation: { required: true } },
email: { type: "string", validation: { required: true } },
phone: { type: "string" },
address: { type: "string" },
city: { type: "string" },
state: { type: "string" },
zipcode: { type: "string" },
country: { type: "string" },
timezone: { type: "string" },
privs: { type: "string" }
}
}
},
pageSize: 20,
serverPaging: false,
serverFiltering: false,
serverSorting: false
},
filterable: true,
sortable: true,
pageable: true,
editable: {
mode: "popup",
template: kendo.template($("#kendo_edit_user_template").html())
},
toolbar: ["create","save","cancel"]
});
There are two point to keep in mind:
Schema.errors The field from the server response which contains server-side errors.
error is an event that will be fired if there was an error.
Basically you need to:
add to your schema an errors definition that provides access to the status sent back from the server.
Implement error event handler that, for example, restore previous value.
If your server returns the error message in a field called myError then you would have something like:
schema: {
errors: "myError",
data: "records",
total: "total",
model: {
id: "userId",
fields: {
userId: { editable: false, nullable: true },
lName: { type: "string", editable: true, validation: { required: true } },
fName: { type: "string", editable: true, validation: { required: true } },
...
or:
schema: {
errors: function(response) {
if (response.myError && response.myError !== "OK") {
return response.myError;
}
return false;
},
data: "records",
total: "total",
model: {
id: "userId",
fields: {
userId: { editable: false, nullable: true },
lName: { type: "string", editable: true, validation: { required: true } },
fName: { type: "string", editable: true, validation: { required: true } },
...
and the event would be:
dataSource: {
error : function (e) {
if (e.errors !== false) {
alert("Error: " + e.errors);
// This will cancel any change done
this.cancelChanges();
}
},
transport: {
read: {
url: "manageUsers.phtml",
data: { mode: "fetch" },
dataType: "json",
type: "POST"
},
EDIT : If what you want is to keep the popup open you should do:
dataSource: {
error : function (e) {
if (e.errors !== false) {
alert("Error: " + e.errors);
// This will keep the popup open
grid.one("dataBinding", function (e) {
e.preventDefault(); // cancel grid rebind
});
}
},
transport: {
read: {
url: "manageUsers.phtml",
data: { mode: "fetch" },
dataType: "json",
type: "POST"
},
Where I bind to databinding event just once using jQuery.one

Resources