Doubts in general about ember components by a java developer - ember.js

I created a panel component with a button which contains some actions in controller.
So the first doubt: What's the main difference between components and views?
I really dont know if i'm doing things in the correct way
First i created a "father" controller which will contain the method to send a panel action to the specified controller action
App.BasicArrayController = Ember.ArrayController.extend({
actions : {
panelActions : function(action) {
this.send(action)
},
},
});
App.BasicObjectController = Ember.ObjectController.extend({
actions : {
panelActions : function(action) {
this.send(action);
},
},
});
Next i created the controller which will extend the "father" and created a object which contains the name to display in panel and the name of action in controller
App.AlbumController = App.BasicObjectController.extend({
arrayActions : [Em.Object.create({name: 'Edit'},{action:'edit'}),Em.Object.create({name: 'Delete'},{action:'delete'})],
actions : {
edit:function(){
this.transitionToRoute('album.edit');
},
confirmDelete:function(){
this.get('model').deleteRecord();
this.get('model').save();
this.transitionToRoute('albums');
}
}
});
This is the correct way to extend a controller in ember?
Next i created the component template (.hbs) with bootstrap
<div {{bind-attr class=bootStrapClass}}>
<div class="panel-heading">
{{#if arrayActions}}
<div style="margin-top: -1.3%" class="btn-group pull-right">
<button type="button" class="btn btn-default dropdown-toggle"
data-toggle="dropdown">
Actions <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
{{#each arrayActions}}
<li><a href="#" {{action 'panelActions' this on='click'}}>{{name}}</a></li>
{{/each}}
</ul>
</div>
{{/if}}
<h3 data-toggle="collapse" data-parent="#accordion" {{bind-attr
href=hrefCollapseId}} {{action 'collapse' on='click'
}} class="panel-title">
<span {{bind-attr id=collapseId}}
class="glyphicon glyphicon-collapse-up">{{title}}
</h3>
</div>
<div {{bind-attr id=customId}} class="panel-collapse collapse in">
<div class="panel-body">{{yield}}</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" {{bind-attr id=myModalId}} tabindex="-1"
role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button {{action 'cancelDelete'}} type="button" class="close"
data-dismiss="modal">
<span aria-hidden="true">×</span><span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">Album</h4>
</div>
<div class="modal-body">Are you shure?</div>
<div class="modal-footer">
<button type="button"
{{action 'cancelDelete'}} class="btn btn-default"
data-dismiss="modal">Cancel</button>
<button type="button"
{{action 'confirmDelete' this}} class="btn btn-primary">Confirm</button>
</div>
</div>
</div>
</div>
Now the component .js
App.PanelPrimaryComponent = Ember.Component.extend({
setupIds: function(){
this.setProperties({
collapseId: "collapse" + this.get('customId'),
hrefCollapseId:"#" + this.get('customId'),
myModalId: "myModal" + this.get('customId')
});
}.on("init"),
actions : {
panelActions : function(obj) {
if(obj.action==="delete") this.send('delete');
else
this.sendAction('panelActions',obj.action);
},
delete:function(){
var jqueryModalId = "#"+ this.get('myModalId');
$(jqueryModalId).modal('toggle')
},
cancelDelete:function(){
this.set('deleteMode',false);
},
confirmDelete:function(){
$(".close").click();
this.sendAction('panelActions','confirmDelete');
},
collapse:function(){
var jQueryCollpaseId= "#"+this.get('collapseId');
if($(jQueryCollpaseId).hasClass("glyphicon-collapse-down")){
$(jQueryCollpaseId).removeClass("glyphicon-collapse-down").addClass("glyphicon-collapse-up")
}
else{
$(jQueryCollpaseId).removeClass("glyphicon-collapse-up").addClass("glyphicon-collapse-down")
}
}
}
});
Next a template which uses the component
<div class="col-xs-6">
{{#panel-primary title="Album" bootStrapClass="panel panel-success" customId="album" arrayActions=arrayActions panelActions='panelActions'}}
<span class="label label-default">Name: </span> {{name}} <span
class="label label-default">Description: </span> {{description}} {{/panel-primary}}
</div>
{{outlet}}
In general this is the best way to do that kind of component? What shold i do different in general?
Since i can have multiple panels i have to bind a dynamic id("collpase" and "modalId" , this is the correct way?
This is the best way to send that kind of action to controller in a component?
In general this is the best way to do that kind of component? What shold i do different in general?

Related

Bootstrap wizard not working inside Bootstrap modal or jquery-ui dialog

Stuck on this for quite some time now, I am trying to create a form wizard using twitter bootstrap wizard (http://vinceg.github.io/twitter-bootstrap-wizard/) which is shown on button click inside a modal window. This doesn't seem to be working for me.
The wizard is created dynamically using an ajax call, which returns the html for the wizard. I also tried using jQuery Steps plugin which was also not working properly inside the modal windows. I tried 2 approaches:
Appending the wizard html inside a jquery-ui dialog. - Here the jquery steps plugin method .steps() wasn't able to create the wizard, rather flat html was rendered instead of a wizard.
Appending the wizard html inside a bootstrap wizard - Tabs are created as links, but clicking on either of the tabs navigates to localhost:port//#tab1
Here are my code snippets:
Bootstrap Wizard
<div id="MainContainer">
<form id="MainForm" class="form-horizontal">
<div class='sectionA' id='rootwizard'>
<ul class="nav nav-tabs">
<li class="active">Tab1</li>
<li>Tab2</li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="Tab1">
<div class="control-group">
<label class="control-label" for="email">Email</label>
<div class="controls">
<input type="text" id="emailfield" name="emailfield" class="required email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="name">Name</label>
<div class="controls">
<input type="text" id="namefield" name="namefield" class="required">
</div>
</div>
</div>
<div class="tab-pane" id="Tab2">
<div class="control-group">
<label class="control-label" for="url">URL</label>
<div class="controls">
<input type="text" id="urlfield" name="urlfield" class="required url">
</div>
</div>
</div>
<ul class="pager wizard">
<li class="previous">Previous</li>
<li class="next">Next</li>
</ul>
</div>
</div>
</form>
</div>
Modal Window
<div id="MainDiv" tabindex="-1" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit Trigger</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="DialogDiv">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Javascript
$('#MainDiv').on('shown.bs.modal', function (e) {
$.ajax({
url: '/MethodToFetchData',
type: 'POST',
data: data,
contentType: 'application/json; charset=utf-8',
success: function (data) {
var html = JSON.stringify(data);
html = html.replace(/(?:\\[rn])+/g, "");
initTriggerAdvancedEdit(html);
},
error: function (err) { alert(JSON.stringify(err)); }
});
});
function initTriggerAdvancedEdit(html) {
$('#rootwizard').bootstrapWizard({
'tabClass': 'nav nav-pills'
});
}

ngx-bootstrap multiple draggable modals(not nested) on same page

i am new in ngx-bootstrap.. working with ngx-bootstrap modals..
using child modal component (#ViewChild('childModal') childModal: CommonModalComponent)
i am able to create simple modals.
the requirement is to show multiple draggable modals at the same page.
Eg. two buttons on page. button1 & button2.
if I click on button1 than respective modal-1 should show.
and now modal-1 should remain open and I can click on button2 and it will show modal2.
now I can see both modal1 and modal2 on the same page and able to drag both..?
how to do it with ngx-bootstrap?
modal-dailog.component.ts
import {Component,Input, ViewChild} from '#angular/core';
import { ModalDirective } from 'ngx-bootstrap';
#Component({
selector: 'common-modal',
templateUrl: './modal-dailog.component.html',
})
export class CommonModalComponent {
#ViewChild('childModal') public childModal:ModalDirective;
#Input() title?:string;
constructor() {
}
show(){
this.childModal.show();
}
hide(){
this.childModal.hide();
}
}
modal-dailog.component.html
<div id='wrapper'>
<div bsModal #childModal="bs-modal" class="modal fade" role="dialog" aria-labelledby="mySmallModalLabel" [config]="{backdrop: false, ignoreBackdropClick: true}" aria-hidden="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title pull-left">{{title}}</h4>
<button type="button" class="close pull-right" aria-label="Close" (click)="hide()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<ng-content select=".modal-body"> </ng-content>
<ng-content select=".modal-footer"> </ng-content>
</div>
</div>
</div>
</div>
</div>
parent.component.ts
import {Component, ViewChild, ViewContainerRef} from '#angular/core'
import {CommonModalComponent} from './core/modal-dailog/modal-dailog.component';
#Component({
selector: 'modal-demo',
templateUrl: './parent.component.html',
})
export class demoComponent {
#ViewChild('childModal') childModal: CommonModalComponent;
#ViewChild('childModal2') childModal2: CommonModalComponent;
constructor() {
}
onCancle() {
this.childModal.hide();
}
onCancle2() {
this.childModal2.hide();
}
}
parent.component.html
<button type="button" class="btn btn-primary"
(click)="childModal.show()">Open modal</button>
<common-modal #childModal [title]="'common modal'">
<div class="modal-body">
hii, modal-body 1
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary"
(click)="onCancle()" >Cancle
<span aria-hidden="true">×</span>
</button>
</div>
</common-modal>
<button type="button" class="btn btn-primary"
(click)="childModal2.show()">Open modal2</button>
<common-modal #childModal2 [title]="'common modal2'">
<div class="modal-body">
hii, modal-body 2
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary"
(click)="onCancle2()" >Cancle
<span aria-hidden="true">×</span>
</button>
</div>
</common-modal>

Ember model attributes in modals

This is my problem:
What I'm trying to do is when I click on a model's name, I get a modal window that shows all it's attributes, like so:
However, when I click on another one, it doesn't work, no modals show up, like so:
This is my index.hbs:
<div class="row" style="text-align:center;">
{{#each model as |event|}}
<div class="col-xs-3 col-md-3">
<div class="centerBlock">
</div>
<button type="button" class="btn btn-link" data-toggle="modal" data-target="#{{event.name}}">{{event.name}}</button>
</div>
<!-- Modal -->
<div class="modal fade" id="{{event.name}}" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">{{event.name}}</h4>
</div>
<div class="modal-body">
<p>{{event.location}}</p>
<p>{{event.roomNumber}}</p>
<p>{{event.eventDay}}</p>
<p>{{event.eventTime}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- End Modal-->
{{/each}}
</div>
And this is my index.js:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('event');
}
});
I suppose that I'm doing my {{#each}} wrong, but I've spent about an hour on it and I can't figure it out.
Sorry this is such a dumb problem, and thanks for any direction!
The problem is your event name. You have spaces in Yoga Drop-In and later you use that as modal id attribute. You can't target model by id with spaces. You have to use another property as modal target. For example you could take model name and remove all spaces from that, or replace with dashes. It will work after you do so.

Bootstrap modal and BXslider not working

HTML:
<!-- Button trigger modal -->
<a href="#" data-toggle="modal" data-target="#myModal" class="quickview">
OPEN MODAL
</a>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">BX Slider</h4>
</div>
<div class="modal-body">
<ul class="bxslider">
<li><img src="http://bxslider.com/images/730_200/tree_root.jpg" /></li>
<li><img src="http://bxslider.com/images/730_200/houses.jpg" /></li>
<li><img src="http://bxslider.com/images/730_200/hill_fence.jpg" /></li>
</ul>
<div id="bx-pager">
<a data-slide-index="0" href=""><img src="http://bxslider.com/images/thumbs/tree_root.jpg" /></a>
<a data-slide-index="1" href=""><img src="http://bxslider.com/images/thumbs/houses.jpg" /></a>
<a data-slide-index="2" href=""><img src="http://bxslider.com/images/thumbs/hill_fence.jpg" /></a>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
JS:
function quickView() {
var slider = $('.bxslider').bxSlider({
pagerCustom: '#bx-pager',
controls: false
});
slider.destroySlider();
//$('#myModal').modal('show');
slider.reloadSlider();
}
$(".quickview").on("click", quickView);
I have a Bootstrap modal which I'm injecting dynamic image galleries into. So fx. I have 10 links on a page, each link is containing unique data-attributes with image URLs. I am then sending these URLs into my click event, so I can use them with BXslider, but it doesn't seem to be working.
I'm reloading the BXslider within my click event, but the "mainimage" is not showing.
However, if I move the code out of the click event, it seems like it's working.
Any suggestions here?
Codepen:
http://codepen.io/marting/pen/dYNabj?editors=101
I changed your code to this, and it works like a charm
JS:
function quickView() {
var slider = $('.bxslider').bxSlider({
pagerCustom: '#bx-pager',
controls: false
});
setTimeout(function() {
slider.reloadSlider();}, 200);
}
$(".quickview").on("click", quickView);
See it works here: http://codepen.io/anon/pen/JYgxOE?editors=101

ReferenceError: fav is not defined

I am a noob with emberjs and I am stuck at the issue for a while now. I created an itemController with the variable fav, but it keeps saying that it is not defined.
My index.html snippet looks like this:
<table class='table'>
{{#each model itemController='hotel'}}
<tr><td>
{{#if fav}}
<h4>{{title}}
<button {{action 'rmFav'}} type="button" class="btn btn-default btn-sm pull-right">
<span class="glyphicon glyphicon-heart"></span>
</button>
</h4>
{{else}}
<h4>{{title}}
<button type="button" class="btn btn-default btn-sm pull-right" {{action 'putFav'}}>
<span class="glyphicon glyphicon-heart-empty"></span>
</button>
</h4>
{{/if}}
<p> {{description}} </p>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star-empty"></span>
</td></tr>
{{/each}}
</table>
and my app.js has the following snippet related to the itemController:
App.HotelController = Ember.ObjectController.extend({
actions: {
putFav: function(){
this.set(fav,true)
},
rmFav: function() {
this.set(fav,false);
}
}
});
UPDATE: Just a clarification, I have an array of objects in json format in app.js file, and each object in it contains fav attribute.
Your problem is with HotelController you are referencing an undeclared variable fav in this.set(fav,...) you need to change to a string, like this.set("fav",...):
App.HotelController = Ember.ObjectController.extend({
actions: {
putFav: function(){
this.set("fav",true);
},
rmFav: function() {
this.set("fav",false);
}
}
});