SQL Count distinct values within the field
I have this weird scenario (at least it is for me) where I have a table
(actually a result set, but I want to make it simpler) that looks like the
following:
ID | Actions
------------------
1 | 10,12,15
2 | 11,12,13
3 | 15
4 | 15,16,17
And I want to count the different actions in the all the table. In this
case, I want the result to be 8 (just counting 10, 11, ...., 17; and
ignoring the repeated values).
In case it matters, I am using MS SQL 2008.
If it makes it any easier, the Actions were previously on XML that looks like
<root>
<actions>10,12,15</actions>
</root>
I doubt it makes it easier, but somebody might comeback with an xml
function that I am not aware and just makes everything easier.
Let me know if there's something else I should say.
Tuesday, 17 September 2013
Assets in Symfony2
Assets in Symfony2
I would like add CSS to one Action/View in my Project. In Symfony i can
use for this config/view.yml in specific folder. This add CSS to section
HEAD. In Symfony i use:
{% stylesheets 'bundles/acme_foo/css/*' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
but this add CSS in current place, not in section HEAD. How is the best
method in Symfony2 to add CSS and JS for one action/view in section HEAD
of HTML?
I would like add CSS to one Action/View in my Project. In Symfony i can
use for this config/view.yml in specific folder. This add CSS to section
HEAD. In Symfony i use:
{% stylesheets 'bundles/acme_foo/css/*' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
but this add CSS in current place, not in section HEAD. How is the best
method in Symfony2 to add CSS and JS for one action/view in section HEAD
of HTML?
Validate Date in Rails before it hits the database
Validate Date in Rails before it hits the database
I need to validate two dates that come from create new record form. Right
now the form has drop downs for year, date, month, hour, minute. In the
controller, I need to validate that the start date is not greater than end
date and it will not let me compare it using the params[:start_date] >
params[:end_date].
How can I properly validate that the start date is not larger than the end
date when adding a new record to the database, I should be doing this in
the model but I cannot figure out how you do it. Does anyone here has any
examples I can look from?
I need to validate two dates that come from create new record form. Right
now the form has drop downs for year, date, month, hour, minute. In the
controller, I need to validate that the start date is not greater than end
date and it will not let me compare it using the params[:start_date] >
params[:end_date].
How can I properly validate that the start date is not larger than the end
date when adding a new record to the database, I should be doing this in
the model but I cannot figure out how you do it. Does anyone here has any
examples I can look from?
Where do I put the mapping files for Elasticsearch?
Where do I put the mapping files for Elasticsearch?
I am confused by the ES docs, in fact here they state the the indexes must
go in the mapping dir (and indexname sub dirs):
Mappings can be defined within files called [mapping_name].json and be
placed either under config/mappings/_default location, or under
config/mappings/[index_name] (for mappings that should be associated only
with a specific index).
But then here in the "config" section, it states:
Index templates can also be placed within the config location (path.conf)
under the templates directory (note, make sure to place them on all master
eligible nodes). For example, a file called template_1.json can be placed
under config/templates and it will be added if it matches an index.
I put my mapping in /config/mappings/myindexname/mappinfile.json and it is
like:
{
"template": "maincontentindex",
"settings": {
"index": {
"analysis": {
"analyzer": {
"htmlStrippingAnalyzer": {
"tokenizer": "standard",
"filter": ["standard", "lowercase"],
"char_filter": "html_strip"
}
}
}
}
},
"mappings": {
"rendition": {
"_timestamp": {
"enabled": true,
"store" : true
},
"properties": {
"key": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"parentPage": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"type": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"language": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"device": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"territory": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"channel": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"template": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"meta": {
"properties": {
"content": {
"type": "string",
"store": "yes"
}
}
}
}
}
}
}
if I use the REST Api to put it in the server it works fine and if I call
/maincontentindex/rendition/_mapping I just get the above structure (even
with no data).
But with the directory I just get a 404 and if I insert anything it's just
the usual dynamic mapping.
I am confused by the ES docs, in fact here they state the the indexes must
go in the mapping dir (and indexname sub dirs):
Mappings can be defined within files called [mapping_name].json and be
placed either under config/mappings/_default location, or under
config/mappings/[index_name] (for mappings that should be associated only
with a specific index).
But then here in the "config" section, it states:
Index templates can also be placed within the config location (path.conf)
under the templates directory (note, make sure to place them on all master
eligible nodes). For example, a file called template_1.json can be placed
under config/templates and it will be added if it matches an index.
I put my mapping in /config/mappings/myindexname/mappinfile.json and it is
like:
{
"template": "maincontentindex",
"settings": {
"index": {
"analysis": {
"analyzer": {
"htmlStrippingAnalyzer": {
"tokenizer": "standard",
"filter": ["standard", "lowercase"],
"char_filter": "html_strip"
}
}
}
}
},
"mappings": {
"rendition": {
"_timestamp": {
"enabled": true,
"store" : true
},
"properties": {
"key": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"parentPage": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"type": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"language": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"device": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"territory": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"channel": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"template": {
"type": "string",
"store": "yes",
"analyzer": "keyword"
},
"meta": {
"properties": {
"content": {
"type": "string",
"store": "yes"
}
}
}
}
}
}
}
if I use the REST Api to put it in the server it works fine and if I call
/maincontentindex/rendition/_mapping I just get the above structure (even
with no data).
But with the directory I just get a 404 and if I insert anything it's just
the usual dynamic mapping.
Sunday, 15 September 2013
How to read first numbers from file in C++
How to read first numbers from file in C++
I have txt file like this.
51.5u-07
-6.5 -10
55u-10
-7 -10
55u-10
-7 -10
55u-10
-7 -10
54u-10
-7 -10
54.5u-10
-7 -10
55u-10
-7 -10
54.5u-10
-7 -10
55.5u-10
-7.5 -10
I want to read this file, get all odd line's value into vector of int,
vec1. get all even line's value into vector of int, vec2.
such as vec1 is [51.5, 55,55,55,... vec2 is [-6.5, -7, -7, -7...] can
anybody help me this?
Thank you.
I have txt file like this.
51.5u-07
-6.5 -10
55u-10
-7 -10
55u-10
-7 -10
55u-10
-7 -10
54u-10
-7 -10
54.5u-10
-7 -10
55u-10
-7 -10
54.5u-10
-7 -10
55.5u-10
-7.5 -10
I want to read this file, get all odd line's value into vector of int,
vec1. get all even line's value into vector of int, vec2.
such as vec1 is [51.5, 55,55,55,... vec2 is [-6.5, -7, -7, -7...] can
anybody help me this?
Thank you.
Safari image overlapping issue
Safari image overlapping issue
Having a weird css image issue with Safari, and haven't been able to find
anything regarding this online anywhere.
Each jewellery piece has a small gallery of thumbnails underneath it. If
there's more thumbnails than can fit in that space, I've set up JS to have
them slide back and forth by adjusting the left margin of the outer div (a
lot like smoothdivscroll, but not as complicated).
In Safari for some reason, the first image in the little thumbnail gallery
is remaining static while the others scroll over it. looks really crap.
And I can't figure why. Is it maybe a bug in Safari?
I do feel like it's a CSS problem, because before adding this sliding
feature, we just had a limit to only 5 images and they would load
overlapped and distorted in Safari as well...
http://jeandousset.com/jewellery/engagement-rings/
Sample HTML:
<div class="span12 offset6 product-images-container" style="margin-left:
140px;">
<div class="product-zoom-container">
<img id="eva-main-image" class="main-image"
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-round-cut-diamond-front.jpg"
data-post-id="530"
title="eva-engagement-ring-cushion-cut-diamond-angle-" alt="">
</div>
<div id="eva-gallery" class="product-gallery text-center">
<div class="scroll-products-right"></div>
<div class="scroll-products-left"></div>
<div class="scrollable-area">
<div class="product-gallery-inner" style="width: 420px;
margin-left: -30px;">
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-angle-.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-angle-.jpg"
title="eva-engagement-ring-cushion-cut-diamond-angle-"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-under.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-under.jpg"
title="eva-engagement-ring-cushion-cut-diamond-under"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-angle.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-angle.jpg"
title="eva-engagement-ring-cushion-cut-diamond-angle"
alt=""></a>
<a href="#" class="product-thumbnail active"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-round-cut-diamond-front.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-round-cut-diamond-front.jpg"
title="eva-engagement-ring-round-cut-diamond-front"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-turned-profile.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-turned-profile.jpg"
title="eva-engagement-ring-cushion-cut-diamond-turned-profile"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
title="eva-engagement-ring-asscher-cut-diamond-angle"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
title="eva-engagement-ring-asscher-cut-diamond-angle"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
title="eva-engagement-ring-asscher-cut-diamond-angle"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
title="eva-engagement-ring-asscher-cut-diamond-angle"
alt="">
</a>
</div>
</div>
</div>
CSS:
.product-gallery {
*zoom: 1;
max-height: 70px;
position: relative;
margin-left: auto;
margin-right: auto;
}
.product-gallery:before,
.product-gallery:after {
display: table;
content: "";
line-height: 0;
}
.product-gallery:after {
clear: both
}
.product-gallery .scrollable-area {
overflow: hidden;
position: relative;
margin-left: auto;
margin-right: auto;
width: 85%;
}
.product-gallery .scroll-products-right,
.product-gallery .scroll-products-left {
position: absolute;
width: 30px;
height: 100%;
background: url(./../img/arrow-small-left.png) center center no-repeat
#fff;
background-color: rgba(255,255,255,0.6);
top: 0;
left: 0;
z-index: 20;
opacity: .6;
filter: alpha(opacity=60);
}
.product-gallery .scroll-products-right:hover,
.product-gallery .scroll-products-left:hover {
cursor: pointer !important;
background-color: rgba(255,255,255,0.8);
opacity: 1;
filter: alpha(opacity=100);
}
.product-gallery .scroll-products-right {
right: 0;
left: auto;
background: url(./../img/arrow-small-right.png) center center
no-repeat #fff;
background-color: rgba(255,255,255,0.6);
}
.product-gallery .product-thumbnail {
float: left;
max-width: 70px;
opacity: .5;
filter: alpha(opacity=50);
}
.product-gallery .product-thumbnail.active {
opacity: 1;
filter: alpha(opacity=100);
}
.product-gallery .product-thumbnail:before,
.product-gallery .product-thumbnail:after {
content: ""
}
JS:
Dousset.product = {
currentWindowWidthMin: null,
currentInterval: null,
init: function () {
$('#wrapper').on('click', '.product-thumbnail',
Dousset.product.thumbClicked);
// $('.product-thumbnail').css({ // 'float': 'none', // 'display':
'inline-block' // });
$('#wrapper').on('mousedown', '.scroll-products-right',
Dousset.product.scrollThumbsLeft);
$('#wrapper').on('mousedown', '.scroll-products-left',
Dousset.product.scrollThumbsRight);
$('#wrapper').on('mouseup', '.scroll-products-left,
.scroll-products-right', function(e){
clearTimeout(Dousset.product.currentInterval);
Dousset.product.currentInterval = null;
});
if((navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i))) {
$('#wrapper').on('click', '.scroll-products-right',
Dousset.product.scrollThumbsLeftBatch);
$('#wrapper').on('click', '.scroll-products-left',
Dousset.product.scrollThumbsRightBatch);
}
Dousset.product.setCurrentWindowWidthMin();
$(window).resize(Dousset.product.windowResized);
},
thumbClicked: function (e) {
e.preventDefault();
if (!$(this).hasClass('active')) {
var postId = $(this).data('post-id');
var newImg = $(this).data('image');
$('.main-image[data-post-id="'+postId+'"]').attr('src',
newImg);
$('.product-thumbnail[data-post-id="'+postId+'"]').removeClass('active');
$(this).addClass('active');
}
},
scrollThumbsLeft: function (e) {
var $inner =
$(this).siblings('.scrollable-area').find('.product-gallery-inner');
var maxMargin = $inner.width() -
$(this).siblings('.scrollable-area').width();
Dousset.product.currentInterval = setInterval(function(){
if (parseInt($inner.css('margin-left'),10) >= -maxMargin) {
$inner.css({
'margin-left' : '-=1'
});
}
},10);
},
scrollThumbsRight: function (e) {
var $inner =
$(this).siblings('.scrollable-area').find('.product-gallery-inner');
Dousset.product.currentInterval = setInterval(function(){
if (parseInt($inner.css('margin-left'),10) <= 0 ) {
$inner.css({
'margin-left' : '+=1'
});
}
},10);
},
scrollThumbsLeftBatch: function (e) {
var $inner =
$(this).siblings('.scrollable-area').find('.product-gallery-inner');
var maxMargin = $inner.width() -
$(this).siblings('.scrollable-area').width();
if (parseInt($inner.css('margin-left'),10) >= -maxMargin) {
$inner.animate({
'margin-left' : '-=70'
});
}
},
scrollThumbsRightBatch: function (e) {
var $inner =
$(this).siblings('.scrollable-area').find('.product-gallery-inner');
if (parseInt($inner.css('margin-left'),10) <= 0 ) {
$inner.animate({
'margin-left' : '+=70'
});
}
},
setCurrentWindowWidthMin: function () {
Dousset.product.currentWindowWidthMin = $( window ).width() >
979 ? 980 : $( window ).width() > 767 ? 768 : 480;
},
windowResized: function () {
var oldWinMin = Dousset.product.currentWindowWidthMin;
Dousset.product.setCurrentWindowWidthMin();
}
}
$(document).ready(function(){ Dousset.product.init(); });
Having a weird css image issue with Safari, and haven't been able to find
anything regarding this online anywhere.
Each jewellery piece has a small gallery of thumbnails underneath it. If
there's more thumbnails than can fit in that space, I've set up JS to have
them slide back and forth by adjusting the left margin of the outer div (a
lot like smoothdivscroll, but not as complicated).
In Safari for some reason, the first image in the little thumbnail gallery
is remaining static while the others scroll over it. looks really crap.
And I can't figure why. Is it maybe a bug in Safari?
I do feel like it's a CSS problem, because before adding this sliding
feature, we just had a limit to only 5 images and they would load
overlapped and distorted in Safari as well...
http://jeandousset.com/jewellery/engagement-rings/
Sample HTML:
<div class="span12 offset6 product-images-container" style="margin-left:
140px;">
<div class="product-zoom-container">
<img id="eva-main-image" class="main-image"
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-round-cut-diamond-front.jpg"
data-post-id="530"
title="eva-engagement-ring-cushion-cut-diamond-angle-" alt="">
</div>
<div id="eva-gallery" class="product-gallery text-center">
<div class="scroll-products-right"></div>
<div class="scroll-products-left"></div>
<div class="scrollable-area">
<div class="product-gallery-inner" style="width: 420px;
margin-left: -30px;">
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-angle-.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-angle-.jpg"
title="eva-engagement-ring-cushion-cut-diamond-angle-"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-under.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-under.jpg"
title="eva-engagement-ring-cushion-cut-diamond-under"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-angle.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-angle.jpg"
title="eva-engagement-ring-cushion-cut-diamond-angle"
alt=""></a>
<a href="#" class="product-thumbnail active"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-round-cut-diamond-front.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-round-cut-diamond-front.jpg"
title="eva-engagement-ring-round-cut-diamond-front"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-turned-profile.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-cushion-cut-diamond-turned-profile.jpg"
title="eva-engagement-ring-cushion-cut-diamond-turned-profile"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
title="eva-engagement-ring-asscher-cut-diamond-angle"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
title="eva-engagement-ring-asscher-cut-diamond-angle"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
title="eva-engagement-ring-asscher-cut-diamond-angle"
alt="">
</a>
<a href="#" class="product-thumbnail"
data-image="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
data-post-id="530">
<img
src="http://doussetwp.loc/wp-content/uploads/2013/07/eva-engagement-ring-asscher-cut-diamond-angle.jpg"
title="eva-engagement-ring-asscher-cut-diamond-angle"
alt="">
</a>
</div>
</div>
</div>
CSS:
.product-gallery {
*zoom: 1;
max-height: 70px;
position: relative;
margin-left: auto;
margin-right: auto;
}
.product-gallery:before,
.product-gallery:after {
display: table;
content: "";
line-height: 0;
}
.product-gallery:after {
clear: both
}
.product-gallery .scrollable-area {
overflow: hidden;
position: relative;
margin-left: auto;
margin-right: auto;
width: 85%;
}
.product-gallery .scroll-products-right,
.product-gallery .scroll-products-left {
position: absolute;
width: 30px;
height: 100%;
background: url(./../img/arrow-small-left.png) center center no-repeat
#fff;
background-color: rgba(255,255,255,0.6);
top: 0;
left: 0;
z-index: 20;
opacity: .6;
filter: alpha(opacity=60);
}
.product-gallery .scroll-products-right:hover,
.product-gallery .scroll-products-left:hover {
cursor: pointer !important;
background-color: rgba(255,255,255,0.8);
opacity: 1;
filter: alpha(opacity=100);
}
.product-gallery .scroll-products-right {
right: 0;
left: auto;
background: url(./../img/arrow-small-right.png) center center
no-repeat #fff;
background-color: rgba(255,255,255,0.6);
}
.product-gallery .product-thumbnail {
float: left;
max-width: 70px;
opacity: .5;
filter: alpha(opacity=50);
}
.product-gallery .product-thumbnail.active {
opacity: 1;
filter: alpha(opacity=100);
}
.product-gallery .product-thumbnail:before,
.product-gallery .product-thumbnail:after {
content: ""
}
JS:
Dousset.product = {
currentWindowWidthMin: null,
currentInterval: null,
init: function () {
$('#wrapper').on('click', '.product-thumbnail',
Dousset.product.thumbClicked);
// $('.product-thumbnail').css({ // 'float': 'none', // 'display':
'inline-block' // });
$('#wrapper').on('mousedown', '.scroll-products-right',
Dousset.product.scrollThumbsLeft);
$('#wrapper').on('mousedown', '.scroll-products-left',
Dousset.product.scrollThumbsRight);
$('#wrapper').on('mouseup', '.scroll-products-left,
.scroll-products-right', function(e){
clearTimeout(Dousset.product.currentInterval);
Dousset.product.currentInterval = null;
});
if((navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i))) {
$('#wrapper').on('click', '.scroll-products-right',
Dousset.product.scrollThumbsLeftBatch);
$('#wrapper').on('click', '.scroll-products-left',
Dousset.product.scrollThumbsRightBatch);
}
Dousset.product.setCurrentWindowWidthMin();
$(window).resize(Dousset.product.windowResized);
},
thumbClicked: function (e) {
e.preventDefault();
if (!$(this).hasClass('active')) {
var postId = $(this).data('post-id');
var newImg = $(this).data('image');
$('.main-image[data-post-id="'+postId+'"]').attr('src',
newImg);
$('.product-thumbnail[data-post-id="'+postId+'"]').removeClass('active');
$(this).addClass('active');
}
},
scrollThumbsLeft: function (e) {
var $inner =
$(this).siblings('.scrollable-area').find('.product-gallery-inner');
var maxMargin = $inner.width() -
$(this).siblings('.scrollable-area').width();
Dousset.product.currentInterval = setInterval(function(){
if (parseInt($inner.css('margin-left'),10) >= -maxMargin) {
$inner.css({
'margin-left' : '-=1'
});
}
},10);
},
scrollThumbsRight: function (e) {
var $inner =
$(this).siblings('.scrollable-area').find('.product-gallery-inner');
Dousset.product.currentInterval = setInterval(function(){
if (parseInt($inner.css('margin-left'),10) <= 0 ) {
$inner.css({
'margin-left' : '+=1'
});
}
},10);
},
scrollThumbsLeftBatch: function (e) {
var $inner =
$(this).siblings('.scrollable-area').find('.product-gallery-inner');
var maxMargin = $inner.width() -
$(this).siblings('.scrollable-area').width();
if (parseInt($inner.css('margin-left'),10) >= -maxMargin) {
$inner.animate({
'margin-left' : '-=70'
});
}
},
scrollThumbsRightBatch: function (e) {
var $inner =
$(this).siblings('.scrollable-area').find('.product-gallery-inner');
if (parseInt($inner.css('margin-left'),10) <= 0 ) {
$inner.animate({
'margin-left' : '+=70'
});
}
},
setCurrentWindowWidthMin: function () {
Dousset.product.currentWindowWidthMin = $( window ).width() >
979 ? 980 : $( window ).width() > 767 ? 768 : 480;
},
windowResized: function () {
var oldWinMin = Dousset.product.currentWindowWidthMin;
Dousset.product.setCurrentWindowWidthMin();
}
}
$(document).ready(function(){ Dousset.product.init(); });
Mongoid, how to keep relations in sync for common parent model?
Mongoid, how to keep relations in sync for common parent model?
I have three models:
Agency
has_many :owners
has_many :properties
Owner
belongs_to :agency
has_many :properties
Property
belongs_to :owner
belongs_to :agency
The agency.properties relation should refer to all properties that all
owners have, but when I create a property inside an owner, the
agency.properties relation is not created. I want this relation to be
automatically fulfilled, as well as deleted when the owner or the property
is deleted.
How can I achieve this behavior with mongoid?
I have three models:
Agency
has_many :owners
has_many :properties
Owner
belongs_to :agency
has_many :properties
Property
belongs_to :owner
belongs_to :agency
The agency.properties relation should refer to all properties that all
owners have, but when I create a property inside an owner, the
agency.properties relation is not created. I want this relation to be
automatically fulfilled, as well as deleted when the owner or the property
is deleted.
How can I achieve this behavior with mongoid?
Subscribe to:
Posts (Atom)