UI5 Image Gallery with Indices (Carousel or Paginator) - carousel

I would like to build a image gallery (in a lightbox (Overlay)) with Indices displaying the index of the current shown image. Like:
I will rarely have more than 5 pictures, I need "swipe" gestures to display the next/prev ones AND arrows.
First I thought the sap.ui.commons.Carousel would be perfect, but as I did not find any events (like e.g. "transitionEnd") I do not know how to access the current index then. The paginator has no swipe event (?)..
I would appreciate any advice which approach you would follow! Just for the first steps, then I'd be happy to post my code here. Right now I need a little help to start with the best fitting solution of controls.
Thanks a lot.

Why not use sap.m.Carousel? It has pageChanged event with oldActivePageId and newActivePageId params.
Here is a sample:
var appCarousel = new sap.m.App("myApp", {initialPage:"carouselPage"});
var carouselPage = new sap.m.Page("carouselPage",
{title: "Carousel",
enableScrolling: false }
);
var page1 = new sap.m.Page("page1",
{title: "Carousel Test Page 1",
enableScrolling: false }
);
var page2 = new sap.m.Page("page2",
{title: "Carousel Test Page 2",
enableScrolling: false }
);
var carousel = new sap.m.Carousel("myCarousel", {
activePage: page1,
loop: true,
pages: [page1, page2]
});
//Listen to 'pageChanged' events
carousel.attachPageChanged(function(oControlEvent) {
console.log(1);
console.log( "sap.m.Carousel: page changed: old: " + oControlEvent.getParameters().oldActivePageId );
console.log(" new: " + oControlEvent.getParameters().newActivePageId );
});
carouselPage.addContent(carousel);
appCarousel.addPage(carouselPage);
appCarousel.placeAt("content");
sap.ui.getCore().applyChanges();
jsbin: http://jsbin.com/tuqohoqinu/2/edit?html,css,js,console,output
You can see changing of pages in the output window. Hope that helps. Thanks.

Related

Howto refresh lightgallery when dynamicEl has changed

I have different albums, the contents of which I want to show in lightgallery.
My initial call goes like :
$('.dlCms_c_Carousel').lightGallery({
dynamic : true ,
dynamicEl : dlThis.LGDynEl ,
thumbnail : true ,
mode : 'lg-fade' ,
});
This works perfect, but then, when opening another album, I want the one or the other way to refresh such that the new content of dynamicEl is shown.
Is there a way to do it ?
I was trying a
$('.dlCms_c_Carousel').data("lightGallery").destroy(true)
before, but that messed up. I.e. there seemed to be some functionality, but it looked like the lightbox lost some styling and wasn't opaque any more.
Any hints ?
I'm using Waypoint.js for infinite scrolling with lightgallery.
The solution that I found for dynamic refresh was:
var gallery = $(".infinite-container").lightGallery({
selector: '.item'
});
var infinite = new Waypoint.Infinite({
element: document.querySelector('.infinite-container'),
onAfterPageLoad: () => {
gallery.data('lightGallery').destroy(true);
gallery = $(".infinite-container").lightGallery({
selector: '.item'
});
}
});
From my experience, the object returned from the lightgallery initialization has to be used on the destroy.
Hope it helps.

how to destroy in Dojo

I am trying to destroy a div and trying to create it once again. I have a span and couple of buttons inside that div. My requirement is to delete the div and recreate the same elements with the same id.
var element = document.createElement("div");
element.setAttribute("id","cellDiv_divValue_"+retrieveDivID+"_"+0);
var divSpan = document.createElement("span");
divSpan.setAttribute("id","cellDiv_divValue_span_"+retrieveDivID+"_"+0);
divSpan.textContent = storeActionName +":"+appendActions.join();
element.appendChild(divSpan);
var deleteBtn = new dijit.form.Button({
id: "cellDiv_divValue_deleteBtn_"+retrieveDivID+"_"+0,
label: "Delete",
class:"primary-button",
style:{float:"left", left:"381px"},
onClick: function()
{
}
});
element.appendChild(deleteBtn.domNode);
var editBtn = new dijit.form.Button({
id: "cellDiv_divValue_editBtn_"+retrieveDivID+"_"+0,
label: "Edit",
class:"primary-button",
style:{float:"left", left:"266px"}
});
element.appendChild(editBtn.domNode);
$('#divValue_'+storeBtnNumber).append(element);
Currently I am able to delete the elements but when I try to recreate them with the same id, the application shows me an error that the id is already registered.
Can someone help me in this respect.
Thanks,
Nirmal Kumar Bhogadi
This is probably due to the dijit (dijit.form.Button.) When you create an instance of a dijit its ID is registered. You should remove the old button using its destroy method.

Sencha Touch - switching between views

