How to filter 'p' within an id of multiple id selection? - jquery-selectors

I'm trying to select multiple ids + an id that would select only paragraphs within that id
$('#big8,#divmenu,#workstext.has('p')').each(function(i) {
$(this).delay((i + 1) * 250).fadeIn(2000);
});
The error i get is: "Uncaught SyntaxError: missing ) after argument list"

Your problem is your code, the . in the $('') part means a class with the name that follows, also, you use ' in this too, escape it or use double quotes, namely: $("''"); or $('\'').
Your code should be more like this:
$('#big8, #divmenu, #workstext').has('p').each(function(i) {
$(this).delay((i + 1) * 250).fadeIn(2000);
});
OR
$("#big8, #divmenu, #workstext").has("p").each(function(i) {
$(this).delay((i + 1) * 250).fadeIn(2000);
});
EDIT
Try this:
$( "#big8, #divmenu" ).each( function ( i )
{
$( this ).delay(( i + 1 ) * 250 ).fadeIn( 2000 );
} );
$( "#workstext" ).has( "p" ).each( function ( i )
{
$( this ).delay(( i + 1 ) * 250 ).fadeIn( 2000 );
} );

Related

Salesforce Trigger - Prevent Parent Case Closure if Parent Case has open Child Cases

I have the following Apex trigger which should prevent a Parent Case from closing if the parent case has open child cases. Kindly assist with trouble shooting as the Apex Trigger is not firing.
trigger CaseTriggerCloseChild on Case ( before update ) {
Set < Id > setCaseIds = new Set < Id >();
Map < Id, Integer > mapOpenCaseCount = new Map < Id, Integer >();
for ( Case objCase : trigger.new ) {
if ( objCase.Status == 'Closed' ) {
setCaseIds.add( objCase.Id );
}
}
for ( Case objCase : [ SELECT ParentId FROM Case WHERE ParentId IN: setCaseIds AND IsClosed = false ] ) {
if ( mapOpenCaseCount.containsKey( objCase.ParentId ) ) {
mapOpenCaseCount.put( objCase.ParentId, mapOpenCaseCount.get( objCase.ParentId ) + 1 );
} else {
mapOpenCaseCount.put( objCase.ParentId, 1 );
}
}
for ( Case objCase : trigger.new ) {
if ( objCase.Status == 'Closed' ) {
if ( mapOpenCaseCount.containsKey( objCase.Id ) ) {
objCase.addError( 'You cannot close this Case. It has ' + mapOpenCaseCount.get( objCase.Id ) + ' open Child Cases.' );
}
}
}
}
Looks like your map of open cases is keyed on the parent ID and you are using the current case ID to look for open cases. You'll need to restructure it some.

How to use Create Command in yii2?

i want to create a new table and then insert value into it using create command. This is the code which i tried
if ( $model->save() )
{
$first_val = $model->num_start - 1;
$connection = \Yii::$app()->db;
$transaction = $connection->beginTransaction();
try
{
$q = "CREATE TABLE range_{$model->id}( id INT(11) NOT NULL AUTO_INCREMENT,PRIMARY KEY (id) ); " ;
$connection->createCommand($q)->execute(); // new table created
$transaction->commit();
if ( $model->num_start > 1 )
{
$r = "INSERT INTO range_{$model->id}( id ) VALUES ({$first_val});" ;
$connection->createCommand($r)->execute(); // new value inserted
$transaction->commit();
}
}
catch (Exception $e)
{
// react on exception
$transaction->rollback();
}
return $this->redirect( [ 'index' ] );
}
when i try to run this code i get an error Call to undefined method Yii::app() How can i use the create command in Yii2?
You have mixed both yii and yii2:
Use:
\Yii::$app->db;
Instead of
\Yii::$app()->db;

Filter information and custom repository with Symfony2?

From GET parameters, I want to get information from my entities.
In my view I created a form with 3 selects (not multiple ones), like this:
http://pix.toile-libre.org/upload/original/1393414663.png
If I filter only by user I got this in the url: ?category=0&user=6&status=0
I'll have to handle the 0 values...
This form used to filter my tasks.
This is a part of my action in my controller:
if($request->query->has('user')) {
$category_id = $request->query->get('category');
$user_id = $request->query->get('user');
$status_id = $request->query->get('status');
// A little test to see if it works.
echo $category_id . '<br>' . $user_id . '<br>' . $status_id;
// I will pass these variables to a repository
$tasks = $em->getRepository('LanCrmBundle:Task')->findFiltered($category_id, $user_id, $status_id);
} else {
$tasks = $em->getRepository('LanCrmBundle:Task')->findAll();
}
I create a repository with this method:
public function findFiltered($category_id, $user_id, $status_id)
{
/**
* Get filtered tasks.
*
* Get only title, priority, created_at, category_id, user_id and status_id fields (optimization)
*
* Where field category_id = $category_id unless $category_id is smaller than 1 (not secure enough)
* Where field user_id = $user_id unless $user_id is smaller than 1 (not secure enough)
* Where field status_id = $status_id unless $status_id is smaller than 1 (not secure enough)
* Should I do these tests here or in the controller?
*/
}
How to do this query ? Do you have any other elegant suggestions to solve this problem?
You can try:
public function findFiltered($category_id, $user_id, $status_id)
{
$queryBuilder = $this->createQueryBuilder('t');
if(!empty($category_id) && is_numeric($category_id)) {
$queryBuilder->andWhere('t.category = :category')->setParameter('category', $category_id);
}
if(!empty($user_id) && is_numeric($user_id)) {
$queryBuilder->andWhere('t.user = :user')->setParameter('user', $user_id);
}
if(!empty($status_id) && is_numeric($status_id)) {
$queryBuilder->andWhere('t.status = :status')->setParameter('status', $status_id);
}
return $queryBuilder->getQuery()->getResult();
}

