Angular ui calendar, $scope.events remains as undefined - angularjs

here's what my controllers looks like
var resource = Restangular.all('api/events/');
resource.getList().then(function(events){
$scope.events = events;
});
$scope.eventRender = function( event, element, view ) {
element.attr({'tooltip': event.title,
'tooltip-append-to-body': true});
$compile(element)($scope);
};
/* config object */
$scope.uiConfig = {
calendar:{
height: 700,
editable: true,
header: {
left: 'prev,next title',
//center: 'title',
right: 'month,agendaWeek,'
},
eventRender: $scope.eventRender
}
};
/* event sources array*/
$scope.eventSources = [$scope.events];
i think angular ui calendar directive is getting triggered first,
how can i make it to get data first and then trigger directive?

You can specify a function in eventSources which does the fetching like so, you have to call the callback function with an array of events.
var resource = Restangular.all('api/events/');
/* event sources array*/
$scope.eventSources = [fetchEvents];
function fetchEvents(start, end, timezone, callback) {
resource.getList()
.then(function(events) {
// do some event processing ?
callback(events);
});
}
Side note from my own experience with fullCalendar and Angular:
$scope.eventRender = function( event, element, view ) {
element.attr({'tooltip': event.title, 'tooltip-append-to-body': true});
$compile(element)($scope);
};
This is a really big bottleneck on performance, and you probably want to avoid this. It will create a dom node+logic for EVERY event you render, which can be quite a lot. The best thing to do is to either make your own tooltip directive which reuses the same dom element or to use the title attribute.

Please try this it should work
/* config object */
$scope.uiConfig = {
calendar:{
height: 700,
editable: true,
header: {
left: 'prev,next title',
//center: 'title',
right: 'month,agendaWeek,'
},
eventRender: getEvents
}
};
$scope.eventSources = [];
function getEvents(callback){
console.log(from); // For test purposes
// Request for data from server and when it comes, call callback to update calendar
var resource = Restangular.all('api/events/');
resource.getList().then(function(events){
$scope.events = events;
callback(events);
});
}
};

Related

Remove all events fullcalendar angular js

I have events came from the database. Fullcalendar is working fine but how to remove all events in click button. My main goal is to reset all event when i need to. Is this possible or any other ways to achieve this goal. Im new to angular js. really appreciate your help. thanks in advance
html
<div class="content-panel" ng-controller="Controller">
<div ui-calendar="uiConfig.calendar" class="span8 calendar" ng-model="eventSources" calendar="myCalendar"></div>
<button type="button" ng-click="removeallevents()">Remove all Event</button>
</div>
js
var app = angular.module('app', ['ui.calendar']);
app.controller('Controller', function($scope, $http ,$timeout){
$scope.events = [];
$scope.myevents = function(start, end, timezone, callback) {
$scope.loaderForm=true;
var formdata = $scope.data;
$http.post("EventsDate.php", formdata).then(function (response) {
var events = [];
var data = response.data;
angular.forEach(data, function(value, key){
$scope.events.push({
id: value.ID,
title: value.titleEvent,
start: value.dateEvent
});
});
callback(events);
$scope.loaderForm=false;
});
}
$scope.removeallevents = function() {
//function to remove all events
}
$scope.uiConfig = {
calendar:{
editable: true,
header:{
left: 'title',
center: '',
right: 'today prev,next'
},
dayClick: $scope.addEvent
}
};
$scope.eventSources = [$scope.events,$scope.myevents];
});
Yes, it's posible usign full calendar function to remove events:
.fullCalendar('removeEvents');
You can find more info here

Events disapearing after month change

I've been using the ui-calendar for an application. But, today I've got a problem that when I change the month (for example, click the button and go from February to March and after this I go back) my events gone.
When I load:
When I Change:
When I Go Back:
The code config I've been using this time.
`
$scope.alertOnEventClick = function(date, jsEvent, view) {
console.log('evento clicado', date, jsEvent, view);
}
$scope.eventRender = function( event, element, view ) {
element.attr({'tooltip': event.title, 'tooltip-append-to-body': true});
$compile(element)($scope);
};
$scope.changeView = function(view,calendar) {
uiCalendarConfig.calendars[calendar].fullCalendar('changeView',view);
};
$scope.renderCalender = function(calendar) {
if(uiCalendarConfig.calendars[calendar]){
uiCalendarConfig.calendars[calendar].fullCalendar('render');
}
};
$scope.eventSources = [$scope.events];
$scope.uiConfig = {
calendar:{
lang: 'pt-br',
height: "parent",
editable: false,
theme:true,
header:{
left: '',
center: 'title',
right: 'today, prev,next'
},
eventClick: $scope.alertOnEventClick,
eventRender: $scope.eventRender
}
};
`
It's an issue in ui-calendar. I've found a solution where I change the function onAdded to:
eventsWatcher.onAdded = function (event) {
if (calendar && calendar.fullCalendar) {
calendar.fullCalendar('renderEvent', event, true);
}
};

How to initialize a combo value in viewController init() without firing its change event