i am trying to make the same app with the miamicode, i am at step 3
http://miamicoder.com/2012/how-to-create-a-sencha-touch-2-app-part-3/
i try to make the button that goes to new note (switch to a new screen and create a new note)
the code at the example is this:
onNewNoteCommand: function () {
console.log("onNewNoteCommand");
var now = new Date();
var noteId = (now.getTime()).toString() + (this.getRandomInt(0, 100)).toString();
var newNote = Ext.create("NotesApp.model.Note", {
id: noteId,
dateCreated: now,
title: "",
narrative: ""
});
this.activateNoteEditor(newNote);
}
the activateNotesList function is this :
activateNotesList: function () {
Ext.Viewport.animateActiveItem(this.getNotesListView(), this.slideRightTransition);
on my own example i try just to go the editview without passing data.
so i try this:
onNewNoteCommand:function()
{
var noteEditor = this.getNoteEditor();
// Ext.Viewport.add(noteEditor); also tried this.
Ext.Viewport.setActiveItem(noteEditor);
that code runs with no errors but the screen doesn't change.
any suggestion? whats the difference on add ?
how do i set the viewport (haven't created any custom viewport) to card? is this the problem that setactiveitem doesn't work? any other way to switch between views?
Are there some errors in google chrome browser's console? Ctrl+Shift+J to open.
Also you have to check if noteEditor equals Object or Number.
From sencha docs: setActiveItem( Object/Number activeItem )

Dojo/Dijit TitlePane

How do you make a titlePane's height dynamic so that if content is added to the pane after the page has loaded the TitlePane will expand?
It looks like the rich content editor being an iframe that is loaded asynchronously confuses the initial layout.
As #missingno mentioned, the resize function is what you want to look at.
If you execute the following function on your page, you can see that it does correctly resize everything:
//iterate through all widgets
dijit.registry.forEach(function(widget){
//if widget has a resize function, call it
if(widget.resize){
widget.resize()
}
});
The above function iterates through all widgets and resizes all of them. This is probably unneccessary. I think you would only need to call it on each of your layout-related widgets, after the dijit.Editor is initialized.
The easiest way to do this on the actual page would probably to add it to your addOnLoad function. For exampe:
dojo.addOnLoad(function() {
dijit.byId("ContentLetterTemplate").set("href","index2.html");
//perform resize on widgets after they are created and parsed.
dijit.registry.forEach(function(widget){
//if widget has a resize function, call it
if(widget.resize){
widget.resize()
}
});
});
EDIT: Another possible fix to the problem is setting the doLayout property on your Content Panes to false. By default all ContentPane's (including subclasses such as TitlePane and dojox.layout.ContentPane) have this property set to true. This means that the size of the ContentPane is predetermined and static. By setting the doLayout property to false, the size of the ContentPanes will grow organically as the content becomes larger or smaller.
Layout widgets have a .resize() method that you can call to trigger a recalculation. Most of the time you don't need to call it yourself (as shown in the examples in the comments) but in some situations you have no choice.
I've made an example how to load data after the pane is open and build content of pane.
What bothers me is after creating grid, I have to first put it into DOM, and after that into title pane, otherwise title pane won't get proper height. There should be cleaner way to do this.
Check it out: http://jsfiddle.net/keemor/T46tt/2/
dojo.require("dijit.TitlePane");
dojo.require("dojo.store.Memory");
dojo.require("dojo.data.ObjectStore");
dojo.require("dojox.grid.DataGrid");
dojo.ready(function() {
var pane = new dijit.TitlePane({
title: 'Dynamic title pane',
open: false,
toggle: function() {
var self = this;
self.inherited('toggle', arguments);
self._setContent(self.onDownloadStart(), true);
if (!self.open) {
return;
}
var xhr = dojo.xhrGet({
url: '/echo/json/',
load: function(r) {
var someData = [{
id: 1,
name: "One"},
{
id: 2,
name: "Two"}];
var store = dojo.data.ObjectStore({
objectStore: new dojo.store.Memory({
data: someData
})
});
var grid = new dojox.grid.DataGrid({
store: store,
structure: [{
name: "Name",
field: "name",
width: "200px"}],
autoHeight: true
});
//After inserting grid anywhere on page it gets height
//Without this line title pane doesn't resize after inserting grid
dojo.place(grid.domNode, dojo.body());
grid.startup();
self.set('content', grid.domNode);
}
});
}
});
dojo.place(pane.domNode, dojo.body());
pane.toggle();
});​
My solution is to move innerWidget.startup() into the after advice to "toggle".
titlePane.aspect = aspect.after(titlePane, 'toggle', function () {
if (titlePane.open) {
titlePane.grid.startup();
titlePane.aspect.remove();
}
});
See the dojo/aspect reference documentation for more information.

jqGrid: different navigator buttons depending on login status

I want to use different navigator buttons in jqGrid depending on login status.
for example: if the user is logged in then add/delete/edit button appeared.
Any ideas?
Thanks in advance.
It is possible to add buttons programmatically using the navButtonAdd method (for the navigation bar) and the toolbarButtonAdd method for the toolbar. For example:
jQuery("#grid").toolbarButtonAdd('#t_meters',{caption:"MyButton",
id: "t_my_button",
title: "Do my button action",
buttonicon: 'ui-icon-edit',
onClickButton:function(){
// Button handle code goes here...
}
});
And:
jQuery("#grid")..navButtonAdd('#pager',{
id: "t_my_button",
title: "Do my button action",
buttonicon: 'ui-icon-edit',
onClickButton:function(){
// Button handle code goes here...
}
});
For more information see the Custom Buttons on the Wiki.
Anyway, once this code is in place, you can detect login status server-side. Then use this knowledge to generate client code that only adds the buttons to your grid if the user is supposed to have access to them.
You can also use for example userdata (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#user_data) to send information about buttons which you need to have in the navigator. userdata should be set by server. Then with respect of:
var navGridParams = jQuery("grid_id").getGridParam('userData');
// var navGridParams = { edit: false, add: false, search: true }
you can get the data set by the server.
Now the typical call like:
jQuery("grid_id").navGrid('#pager', { edit: false, add: false, search: true });
You should place not after creating of jqGrid, but inside of than inside of loadComplete. So the code could looks like following:
var isNavCreated = false;
jQuery('#list').jqGrid({
// ...
loadComplete: function () {
var grid = jQuery("grid_id");
if (isNavCreated === false) {
isNavCreated = true;
var navGridParams = grid.getGridParam('userData');
grid.navGrid('#pager', navGridParams);
}
},
// ...
});
Another option that I see, is to use cookie instead of userdata to send information about navGridParams back to the client.