Nodejs TCP socket, when ending, does not contain remoteAddress information

I am building a simple echo server for the purposes of learning the fundamentals about building tcp services with node.js and figuring out what information is available.
When I am creating a server, as shown below, I can access information about the incomingSocket such as the remote address. Why is it that I cannot access the information on the closing of socket? Below is my code; my comment indicates the output I have received.
var net = require ( 'net' );
var server = net.createServer (
function ( incomingSocket )
{
//'connection' listener
console.log ( 'Connection from ' + incomingSocket.remoteAddress + ':' + incomingSocket.remotePort + " established." );
incomingSocket.on (
'data' ,
function ( data )
{
// The incomingSocket.remoteAddress is defined here
console.log ( incomingSocket.remoteAddress + ':' + incomingSocket.remotePort + ' -> ' + data.toString () );
}
);
incomingSocket.on (
'close' ,
function ()
{
// The incomingSocket.remoteAddress is undefined here
console.log ( 'connection from ' + incomingSocket.remoteAddress + ' closed.' );
}
);
incomingSocket.pipe ( incomingSocket );
}
);
// listening to a port happens here
I would appreciate any response! Thank you!
Well no, because when it gets in the event handler for the socket close event, the socket object no longer exists. If you need to display the remote address of the client as the socket is closing, simply store the remote address as the client initially connects.
var clients = new Array();
net.createServer(function(socket) {
var remoteAddress = socket.remoteAddress;
var remotePort = socket.remotePort;
// Add to array of clients
clients.push(remoteAddress + ':' + remotePort);
console.log('Connection from ' + remoteAddress + ':' + remotePort + " established.");
socket.on('data', function(data) {
console.log(remoteAddress + ':' + remotePort + ' -> ' + data.toString());
});
socket.on('close', function() {
// Remove from array of clients
clients.splice(clients.indexOf(remoteAddress + ':' + remotePort), 1);
console.log('Connection from ' + remoteAddress + ':' + remotePort + ' closed.');
});
...

Jquery-ui sortable doesn't work on touch devices based on Android or IOS

Is there any fix to make Jquery-ui sortable work on touch devices based on Android or IOS?
I suggest jQuery UI Touch Punch. I've tested it on iOS 5 and Android 2.3 and it works great on both.
The other answer is great but unfortunately it will only work on iOS devices.
Also there was is a breakage caused by later versions of jquery.ui that meant that _touchEnd events were not correctly resetting an internal flag (mouseHandled) in mouse.ui and this was causing exceptions.
Both of these problems should now be fixed with this code.
/*
* Content-Type:text/javascript
*
* A bridge between iPad and iPhone touch events and jquery draggable,
* sortable etc. mouse interactions.
* #author Oleg Slobodskoi
*
* modified by John Hardy to use with any touch device
* fixed breakage caused by jquery.ui so that mouseHandled internal flag is reset
* before each touchStart event
*
*/
(function( $ ) {
$.support.touch = typeof Touch === 'object';
if (!$.support.touch) {
return;
}
var proto = $.ui.mouse.prototype,
_mouseInit = proto._mouseInit;
$.extend( proto, {
_mouseInit: function() {
this.element
.bind( "touchstart." + this.widgetName, $.proxy( this, "_touchStart" ) );
_mouseInit.apply( this, arguments );
},
_touchStart: function( event ) {
if ( event.originalEvent.targetTouches.length != 1 ) {
return false;
}
this.element
.bind( "touchmove." + this.widgetName, $.proxy( this, "_touchMove" ) )
.bind( "touchend." + this.widgetName, $.proxy( this, "_touchEnd" ) );
this._modifyEvent( event );
$( document ).trigger($.Event("mouseup")); //reset mouseHandled flag in ui.mouse
this._mouseDown( event );
return false;
},
_touchMove: function( event ) {
this._modifyEvent( event );
this._mouseMove( event );
},
_touchEnd: function( event ) {
this.element
.unbind( "touchmove." + this.widgetName )
.unbind( "touchend." + this.widgetName );
this._mouseUp( event );
},
_modifyEvent: function( event ) {
event.which = 1;
var target = event.originalEvent.targetTouches[0];
event.pageX = target.clientX;
event.pageY = target.clientY;
}
});
})( jQuery );
is this meant to replace the mouse.ui js code or to be called after that javascript is loaded? I am unable to get it to work for me on an Android tablet.
EDIT for anyone finding this in the future - got this to work for a Samsung Galaxy Android tablet with the following code:
/iPad|iPhone|Android/.test( navigator.userAgent ) && (function( $ ) {
var proto = $.ui.mouse.prototype,
_mouseInit = proto._mouseInit;
$.extend( proto, {
_mouseInit: function() {
this.element
.bind( "touchstart." + this.widgetName, $.proxy( this, "_touchStart" ) );
_mouseInit.apply( this, arguments );
},
_touchStart: function( event ) {
/* if ( event.originalEvent.targetTouches.length != 1 ) {
return false;
} */
this.element
.bind( "touchmove." + this.widgetName, $.proxy( this, "_touchMove" ) )
.bind( "touchend." + this.widgetName, $.proxy( this, "_touchEnd" ) );
this._modifyEvent( event );
$( document ).trigger($.Event("mouseup")); //reset mouseHandled flag in ui.mouse
this._mouseDown( event );
//return false;
},
_touchMove: function( event ) {
this._modifyEvent( event );
this._mouseMove( event );
},
_touchEnd: function( event ) {
this.element
.unbind( "touchmove." + this.widgetName )
.unbind( "touchend." + this.widgetName );
this._mouseUp( event );
},
_modifyEvent: function( event ) {
event.which = 1;
var target = event.originalEvent.targetTouches[0];
event.pageX = target.clientX;
event.pageY = target.clientY;
}
});
})( jQuery );
I finally found a solution that works with drag handles.
Go to this page.
In Downloads, grab the "altfix" version, which only applies touch handling to the elements you specify.
Add a script tag for the downloaded JS file.
Add touch handling for your drag handles in your document ready handler; e.g. $('.handle').addTouch()
I'm using this snippet below in conjunction with jquery-sortable which does allow the drag sort to happen on my iPhone. I am having a problem after I finish the first sort however as any scrolling on the list at all is detected as a drag.
EDIT - see here as well http://bugs.jqueryui.com/ticket/4143
EDIT 2 - I was able to get this working if I use the entire row as the handle. It also fixed a problem I was having where the offset was incorrect after scrolling.
/*
* A bridge between iPad and iPhone touch events and jquery draggable, sortable etc. mouse interactions.
* #author Oleg Slobodskoi
*/
/iPad|iPhone/.test( navigator.userAgent ) && (function( $ ) {
var proto = $.ui.mouse.prototype,
_mouseInit = proto._mouseInit;
$.extend( proto, {
_mouseInit: function() {
this.element
.bind( "touchstart." + this.widgetName, $.proxy( this, "_touchStart" ) );
_mouseInit.apply( this, arguments );
},
_touchStart: function( event ) {
if ( event.originalEvent.targetTouches.length != 1 ) {
return false;
}
this.element
.bind( "touchmove." + this.widgetName, $.proxy( this, "_touchMove" ) )
.bind( "touchend." + this.widgetName, $.proxy( this, "_touchEnd" ) );
this._modifyEvent( event );
this._mouseDown( event );
return false;
},
_touchMove: function( event ) {
this._modifyEvent( event );
this._mouseMove( event );
},
_touchEnd: function( event ) {
this.element
.unbind( "touchmove." + this.widgetName )
.unbind( "touchend." + this.widgetName );
this._mouseUp( event );
},
_modifyEvent: function( event ) {
event.which = 1;
var target = event.originalEvent.targetTouches[0];
event.pageX = target.clientX;
event.pageY = target.clientY;
}
});
})( jQuery );
This worked a lot better for me than the selected answer, so I hope this helps other people:
http://code.google.com/p/rsslounge/source/browse/trunk/public/javascript/addtouch.js?r=115.
The other code behaves weird, when you drag an element the potential dropping position is very far from were it should be.
Using Touch Punch is as easy as 1, 2…
Just follow these simple steps to enable touch events in your jQuery UI app:
Include jQuery and jQuery UI on your page.
Include Touch Punch after jQuery UI and before its first use.
Please note that if you are using jQuery UI's components, Touch Punch must be included after jquery.ui.mouse.js, as Touch Punch modifies its behavior.
There is no 3. Just use jQuery UI as expected and watch it work at the touch of a finger.
$('#widget').draggable();
Tested on iPad, iPhone, Android and other touch-enabled mobile devices.