I have a Sencha Fiddle that describes the problem:
https://fiddle.sencha.com/#fiddle/13ol
I want to initialize the combo, but avoid firing its change event (until after init() is complete). The value for the combo is first available in the viewController init() method.
I don't know how you can defer it until after init function, but you can at least defer it until directly before init function ends:
init: function() {
var combo = this.lookupReference('MyCombo');
combo.suspendEvent("change");
combo.setValue('Week');
// do everything else you want to do in init.
combo.resumeEvent("change");
}
I have tested in your fiddle that this code:
init: function() {
var combo = this.lookupReference('MyCombo');
combo.suspendEvent("change");
combo.setValue('Week');
console.log('testfirst');
combo.resumeEvent("change");
},
onMyComboChange: function() {
console.log('testsecond')
// Need to avoid firing this method during init
}
produces this console.log:
run?_dc=1452632485198:60 testfirst
run?_dc=1452632485198:65 testsecond
Use value config to create combobox with an initial value.
Ext.define('MyApp.view.TestViewControler', {
...
init: function() {
// Do something
var newValue = 'Week'; // Get new value
this.getView().addCombo(newValue);
}
...
});
Ext.define('MyApp.view.TestView', {
...
addCombo: function(value) {
this.add({
xtype: 'combo',
reference: 'MyCombo',
editable: false,
hidden: false,
fieldLabel: 'My Combo',
bind: {
store: '{comboStore}'
},
displayField: 'name',
valueField: 'key',
listeners: {
change: 'onMyComboChange'
},
value: value
});
}
});

What is the correct way to use ui-calendar with Urigo's angular-meteor?

I want to use ui-calendar with Urigo's angular-meteor. I code like this, it doesn't work but I don't know why and how to fix it.
The collection is not empty but event do not appear in calendar. Thank you for attention.
https://github.com/wuxianliang/ui-calendar-angular-meteor
CalEvents = new Mongo.Collection("calevents");
CalEvents.allow({
insert: function () {
return true;
},
update: function () {
return true;
},
remove: function () {
return true;
}
});
if (Meteor.isClient) {
angular.module('Calendardemo', ['angular-meteor', 'ui.calendar','ui.router', 'angularMoment','mgcrea.ngStrap','ngAnimate']);
Meteor.startup(function() {
angular.bootstrap(document, ['Calendardemo']);
});
angular.module('Calendardemo').controller('MyCalendar', [
'$scope',
'$collection',
function($scope, $collection) {
$collection(CalEvents).bind($scope,'calevents',true,true);
$scope.addCalEvent=function(date, jsEvent, view){
var startDateTime = moment(date).format('YYYY-MM-DDTHH:mm:ss.SSSZ');
var endDateTime = moment(date).add(1, 'h').format('YYYY-MM-DDTHH:mm:ss.SSSZ');
$scope.calevents.push({
title: 'New Event',
start: startDateTime,
end: endDateTime,
completed: null,
doing: null
})
};
$scope.eventRender = function(event,element){};
/* config object */
$scope.uiConfig = {
calendar:{
height: 450,
defaultView: 'month',
lang: 'en',
eventColor: 'grey',
header:{
left: 'prev next today',
center: 'title',
right: 'month agendaWeek'
},
dayClick: $scope.addCalEvent,
eventRender: $scope.eventRender,
editable: true,
selectable: true,
allDayDefault: false
}
};
$scope.eventSources = [$scope.calevents];
}]);}
if (Meteor.isServer) {
Meteor.publish('calevents', function(){
return CalEvents.find();
})
}
You should use this package:
https://github.com/netanelgilad/meteor-angular-ui-calendar
This package wraps angular-ui-calendar for Meteor.
It might not updated so you can open an issue inside
EDIT
You might also want to check out this package that looks more updated:
https://atmospherejs.com/planettraining/angular-ui-calendar

Asscociating a store with Ext.menu.Menu

I am new to extjs.I want to associate a store on selecting a menu item from Ext.menu.Menu. I am using extjs 4.1.0. I searched on the net even went through sencha doc but I couldn't find any way to achieve this.
Is there some way to achieve it?
Thanks in advance.
I'm using a menu with a store in a project. Here's an example:
Ext.define("Ext.ux.menu.DynamicMenu", {
extend: "Ext.menu.Menu",
alias: 'widget.dynamicmenu',
loaded: false,
loadMsg: 'Loading...',
store: undefined,
icon: '',
constructor: function (config) {
var me = this;
Ext.apply(me, config);
me.callParent();
},
initComponent: function () {
var me = this;
me.callParent(arguments);
me.on('show', me.onMenuLoad, me);
listeners = {
scope: me,
load: me.onLoad,
beforeload: me.onBeforeLoad
};
me.mon(me.store, listeners);
},
onMenuLoad: function () { var me = this; if (!me.store.loaded) me.store.load(); },
onBeforeLoad: function (store) { this.updateMenuItems(false); },
onLoad: function (store, records) { this.updateMenuItems(true, records); },
updateMenuItems: function (loadedState, records) {
var me = this;
me.removeAll();
if (loadedState) {
me.setLoading(false, false);
Ext.Array.each(records, function (record, index, array) {
me.add({
text: record.get('DisplayName'),
data: record,
icon: me.icon
});
});
me.store.loaded = true;
}
else {
me.add({ width: 75, height: 40 });
me.setLoading(me.loadMsg, false);
}
me.loaded = loadedState;
}
});
I found this one on the sencha forums if IIRC, but can't find the link anymore. I made some tweaks for icons etc, ...
On the Ext.Array.each(records, ....
You'll need to define your own logic, It's depending on your model. My model has a DisplayName which I use to show as text. I also stock my record in a data property I made in the menu item. You're completely free there.
Good luck!

Resources