first import
This commit is contained in:
339
sites/all/modules/draggableviews/LICENSE.txt
Normal file
339
sites/all/modules/draggableviews/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
60
sites/all/modules/draggableviews/README.txt
Normal file
60
sites/all/modules/draggableviews/README.txt
Normal file
@@ -0,0 +1,60 @@
|
||||
DraggableViews
|
||||
==============
|
||||
|
||||
This module provides dragging entities and saving their order.
|
||||
|
||||
Quick install:
|
||||
1) Activate Draggableviews module at admin/modules
|
||||
2) Navigate to view edit-page, click on the first link at the Format section and then choose style "table".
|
||||
3) Click Add button at the "Fields" section and choose field "Content:title", add and apply.
|
||||
4) Click Add button at the "Fields" section and choose field "Content:Draggable views (Draggable views)", add and apply.
|
||||
5) Click Add button at the "Sort criteria" section and choose field "Content:Draggable views weight", add and choose sort asc, then apply.
|
||||
6) Save the view and you're done.
|
||||
|
||||
In the case of table standard drupal tabledrag.js javascript is used.
|
||||
|
||||
We also support jQuery UI Sortable javascript. In order to use it please set display style HTML List.
|
||||
By default HTML list is displayed like grid. If you would like it to be displayed as list override
|
||||
CSS styles for example in following way:
|
||||
.draggableviews-processed li.views-row { float: none; width: 100%; margin-left: 0; }
|
||||
|
||||
One view/display to set order another to display
|
||||
================================================
|
||||
|
||||
You can create one view to set the order and another view to display the order. Or even
|
||||
create one view with two separate displays. In a view that displays the order there
|
||||
should be no draggableviews field (that makes view sortable), then in the settings of
|
||||
the "draggableviews weight" sorting criteria there will be selectbox "Display sort as"
|
||||
where you can choose the source view of your weights. This is applicable when you use
|
||||
Native handler.
|
||||
|
||||
Permissions
|
||||
===========
|
||||
|
||||
Please add "Access draggable views" permission to users who should be able to reorder views.
|
||||
|
||||
Arguments handling
|
||||
==================
|
||||
|
||||
Every time we save the order of a view, current set of arguments are saved with order.
|
||||
You can see this in draggableviews_structure table "args" column. By default when we display order we use all
|
||||
currently passed arguments to a view to "match" arguments in "args" column. This means that we can create
|
||||
a view with contextual filter or exposed filter criteria and save different orders for different sets of arguments.
|
||||
|
||||
We can also completely ignore passed arguments using "Do not use any arguments (use empty arguments)" option
|
||||
in Arguments handling of Sort criteria Draggable views weight. Be aware that in this case empty arguments set
|
||||
will be used. So you can set order for a view when no arguments passed and then whatever arguments passed,
|
||||
empty set will be used.
|
||||
|
||||
Prepare arguments with PHP code is an option when you would like to alter arguments before they passed to
|
||||
"matching" with "args" column. For us this means that we can create for example several exposed filters,
|
||||
but pass values of only one of values of exposed filters instead of all of them (like we create two exposed
|
||||
filters: author and node type, but take into account for ordering only node type).
|
||||
Please be aware that in PHP code arguments are passed as $arguments variable and you should return array.
|
||||
Contextual filters are number keyed and exposed filters are name keyed.
|
||||
|
||||
Contextual link "Order view"
|
||||
============================
|
||||
|
||||
If there is view with sort order draggableviews weight and the order is set by another view we show "Order view"
|
||||
contextual link for opening a view that sets the order.
|
24
sites/all/modules/draggableviews/css/draggableviews_list.css
Normal file
24
sites/all/modules/draggableviews/css/draggableviews_list.css
Normal file
@@ -0,0 +1,24 @@
|
||||
.draggableviews-processed {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.draggableviews-processed li.views-row {
|
||||
display: block;
|
||||
float: left;
|
||||
width: 180px;
|
||||
/* height: 180px; if required for fixed height displays */
|
||||
margin: 10px;
|
||||
padding: 5px;
|
||||
cursor:move;
|
||||
}
|
||||
|
||||
.draggableviews-processed li.views-row.ui-sortable-helper {
|
||||
border: 1px dotted blue;
|
||||
}
|
||||
.draggableviews-processed li.views-row {
|
||||
border: 1px dotted grey;
|
||||
}
|
||||
|
||||
.draggableviews-weight{
|
||||
display:none;
|
||||
}
|
24
sites/all/modules/draggableviews/draggableviews.api.php
Normal file
24
sites/all/modules/draggableviews/draggableviews.api.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks provided by the Draggableviews module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* If Native handler used, you can alter arguments set before saved to database.
|
||||
*
|
||||
* This can be used when you would like to exclude or add some of arguments
|
||||
* to be recorded to database. Also you can add new records to be saved to
|
||||
* database (for example for translated nodes, etc.)
|
||||
*
|
||||
* @see http://drupal.org/node/1463596#comment-5687620
|
||||
*
|
||||
* @param array $arguments
|
||||
* Array of arguments before saving.
|
||||
* @param array $form_values
|
||||
* Array of submitted entity ids and weights.
|
||||
* @param object $view
|
||||
* Views object.
|
||||
*/
|
||||
function hook_draggableviews_handler_native_arguments_alter(&$arguments, $view, &$form_values) {}
|
22
sites/all/modules/draggableviews/draggableviews.info
Normal file
22
sites/all/modules/draggableviews/draggableviews.info
Normal file
@@ -0,0 +1,22 @@
|
||||
name = Draggableviews
|
||||
description = Makes Views draggable
|
||||
dependencies[] = views
|
||||
package = Views
|
||||
core = 7.x
|
||||
|
||||
files[] = handlers/draggableviews_handler.inc
|
||||
files[] = handlers/draggableviews_handler_native.inc
|
||||
files[] = handlers/draggableviews_handler_fieldapi.inc
|
||||
files[] = views/draggableviews_handler_field_draggable.inc
|
||||
files[] = views/draggableviews_handler_sort.inc
|
||||
files[] = views/draggableviews_join_handler.inc
|
||||
files[] = test/draggableviews.test
|
||||
|
||||
dependencies[] = entity
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-04-02
|
||||
version = "7.x-2.0-beta1"
|
||||
core = "7.x"
|
||||
project = "draggableviews"
|
||||
datestamp = "1333351548"
|
||||
|
87
sites/all/modules/draggableviews/draggableviews.install
Normal file
87
sites/all/modules/draggableviews/draggableviews.install
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Draggableviews defines a new database schema
|
||||
* for saving the order.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function draggableviews_schema() {
|
||||
$schema['draggableviews_structure'] = array(
|
||||
'description' => 'The table saves the order settings of an draggableview.',
|
||||
'fields' => array(
|
||||
'dvid' => array(
|
||||
'description' => 'The primary identifier.',
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'view_name' => array(
|
||||
'description' => 'Makes the order unique for each view.',
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'view_display' => array(
|
||||
'description' => 'Makes the order unique for each view display.',
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'args' => array(
|
||||
'description' => 'Makes the order unique for a given set of arguments',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
),
|
||||
'entity_id' => array(
|
||||
'description' => 'Id of the entity that we are sorting (node, user, etc.).',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'weight' => array(
|
||||
'description' => 'The order weight.',
|
||||
'type' => 'int',
|
||||
'unsigned' => FALSE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
),
|
||||
'unique keys' => array(
|
||||
'dvid' => array('dvid'),
|
||||
),
|
||||
'primary key' => array('dvid'),
|
||||
);
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase sizes of view_name and view_display fields of
|
||||
* draggableviews_strucutre table.
|
||||
*/
|
||||
function draggableviews_update_7001() {
|
||||
$new_field = array(
|
||||
'description' => 'Makes the order unique for each view.',
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
);
|
||||
db_change_field('draggableviews_structure', 'view_name', 'view_name', $new_field);
|
||||
|
||||
$new_field = array(
|
||||
'description' => 'Makes the order unique for each view display.',
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
);
|
||||
db_change_field('draggableviews_structure', 'view_display', 'view_display', $new_field);
|
||||
}
|
323
sites/all/modules/draggableviews/draggableviews.module
Normal file
323
sites/all/modules/draggableviews/draggableviews.module
Normal file
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function draggableviews_views_api() {
|
||||
return array(
|
||||
'api' => 3,
|
||||
'path' => drupal_get_path('module', 'draggableviews') . '/views',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*
|
||||
* Alter views form to change button label.
|
||||
*/
|
||||
function draggableviews_form_alter(&$form, &$form_state, $form_id) {
|
||||
if (isset($form['draggableviews']) && !empty($form['draggableviews'])) {
|
||||
// Check permissions.
|
||||
if (!user_access('access draggableviews')) {
|
||||
$form['actions']['submit']['#access'] = FALSE;
|
||||
return;
|
||||
}
|
||||
$view = $form_state['build_info']['args'][0];
|
||||
$options = $view->field['draggableviews']->options['draggableviews'];
|
||||
$form['actions']['submit']['#value'] = t($options['save_button_label']);
|
||||
$form['actions']['submit']['#submit'] = array('draggableviews_views_submit');
|
||||
|
||||
if ($options['ajax']) {
|
||||
$form['actions']['submit']['#ajax'] = array(
|
||||
'callback' => 'draggableviews_view_draggabletable_form_ajax'
|
||||
);
|
||||
}
|
||||
// Set action as current path.
|
||||
|
||||
global $language;
|
||||
$lang_code = $language->language;
|
||||
|
||||
$my_base_path = base_path();
|
||||
|
||||
if ($lang_code != 'en') {
|
||||
$my_base_path .= $lang_code . '/';
|
||||
}
|
||||
$form['#action'] = $my_base_path . current_path();
|
||||
|
||||
// $form['#action'] = base_path() . current_path();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save weight records after form submit.
|
||||
*/
|
||||
function draggableviews_views_submit($form, &$form_state) {
|
||||
$view = $form_state['build_info']['args'][0];
|
||||
|
||||
// Use 'input' instead of mapped 'values' here. This is done because if in
|
||||
// table display we sort by header then set weights and save, we got
|
||||
// totally wrong results ($form_state['values']['draggableviews'] mapped
|
||||
// wrong from $form_state['input']['draggableviews'])
|
||||
$form_state['values']['draggableviews'] = $form_state['input']['draggableviews'];
|
||||
|
||||
// Set the weight.
|
||||
$handler_object = draggableviews_get_handler_class($view->field['draggableviews']->options['draggableviews']['handler']);
|
||||
$handler_object->set($form_state);
|
||||
|
||||
// Trigger the event "A view has been sorted"
|
||||
if (module_exists('rules')) {
|
||||
rules_invoke_event('draggableviews_rules_event_sorted', $view->name, $view->current_display);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementes hook_preprocess_views_view_table().
|
||||
*/
|
||||
function draggableviews_preprocess_views_view_table(&$vars) {
|
||||
// Check whether this table view has draggableview field.
|
||||
if (!isset($vars['view']->field['draggableviews'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check permissions.
|
||||
if (!user_access('access draggableviews')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add table class.
|
||||
$vars['classes_array'][] = 'draggable';
|
||||
|
||||
// Add row class.
|
||||
foreach ($vars['row_classes'] as &$row_classes) {
|
||||
$row_classes[] = 'draggable';
|
||||
}
|
||||
|
||||
$vars['attributes_array']['id'] = 'draggableviews-table-' . $vars['view']->name . '-' . $vars['view']->current_display;
|
||||
// Add javascript.
|
||||
drupal_add_tabledrag($vars['attributes_array']['id'], 'order', 'sibling', 'draggableviews-weight');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementes hook_preprocess_views_view_list().
|
||||
*/
|
||||
function draggableviews_preprocess_views_view_list(&$vars) {
|
||||
// Check whether this table view has draggableview field.
|
||||
if (!isset($vars['view']->field['draggableviews'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check permissions.
|
||||
if (!user_access('access draggableviews')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add class to ul item of the view.
|
||||
$class = 'draggableviews-grid-' . $vars['view']->name . '-' . $vars['view']->current_display;
|
||||
$vars['list_type_prefix'] = str_replace('>', ' class="' . $class . '">', $vars['list_type_prefix']);
|
||||
// Add javascript.
|
||||
drupal_add_library('system', 'ui.sortable');
|
||||
// Add setting of the row class.
|
||||
$js_setting = array('draggableviews_row_class' => $class);
|
||||
// Add setting whether ajax enabled or not.
|
||||
$js_setting['draggableviews_ajax'] = $vars['view']->field['draggableviews']->options['draggableviews']['ajax'];
|
||||
drupal_add_js($js_setting, 'setting');
|
||||
// Add custom js and css.
|
||||
drupal_add_js(drupal_get_path('module', 'draggableviews') . '/js/draggableviews_list.js');
|
||||
drupal_add_css(drupal_get_path('module', 'draggableviews') . '/css/draggableviews_list.css');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function draggableviews_permission() {
|
||||
return array(
|
||||
'access draggableviews' => array(
|
||||
'title' => t('Access draggable views'),
|
||||
'description' => t('Give users the right to sort their views'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_plugin_type().
|
||||
*/
|
||||
function draggableviews_ctools_plugin_type() {
|
||||
return array(
|
||||
'handler' => array(
|
||||
'use hooks' => FALSE,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_plugin_directory().
|
||||
*/
|
||||
function draggableviews_ctools_plugin_directory($module, $plugin) {
|
||||
if (($module == 'draggableviews') && ($plugin == 'handler')) {
|
||||
return 'handlers';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_contextual_links_view_alter().
|
||||
*
|
||||
* Adds "Order view" contextual link.
|
||||
*/
|
||||
function draggableviews_contextual_links_view_alter(&$element, $items) {
|
||||
// Check permission to use draggable.
|
||||
if (!user_access('access draggableviews')) {
|
||||
return;
|
||||
}
|
||||
// Do not add contextual link on view preview.
|
||||
if (module_exists('views_ui') && views_ui_contextual_links_suppress()) {
|
||||
return;
|
||||
}
|
||||
// Add Draggableviews contextual link "Order view".
|
||||
if ( isset($element['#element']['#views_contextual_links_info']['views_ui']['view_display_id'])
|
||||
&& !empty($element['#element']['#views_contextual_links_info']['views_ui']['view_display_id'])
|
||||
&& isset($element['#element']['#views_contextual_links_info']['views_ui']['view'])) {
|
||||
$display_id = $element['#element']['#views_contextual_links_info']['views_ui']['view_display_id'];
|
||||
$view = $element['#element']['#views_contextual_links_info']['views_ui']['view'];
|
||||
$view->build($display_id);
|
||||
|
||||
// Proceed only if there is draggableviews weight sort criteria available.
|
||||
if (!$sort_key = draggable_views_get_draggable_sort($view)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Proceed only if order view is no self.
|
||||
$order_view_display = $view->sort[$sort_key]->options['draggableviews_setting_view'];
|
||||
if (empty($order_view_display) || $order_view_display == 'self') {
|
||||
return;
|
||||
}
|
||||
list($order_view_name, $order_view_display_id) = explode(':', $order_view_display);
|
||||
// Load order view and check its path.
|
||||
$order_view = views_get_view($order_view_name);
|
||||
if (isset($order_view->display[$order_view_display_id]->display_options['path'])) {
|
||||
$path = $order_view->display[$order_view_display_id]->display_options['path'];
|
||||
// If page expects arguments, we provide arguments set to current view.
|
||||
if (strpos($path, '%') !== FALSE && !empty($view->args)) {
|
||||
$placeholders = array();
|
||||
foreach (explode('/', $path) as $path_part) {
|
||||
if (strpos($path_part, '%') !== FALSE) {
|
||||
$placeholders[] = $path_part;
|
||||
}
|
||||
}
|
||||
$path = str_replace($placeholders, $view->args, $path);
|
||||
}
|
||||
$element['#links']['draggableviews-order'] = array(
|
||||
'title' => t('Order view'),
|
||||
'href' => $path,
|
||||
'query' => array('destination' => current_path()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_post_execute().
|
||||
*/
|
||||
function draggableviews_views_post_execute(&$view) {
|
||||
if (isset($view->field['draggableviews'])) {
|
||||
// Remove 'draggable' field if user has no access to sort a view.
|
||||
if (!user_access('access draggableviews')) {
|
||||
unset($view->field['draggableviews']);
|
||||
}
|
||||
else {
|
||||
// Move draggableviews field to last column
|
||||
// otherwise tabledrag.js doesn't work.
|
||||
$draggable_field = $view->field['draggableviews'];
|
||||
unset($view->field['draggableviews']);
|
||||
$view->field['draggableviews'] = $draggable_field;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class of handler.
|
||||
*
|
||||
* @param object
|
||||
* Handler's class object.
|
||||
*/
|
||||
function draggableviews_get_handler_class($handler_name) {
|
||||
$objects = &drupal_static(__FUNCTION__);
|
||||
if (!isset($objects[$handler_name])) {
|
||||
ctools_include('plugins');
|
||||
if ($class = ctools_plugin_load_class('draggableviews', 'handler', $handler_name, 'handler')) {
|
||||
$objects[$handler_name] = new $class();
|
||||
}
|
||||
}
|
||||
|
||||
return $objects[$handler_name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all plugins.
|
||||
*
|
||||
* Check whether handler class inherits draggablevies_handler.
|
||||
*
|
||||
* @return array
|
||||
* Array of proper draggableviews handlers.
|
||||
*/
|
||||
function draggableviews_get_handlers() {
|
||||
ctools_include('plugins');
|
||||
$handlers = ctools_get_plugins('draggableviews', 'handler');
|
||||
$return = array();
|
||||
foreach ($handlers as $handler_id => $handler) {
|
||||
$handler_object = draggableviews_get_handler_class($handler_id);
|
||||
if (in_array('draggableviews_handler', class_parents(get_class($handler_object)))) {
|
||||
$return[$handler_id] = $handler_object;
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax draggabletable submit handler.
|
||||
*/
|
||||
function draggableviews_view_draggabletable_form_ajax($form, $form_state) {
|
||||
// Find the form element
|
||||
$form_element = "form:has(input[name=form_build_id][value='{$form['form_build_id']['#value']}'])";
|
||||
|
||||
// Remove warning and asterisk.
|
||||
return array('#type' => 'ajax', '#commands' => array(
|
||||
ajax_command_remove("$form_element div.tabledrag-changed-warning"),
|
||||
ajax_command_remove("$form_element span.tabledrag-changed"),
|
||||
ajax_command_remove("$form_element div.draggableviews-changed-warning"),
|
||||
ajax_command_invoke("$form_element ul.draggableviews-changed", 'removeClass', array('draggableviews-changed')),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the draggable views weight sort of a view if there is one and return its
|
||||
* ID. If there are multiple of these sorts the first is returned.
|
||||
*
|
||||
* @param $view
|
||||
* The view object.
|
||||
*
|
||||
* @return
|
||||
* The ID of the sort or FALSE if there isn't one.
|
||||
*/
|
||||
function draggable_views_get_draggable_sort($view) {
|
||||
foreach ($view->sort as $id => $sort) {
|
||||
if ($sort->definition['handler'] == 'draggableviews_handler_sort') {
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evalutes the given PHP code, with the given variables defined.
|
||||
*
|
||||
* @param $code
|
||||
* The PHP code to run, without <?php ?>
|
||||
* @param $arguments
|
||||
* Views arguments including values of exposed filters.
|
||||
*
|
||||
* @return
|
||||
* The return value of the evaled code.
|
||||
*/
|
||||
function draggableviews_eval_return($code, $arguments) {
|
||||
return eval($code);
|
||||
}
|
30
sites/all/modules/draggableviews/draggableviews.rules.inc
Normal file
30
sites/all/modules/draggableviews/draggableviews.rules.inc
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Rules hooks implementation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_rules_event_info().
|
||||
*/
|
||||
function draggableviews_rules_event_info() {
|
||||
$events = array();
|
||||
|
||||
$events['draggableviews_rules_event_sorted'] = array(
|
||||
'label' => t('A view has been sorted'),
|
||||
'group' => t('DraggableViews'),
|
||||
'variables' => array(
|
||||
'view_name' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('view name'),
|
||||
),
|
||||
'display_name' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('view current display name'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $events;
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Base plugin implementation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parent class for all handlers.
|
||||
*/
|
||||
class draggableviews_handler {
|
||||
|
||||
/**
|
||||
* Get the weight value.
|
||||
*
|
||||
* @param object $field
|
||||
* Draggableviews field handler. View is $field->view,
|
||||
* to get a row $field->view->result[$index].
|
||||
* @param int $index
|
||||
* Index of the row.
|
||||
*
|
||||
* @return int
|
||||
* Weight value.
|
||||
*/
|
||||
public function get($field, $index) {}
|
||||
|
||||
/**
|
||||
* Save weight value.
|
||||
*
|
||||
* @param $form_state
|
||||
* Attay of form state of the form.
|
||||
* View object $form_state['values']['view'].
|
||||
*/
|
||||
public function set($form_state) {}
|
||||
|
||||
/**
|
||||
* Form with settings of the handler.
|
||||
*
|
||||
* @param object $field
|
||||
* Draggableviews field handler.
|
||||
*
|
||||
* @return array
|
||||
* Form array.
|
||||
*/
|
||||
public function options_form($field) {}
|
||||
|
||||
/**
|
||||
* Settings form default values.
|
||||
*
|
||||
* @return array
|
||||
* Array with default values.
|
||||
*/
|
||||
public function option_definition() {}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Field API handler plugin.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'label' => 'FieldAPI',
|
||||
'handler' => array(
|
||||
'class' => 'draggableviews_handler_fieldapi',
|
||||
),
|
||||
);
|
||||
|
||||
class draggableviews_handler_fieldapi extends draggableviews_handler {
|
||||
/**
|
||||
* Set default value of field option.
|
||||
*/
|
||||
public function option_definition() {
|
||||
return array('field' => '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add field options for handler.
|
||||
*/
|
||||
function options_form($field) {
|
||||
$form = array();
|
||||
$options = array('' => t('- Select -'));
|
||||
|
||||
// Check all the sortings added to a view. Hope there is
|
||||
// better way to determine them. Need to research.
|
||||
foreach ($field->view->display_handler->display->display_options['sorts'] as $sort_option) {
|
||||
$field_name = $sort_option['field'];
|
||||
// Field should be like "field_name_value".
|
||||
if (strpos($field_name, 'field_') === FALSE || strpos($field_name, '_value') === FALSE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove "_value" from field name and try to load the field.
|
||||
$field_name = drupal_substr($field_name, 0, drupal_strlen($field_name) - 6);
|
||||
if ($field_info = field_info_field($field_name)) {
|
||||
if ($field_info['type'] == 'number_integer') {
|
||||
$views_field_data = field_views_field_default_views_data($field_info);
|
||||
$options[$sort_option['table'] . ':' . $sort_option['field']] = filter_xss($views_field_data[$sort_option['table']][$sort_option['field']]['title']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If options are emtpy, show warning message.
|
||||
if (count($options) == 1) {
|
||||
$form['field_warning'] = array(
|
||||
'#markup' => '<div class="messages warning">' . t('Add weight integer field to sorts so it can be selected.') . '</div>',
|
||||
);
|
||||
}
|
||||
|
||||
$form['field'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Field'),
|
||||
'#options' => $options,
|
||||
'#default_value' => $field->options['draggableviews']['draggableviews_handler_fieldapi']['field'],
|
||||
'#description' => t('Please select field that contains weight. It should be integer type and already added to sorts of the view.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function get($field, $index) {
|
||||
// Get the name of selected field.
|
||||
$field_option = $field->options['draggableviews']['draggableviews_handler_fieldapi']['field'];
|
||||
list($field_table, $field_name) = explode(':', $field_option);
|
||||
// Current row.
|
||||
$row = $field->view->result[$index];
|
||||
// Check whether key has table name and field name in it.
|
||||
foreach ($row as $key => $value) {
|
||||
if (strpos($key, $field_table) !== FALSE && strpos($key, $field_name) !== FALSE) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function set($form_state) {
|
||||
$fv = $form_state['values'];
|
||||
$view = $form_state['build_info']['args'][0];
|
||||
$view_name = $view->name;
|
||||
$view_display = $view->current_display;
|
||||
// View arguments.
|
||||
$arguments = $view->args;
|
||||
if (isset($view->exposed_raw_input)) {
|
||||
$arguments += $view->exposed_raw_input;
|
||||
ksort($arguments);
|
||||
// Redirect view to the same page with exposed filters set.
|
||||
$form_state['redirect'] = array(current_path(), array('query' => $view->exposed_raw_input));
|
||||
}
|
||||
|
||||
$base_table = $view->base_table;
|
||||
$entity_info_all = entity_get_info();
|
||||
$entity_type = '';
|
||||
foreach ($entity_info_all as $entity_name_key => $entity_info) {
|
||||
if ($entity_info['base table'] == $view->base_table) {
|
||||
$entity_type = $entity_name_key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$options_field = $view->field['draggableviews']->options['draggableviews']['draggableviews_handler_fieldapi']['field'];
|
||||
list($field_tabe, $field_column) = explode(':', $options_field);
|
||||
// Remove '_value' from column name to get field name.
|
||||
$field_name = drupal_substr($field_column, 0, drupal_strlen($field_column) - 6);
|
||||
|
||||
// Save the values of the field.
|
||||
foreach ($fv['draggableviews'] as $item) {
|
||||
$entity_wrapper = entity_metadata_wrapper($entity_type, $item['id']);
|
||||
$entity_wrapper->{$field_name}->set($item['weight']);
|
||||
$entity_wrapper->save();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Native handler plugin.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'label' => 'Native',
|
||||
'handler' => array(
|
||||
'class' => 'draggableviews_handler_native',
|
||||
),
|
||||
);
|
||||
|
||||
class draggableviews_handler_native extends draggableviews_handler {
|
||||
public function get($field, $index) {
|
||||
$row = $field->view->result[$index];
|
||||
return (isset($row->draggableviews_structure_weight)) ? $row->draggableviews_structure_weight : 0;
|
||||
}
|
||||
|
||||
function set($form_state) {
|
||||
$fv = $form_state['values'];
|
||||
$view = $form_state['build_info']['args'][0];
|
||||
$view_name = $view->name;
|
||||
$view_display = $view->current_display;
|
||||
// View arguments.
|
||||
$arguments = $view->args;
|
||||
if (isset($view->exposed_raw_input)) {
|
||||
$arguments += $view->exposed_raw_input;
|
||||
ksort($arguments);
|
||||
// Redirect view to the same page with exposed filters set.
|
||||
$form_state['redirect'] = array(current_path(), array('query' => $view->exposed_raw_input));
|
||||
}
|
||||
|
||||
// Give other modules a chance to alter saved arguments.
|
||||
drupal_alter('draggableviews_handler_native_arguments', $arguments, $view, $fv['draggableviews']);
|
||||
|
||||
$args_string = json_encode($arguments);
|
||||
|
||||
// Save records to our custom table.
|
||||
foreach ($fv['draggableviews'] as $item) {
|
||||
// Delete previous order record.
|
||||
db_delete('draggableviews_structure')
|
||||
->condition('view_name', $view_name)
|
||||
->condition('view_display', $view_display)
|
||||
->condition('args', $args_string)
|
||||
->condition('entity_id', $item['id'])
|
||||
->execute();
|
||||
|
||||
// Create new order record.
|
||||
$record = array(
|
||||
'view_name' => $view_name,
|
||||
'view_display' => $view_display,
|
||||
'args' => $args_string,
|
||||
'entity_id' => $item['id'],
|
||||
'weight' => $item['weight'],
|
||||
);
|
||||
drupal_write_record('draggableviews_structure', $record);
|
||||
}
|
||||
}
|
||||
}
|
45
sites/all/modules/draggableviews/js/draggableviews_list.js
Normal file
45
sites/all/modules/draggableviews/js/draggableviews_list.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @file
|
||||
* Adds draggable functionality to the html list display of the view.
|
||||
*/
|
||||
|
||||
(function ($) {
|
||||
Drupal.behaviors.draggableViews = {
|
||||
attach: function (context, settings) {
|
||||
$('.views-form .' + Drupal.settings.draggableviews_row_class + ':not(.draggableviews-processed)', context)
|
||||
// Add class for theming.
|
||||
.addClass('draggableviews-processed')
|
||||
// Add sortable effect.
|
||||
.sortable({
|
||||
update: function(event, ui) {
|
||||
$( ".draggableviews-weight" ).each(function (i, Val) {
|
||||
$(this).val(i);
|
||||
});
|
||||
if (!$(this).hasClass('draggableviews-changed')) {
|
||||
// If view is not ajaxified.
|
||||
if (!Drupal.settings.draggableviews_ajax) {
|
||||
$('<div class="draggableviews-changed-warning messages warning">' + Drupal.t('Changes made in this list will not be saved until the form is submitted.') + '</div>')
|
||||
.insertBefore($(this).parents('form div.item-list')).hide().fadeIn('slow');
|
||||
$(this).addClass('draggableviews-changed');
|
||||
}
|
||||
else {
|
||||
// If view ajaxified.
|
||||
$('<div class="draggableviews-changed-notice messages warning">' + Drupal.t('Order of the list has been changed.') + '</div>')
|
||||
.insertBefore($(this).parents('form div.item-list')).hide().fadeIn('slow').delay(3000).fadeOut('slow');
|
||||
$(this).addClass('draggableviews-changed');
|
||||
}
|
||||
}
|
||||
// If Ajax enabled, we should submit the form.
|
||||
if (Drupal.settings.draggableviews_ajax) {
|
||||
$(this).parent().parent().find('#edit-submit').trigger('mousedown');
|
||||
}
|
||||
},
|
||||
containment: 'parent',
|
||||
cursor: 'move'
|
||||
});
|
||||
if (Drupal.settings.draggableviews_ajax) {
|
||||
$('.views-form .' + Drupal.settings.draggableviews_row_class).parent().parent().find('#edit-submit').hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
425
sites/all/modules/draggableviews/test/draggableviews.test
Normal file
425
sites/all/modules/draggableviews/test/draggableviews.test
Normal file
@@ -0,0 +1,425 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test cases file.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for testing Draggableviews module.
|
||||
*/
|
||||
class DraggableviewsTestCase extends DrupalWebTestCase {
|
||||
|
||||
function setUp() {
|
||||
parent::setUp(array('ctools', 'views', 'views_ui', 'entity', 'draggableviews', 'draggableviews_test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fork from drupalPost().
|
||||
*
|
||||
* When action of the form determined we don't care about exposed filter
|
||||
* arguments passed to the view. In this fork we use
|
||||
* $this->getUrl() unconditionally.
|
||||
*/
|
||||
protected function drupalDraggableviewsPost($path, $edit, $submit, array $options = array(), array $headers = array(), $form_html_id = NULL, $extra_post = NULL) {
|
||||
$submit_matches = FALSE;
|
||||
$ajax = is_array($submit);
|
||||
if (isset($path)) {
|
||||
$this->drupalGet($path, $options);
|
||||
}
|
||||
if ($this->parse()) {
|
||||
$edit_save = $edit;
|
||||
// Let's iterate over all the forms.
|
||||
$xpath = "//form";
|
||||
if (!empty($form_html_id)) {
|
||||
$xpath .= "[@id='" . $form_html_id . "']";
|
||||
}
|
||||
$forms = $this->xpath($xpath);
|
||||
foreach ($forms as $form) {
|
||||
// We try to set the fields of this form as specified in $edit.
|
||||
$edit = $edit_save;
|
||||
$post = array();
|
||||
$upload = array();
|
||||
$submit_matches = $this->handleForm($post, $edit, $upload, $ajax ? NULL : $submit, $form);
|
||||
// $action = isset($form['action']) ? $this->getAbsoluteUrl((string) $form['action']) : $this->getUrl();
|
||||
$action = $this->getUrl();
|
||||
if ($ajax) {
|
||||
$action = $this->getAbsoluteUrl(!empty($submit['path']) ? $submit['path'] : 'system/ajax');
|
||||
// Ajax callbacks verify the triggering element if necessary, so while
|
||||
// we may eventually want extra code that verifies it in the
|
||||
// handleForm() function, it's not currently a requirement.
|
||||
$submit_matches = TRUE;
|
||||
}
|
||||
|
||||
// We post only if we managed to handle every field in edit and the
|
||||
// submit button matches.
|
||||
if (!$edit && ($submit_matches || !isset($submit))) {
|
||||
$post_array = $post;
|
||||
if ($upload) {
|
||||
// TODO: cURL handles file uploads for us, but the implementation
|
||||
// is broken. This is a less than elegant workaround. Alternatives
|
||||
// are being explored at #253506.
|
||||
foreach ($upload as $key => $file) {
|
||||
$file = drupal_realpath($file);
|
||||
if ($file && is_file($file)) {
|
||||
$post[$key] = '@' . $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($post as $key => $value) {
|
||||
// Encode according to application/x-www-form-urlencoded
|
||||
// Both names and values needs to be urlencoded, according to
|
||||
// http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
|
||||
$post[$key] = urlencode($key) . '=' . urlencode($value);
|
||||
}
|
||||
$post = implode('&', $post) . $extra_post;
|
||||
}
|
||||
$out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HTTPHEADER => $headers));
|
||||
// Ensure that any changes to variables in the other thread are picked up.
|
||||
$this->refreshVariables();
|
||||
|
||||
// Replace original page output with new output from redirected page(s).
|
||||
if ($new = $this->checkForMetaRefresh()) {
|
||||
$out = $new;
|
||||
}
|
||||
$this->verbose('POST request to: ' . $path .
|
||||
'<hr />Ending URL: ' . $this->getUrl() .
|
||||
'<hr />Fields: ' . highlight_string('<?php ' . var_export($post_array, TRUE), TRUE) .
|
||||
'<hr />' . $out);
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
// We have not found a form which contained all fields of $edit.
|
||||
foreach ($edit as $name => $value) {
|
||||
$this->fail(t('Failed to set field @name to @value', array('@name' => $name, '@value' => $value)));
|
||||
}
|
||||
if (!$ajax && isset($submit)) {
|
||||
$this->assertTrue($submit_matches, t('Found the @submit button', array('@submit' => $submit)));
|
||||
}
|
||||
$this->fail(t('Found the requested form fields at @path', array('@path' => $path)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing Native Handler.
|
||||
*/
|
||||
class DraggableviewsNativeHandlerTestCase extends DraggableviewsTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Native handler',
|
||||
'description' => 'Test the native handler.',
|
||||
'group' => 'Draggableviews',
|
||||
);
|
||||
}
|
||||
|
||||
function testSort() {
|
||||
$permissions = array('access content');
|
||||
$rid = $this->drupalCreateRole($permissions);
|
||||
|
||||
// Create five test users.
|
||||
$accounts = array();
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$edit = array();
|
||||
$edit['name'] = $this->randomName();
|
||||
// First three users should be prefixed 'test_'.
|
||||
if ($i < 3) {
|
||||
$edit['name'] = 'test_' . $edit['name'];
|
||||
}
|
||||
$edit['mail'] = $edit['name'] . '@example.com';
|
||||
$edit['roles'] = array($rid => $rid);
|
||||
$edit['pass'] = user_password();
|
||||
$edit['status'] = 1;
|
||||
|
||||
$account = user_save(drupal_anonymous_user(), $edit);
|
||||
$account->pass_raw = $edit['pass'];
|
||||
|
||||
$accounts[$account->uid] = $account;
|
||||
}
|
||||
|
||||
$account = $this->drupalCreateUser(array('access content', 'access draggableviews', 'access user profiles', 'access contextual links'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// Now lets sort and save a view.
|
||||
$edit = array(
|
||||
'draggableviews[0][weight]' => 0,
|
||||
'draggableviews[0][id]' => 1,
|
||||
'draggableviews[1][weight]' => 1,
|
||||
'draggableviews[1][id]' => 2,
|
||||
'draggableviews[2][weight]' => 2,
|
||||
'draggableviews[2][id]' => 3,
|
||||
'draggableviews[3][weight]' => 3,
|
||||
'draggableviews[3][id]' => 4,
|
||||
'draggableviews[4][weight]' => 4,
|
||||
'draggableviews[4][id]' => 5,
|
||||
'draggableviews[5][weight]' => 5,
|
||||
'draggableviews[5][id]' => 6,
|
||||
'draggableviews[6][weight]' => 6,
|
||||
'draggableviews[6][id]' => 7,
|
||||
);
|
||||
$this->drupalPost('users-set', $edit, t('Save'));
|
||||
|
||||
// Assert that first user is on first place, and second is on second.
|
||||
$first_row = $this->xpath('//tr[@class="odd views-row-first draggable"]/td/a[@class="username"]');
|
||||
$second_row = $this->xpath('//tr[@class="even draggable"]/td/a[@class="username"]');
|
||||
$this->assertEqual((string) $first_row[0], 'placeholder-for...', t('First row user uid 1.'));
|
||||
$this->assertEqual((string) $second_row[0], $accounts[2]->name, t('Second row user uid 2.'));
|
||||
|
||||
// Now save a different sort (first and second rows changed places).
|
||||
$edit = array(
|
||||
'draggableviews[0][weight]' => 0,
|
||||
'draggableviews[0][id]' => 2,
|
||||
'draggableviews[1][weight]' => 1,
|
||||
'draggableviews[1][id]' => 1,
|
||||
'draggableviews[2][weight]' => 2,
|
||||
'draggableviews[2][id]' => 3,
|
||||
'draggableviews[3][weight]' => 3,
|
||||
'draggableviews[3][id]' => 4,
|
||||
'draggableviews[4][weight]' => 4,
|
||||
'draggableviews[4][id]' => 5,
|
||||
'draggableviews[5][weight]' => 5,
|
||||
'draggableviews[5][id]' => 6,
|
||||
'draggableviews[6][weight]' => 6,
|
||||
'draggableviews[6][id]' => 7,
|
||||
);
|
||||
$this->drupalPost('users-set', $edit, t('Save'));
|
||||
// Assert that first user is on second place, and second user is on first.
|
||||
$first_row = $this->xpath('//tr[@class="odd views-row-first draggable"]/td/a[@class="username"]');
|
||||
$second_row = $this->xpath('//tr[@class="even draggable"]/td/a[@class="username"]');
|
||||
$this->assertEqual((string) $first_row[0], $accounts[2]->name, t('First row user uid 2.'));
|
||||
$this->assertEqual((string) $second_row[0], 'placeholder-for...', t('Second row user uid 1.'));
|
||||
|
||||
// Apply exposed filter and set weights.
|
||||
$edit = array(
|
||||
'draggableviews[0][weight]' => 0,
|
||||
'draggableviews[0][id]' => 4,
|
||||
'draggableviews[1][weight]' => 1,
|
||||
'draggableviews[1][id]' => 3,
|
||||
'draggableviews[2][weight]' => 2,
|
||||
'draggableviews[2][id]' => 2,
|
||||
);
|
||||
$this->drupalDraggableviewsPost('users-set', $edit, t('Save'), array('query' => array('mail' => 'test')));
|
||||
|
||||
// Now lets check display view page.
|
||||
$this->drupalGet('users-display');
|
||||
$first_row = $this->xpath('//tr[@class="odd views-row-first"]/td/a[@class="username"]');
|
||||
$second_row = $this->xpath('//tr[@class="even"]/td/a[@class="username"]');
|
||||
$this->assertEqual((string) $first_row[0], $accounts[2]->name, t('Display view. First row user uid 2.'));
|
||||
$this->assertEqual((string) $second_row[0], 'placeholder-for...', t('Display view. Second row user uid 1.'));
|
||||
|
||||
// Check display view with applied exposed filter.
|
||||
$this->drupalGet('users-display', array('query' => array('mail' => 'test')));
|
||||
$first_row = $this->xpath('//tr[@class="odd views-row-first"]/td/a[@class="username"]');
|
||||
$second_row = $this->xpath('//tr[@class="even"]/td/a[@class="username"]');
|
||||
$this->assertEqual((string) $first_row[0], $accounts[4]->name, t('Display view. Exposed filter applied. First row user uid 4.'));
|
||||
$this->assertEqual((string) $second_row[0], $accounts[3]->name, t('Display view. Exposed filter applied. Second row user uid 3.'));
|
||||
|
||||
// Check contextual link existense.
|
||||
$contextual_links = $this->xpath('//ul[@class="contextual-links views-contextual-links-page"]/li/a');
|
||||
$href = (string) $contextual_links[0]['href'];
|
||||
$this->assertTrue(strpos($href, 'users-set?destination=users-display') !== FALSE, t('Contextual link exists.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing Fielad API Handler.
|
||||
*/
|
||||
class DraggableviewsFieldAPIHandlerTestCase extends DraggableviewsTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field API handler',
|
||||
'description' => 'Test the Field API handler.',
|
||||
'group' => 'Draggableviews',
|
||||
);
|
||||
}
|
||||
|
||||
public function testSort() {
|
||||
$this->createField();
|
||||
|
||||
$account = $this->drupalCreateUser(array('access content', 'access draggableviews', 'access user profiles', 'access contextual links'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// Create five nodes.
|
||||
$nodes = array();
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$node = $this->drupalCreateNode(array('type' => 'article',));
|
||||
$nodes[$node->nid] = $node;
|
||||
}
|
||||
|
||||
// Now lets sort and save a view.
|
||||
$edit = array(
|
||||
'draggableviews[0][weight]' => 0,
|
||||
'draggableviews[0][id]' => 1,
|
||||
'draggableviews[1][weight]' => 1,
|
||||
'draggableviews[1][id]' => 2,
|
||||
'draggableviews[2][weight]' => 2,
|
||||
'draggableviews[2][id]' => 3,
|
||||
'draggableviews[3][weight]' => 3,
|
||||
'draggableviews[3][id]' => 4,
|
||||
'draggableviews[4][weight]' => 4,
|
||||
'draggableviews[4][id]' => 5,
|
||||
);
|
||||
$this->drupalPost('nodes-set', $edit, t('Save'));
|
||||
// Assert that first node is on first place, and second is on second.
|
||||
$first_row = $this->xpath('//tr[@class="odd views-row-first draggable"]/td/a');
|
||||
$second_row = $this->xpath('//tr[@class="even draggable"]/td/a');
|
||||
$this->assertEqual((string) $first_row[0], $nodes[1]->title, t('First row node nid 1.'));
|
||||
$this->assertEqual((string) $second_row[0], $nodes[2]->title, t('Second row node nid 2.'));
|
||||
|
||||
// Now save a different sort (first and second rows changed places).
|
||||
$edit = array(
|
||||
'draggableviews[0][weight]' => 0,
|
||||
'draggableviews[0][id]' => 2,
|
||||
'draggableviews[1][weight]' => 1,
|
||||
'draggableviews[1][id]' => 1,
|
||||
'draggableviews[2][weight]' => 2,
|
||||
'draggableviews[2][id]' => 3,
|
||||
'draggableviews[3][weight]' => 3,
|
||||
'draggableviews[3][id]' => 4,
|
||||
'draggableviews[4][weight]' => 4,
|
||||
'draggableviews[4][id]' => 5,
|
||||
);
|
||||
$this->drupalPost('nodes-set', $edit, t('Save'));
|
||||
// Assert that first node is on second place, and second is on first.
|
||||
$first_row = $this->xpath('//tr[@class="odd views-row-first draggable"]/td/a');
|
||||
$second_row = $this->xpath('//tr[@class="even draggable"]/td/a');
|
||||
$this->assertEqual((string) $first_row[0], $nodes[2]->title, t('First row node nid 2.'));
|
||||
$this->assertEqual((string) $second_row[0], $nodes[1]->title, t('Second row node nid 1.'));
|
||||
|
||||
// Check display view order.
|
||||
$this->drupalGet('nodes-display');
|
||||
$first_row = $this->xpath('//tr[@class="odd views-row-first"]/td/a');
|
||||
$second_row = $this->xpath('//tr[@class="even"]/td/a');
|
||||
$this->assertEqual((string) $first_row[0], $nodes[2]->title, t('First row node nid 2.'));
|
||||
$this->assertEqual((string) $second_row[0], $nodes[1]->title, t('Second row node nid 1.'));
|
||||
|
||||
// Check values of nodes.
|
||||
$node1 = node_load(1);
|
||||
$node2 = node_load(2);
|
||||
$this->assertTrue($node1->field_weight[LANGUAGE_NONE][0]['value'] > $node2->field_weight[LANGUAGE_NONE][0]['value'], t('Weight of node 1 is more than weight of node 2.'));
|
||||
}
|
||||
|
||||
// Create a integer field for Article nodes.
|
||||
function createField() {
|
||||
$field = array (
|
||||
'translatable' => '0',
|
||||
'entity_types' =>
|
||||
array (
|
||||
),
|
||||
'settings' =>
|
||||
array (
|
||||
),
|
||||
'storage' =>
|
||||
array (
|
||||
'type' => 'field_sql_storage',
|
||||
'settings' =>
|
||||
array (
|
||||
),
|
||||
'module' => 'field_sql_storage',
|
||||
'active' => '1',
|
||||
'details' =>
|
||||
array (
|
||||
'sql' =>
|
||||
array (
|
||||
'FIELD_LOAD_CURRENT' =>
|
||||
array (
|
||||
'field_data_field_weight' =>
|
||||
array (
|
||||
'value' => 'field_weight_value',
|
||||
),
|
||||
),
|
||||
'FIELD_LOAD_REVISION' =>
|
||||
array (
|
||||
'field_revision_field_weight' =>
|
||||
array (
|
||||
'value' => 'field_weight_value',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'foreign keys' =>
|
||||
array (
|
||||
),
|
||||
'indexes' =>
|
||||
array (
|
||||
),
|
||||
'id' => '5',
|
||||
'field_name' => 'field_weight',
|
||||
'type' => 'number_integer',
|
||||
'module' => 'number',
|
||||
'active' => '1',
|
||||
'locked' => '0',
|
||||
'cardinality' => '1',
|
||||
'deleted' => '0',
|
||||
'columns' =>
|
||||
array (
|
||||
'value' =>
|
||||
array (
|
||||
'type' => 'int',
|
||||
'not null' => false,
|
||||
),
|
||||
),
|
||||
'bundles' =>
|
||||
array (
|
||||
'node' =>
|
||||
array (
|
||||
0 => 'article',
|
||||
),
|
||||
),
|
||||
);
|
||||
field_create_field($field);
|
||||
|
||||
$instance = array (
|
||||
'label' => 'Weight',
|
||||
'widget' =>
|
||||
array (
|
||||
'weight' => 0,
|
||||
'type' => 'number',
|
||||
'module' => 'number',
|
||||
'active' => 0,
|
||||
'settings' =>
|
||||
array (
|
||||
),
|
||||
),
|
||||
'settings' =>
|
||||
array (
|
||||
'min' => '',
|
||||
'max' => '',
|
||||
'prefix' => '',
|
||||
'suffix' => '',
|
||||
'user_register_form' => false,
|
||||
),
|
||||
'display' =>
|
||||
array (
|
||||
'default' =>
|
||||
array (
|
||||
'label' => 'above',
|
||||
'type' => 'number_integer',
|
||||
'settings' =>
|
||||
array (
|
||||
'thousand_separator' => ' ',
|
||||
'decimal_separator' => '.',
|
||||
'scale' => 0,
|
||||
'prefix_suffix' => true,
|
||||
),
|
||||
'module' => 'number',
|
||||
'weight' => 11,
|
||||
),
|
||||
),
|
||||
'required' => 0,
|
||||
'description' => '',
|
||||
'default_value' => NULL,
|
||||
'id' => '7',
|
||||
'field_id' => '5',
|
||||
'field_name' => 'field_weight',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'article',
|
||||
'deleted' => '0',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
name = Draggableviews Test
|
||||
description = Provides views for testing.
|
||||
dependencies[] = draggableviews
|
||||
package = Views
|
||||
core = 7.x
|
||||
hidden = TRUE
|
||||
; Information added by drupal.org packaging script on 2012-04-02
|
||||
version = "7.x-2.0-beta1"
|
||||
core = "7.x"
|
||||
project = "draggableviews"
|
||||
datestamp = "1333351548"
|
||||
|
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function draggableviews_test_views_api() {
|
||||
return array(
|
||||
'api' => 3,
|
||||
'path' => drupal_get_path('module', 'draggableviews_test'),
|
||||
);
|
||||
}
|
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views to import for testing.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_default_views().
|
||||
*/
|
||||
function draggableviews_test_views_default_views() {
|
||||
$view = new view;
|
||||
$view->name = 'users';
|
||||
$view->description = '';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'users';
|
||||
$view->human_name = 'Users';
|
||||
$view->core = 7;
|
||||
$view->api_version = '3.0';
|
||||
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
||||
|
||||
/* Display: Master */
|
||||
$handler = $view->new_display('default', 'Master', 'default');
|
||||
$handler->display->display_options['title'] = 'Users';
|
||||
$handler->display->display_options['access']['type'] = 'perm';
|
||||
$handler->display->display_options['access']['perm'] = 'access user profiles';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['query']['options']['query_tags'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
|
||||
$handler->display->display_options['style_plugin'] = 'table';
|
||||
/* Field: User: Name */
|
||||
$handler->display->display_options['fields']['name']['id'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['table'] = 'users';
|
||||
$handler->display->display_options['fields']['name']['field'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
|
||||
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
|
||||
/* Field: Draggableviews: User */
|
||||
$handler->display->display_options['fields']['draggableviews']['id'] = 'draggableviews';
|
||||
$handler->display->display_options['fields']['draggableviews']['table'] = 'users';
|
||||
$handler->display->display_options['fields']['draggableviews']['field'] = 'draggableviews';
|
||||
$handler->display->display_options['fields']['draggableviews']['element_label_colon'] = 1;
|
||||
$handler->display->display_options['fields']['draggableviews']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['draggableviews']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['draggableviews']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['draggableviews']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['draggableviews']['draggableviews']['ajax'] = 0;
|
||||
/* Field: User: E-mail */
|
||||
$handler->display->display_options['fields']['mail']['id'] = 'mail';
|
||||
$handler->display->display_options['fields']['mail']['table'] = 'users';
|
||||
$handler->display->display_options['fields']['mail']['field'] = 'mail';
|
||||
$handler->display->display_options['fields']['mail']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['mail']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['mail']['alter']['more_link'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['element_label_colon'] = 1;
|
||||
$handler->display->display_options['fields']['mail']['element_default_classes'] = 1;
|
||||
$handler->display->display_options['fields']['mail']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['hide_alter_empty'] = 1;
|
||||
/* Sort criterion: Draggableviews: Weight */
|
||||
$handler->display->display_options['sorts']['weight']['id'] = 'weight';
|
||||
$handler->display->display_options['sorts']['weight']['table'] = 'draggableviews_structure';
|
||||
$handler->display->display_options['sorts']['weight']['field'] = 'weight';
|
||||
$handler->display->display_options['sorts']['weight']['draggableviews_setting_view'] = 'users:page';
|
||||
$handler->display->display_options['sorts']['weight']['draggableviews_setting_new_items_bottom_list'] = 1;
|
||||
/* Filter criterion: User: Active */
|
||||
$handler->display->display_options['filters']['status']['id'] = 'status';
|
||||
$handler->display->display_options['filters']['status']['table'] = 'users';
|
||||
$handler->display->display_options['filters']['status']['field'] = 'status';
|
||||
$handler->display->display_options['filters']['status']['value'] = '1';
|
||||
$handler->display->display_options['filters']['status']['group'] = 1;
|
||||
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
|
||||
/* Filter criterion: User: E-mail */
|
||||
$handler->display->display_options['filters']['mail']['id'] = 'mail';
|
||||
$handler->display->display_options['filters']['mail']['table'] = 'users';
|
||||
$handler->display->display_options['filters']['mail']['field'] = 'mail';
|
||||
$handler->display->display_options['filters']['mail']['operator'] = 'starts';
|
||||
$handler->display->display_options['filters']['mail']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['mail']['expose']['operator_id'] = 'mail_op';
|
||||
$handler->display->display_options['filters']['mail']['expose']['label'] = 'E-mail';
|
||||
$handler->display->display_options['filters']['mail']['expose']['operator'] = 'mail_op';
|
||||
$handler->display->display_options['filters']['mail']['expose']['identifier'] = 'mail';
|
||||
$handler->display->display_options['filters']['mail']['expose']['required'] = 0;
|
||||
$handler->display->display_options['filters']['mail']['expose']['multiple'] = FALSE;
|
||||
|
||||
/* Display: Page */
|
||||
$handler = $view->new_display('page', 'Page', 'page_1');
|
||||
$handler->display->display_options['defaults']['fields'] = FALSE;
|
||||
/* Field: User: Name */
|
||||
$handler->display->display_options['fields']['name']['id'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['table'] = 'users';
|
||||
$handler->display->display_options['fields']['name']['field'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
|
||||
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
|
||||
/* Field: User: E-mail */
|
||||
$handler->display->display_options['fields']['mail']['id'] = 'mail';
|
||||
$handler->display->display_options['fields']['mail']['table'] = 'users';
|
||||
$handler->display->display_options['fields']['mail']['field'] = 'mail';
|
||||
$handler->display->display_options['fields']['mail']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['mail']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['mail']['alter']['more_link'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['element_label_colon'] = 1;
|
||||
$handler->display->display_options['fields']['mail']['element_default_classes'] = 1;
|
||||
$handler->display->display_options['fields']['mail']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['mail']['hide_alter_empty'] = 1;
|
||||
$handler->display->display_options['path'] = 'users-display';
|
||||
|
||||
/* Display: Set Page */
|
||||
$handler = $view->new_display('page', 'Set Page', 'page');
|
||||
$handler->display->display_options['path'] = 'users-set';
|
||||
|
||||
$views[$view->name] = $view;
|
||||
|
||||
$view = new view;
|
||||
$view->name = 'nodes';
|
||||
$view->description = '';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'nodes';
|
||||
$view->core = 7;
|
||||
$view->api_version = '3.0';
|
||||
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
||||
|
||||
/* Display: Master */
|
||||
$handler = $view->new_display('default', 'Master', 'default');
|
||||
$handler->display->display_options['title'] = 'nodes';
|
||||
$handler->display->display_options['access']['type'] = 'perm';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['query']['options']['query_tags'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
|
||||
$handler->display->display_options['style_plugin'] = 'table';
|
||||
/* Field: Content: Title */
|
||||
$handler->display->display_options['fields']['title']['id'] = 'title';
|
||||
$handler->display->display_options['fields']['title']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['title']['field'] = 'title';
|
||||
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
|
||||
/* Field: Draggableviews: Content */
|
||||
$handler->display->display_options['fields']['draggableviews']['id'] = 'draggableviews';
|
||||
$handler->display->display_options['fields']['draggableviews']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['draggableviews']['field'] = 'draggableviews';
|
||||
$handler->display->display_options['fields']['draggableviews']['element_label_colon'] = 1;
|
||||
$handler->display->display_options['fields']['draggableviews']['element_default_classes'] = 0;
|
||||
$handler->display->display_options['fields']['draggableviews']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['draggableviews']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['draggableviews']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['draggableviews']['draggableviews']['handler'] = 'draggableviews_handler_fieldapi';
|
||||
$handler->display->display_options['fields']['draggableviews']['draggableviews']['ajax'] = 0;
|
||||
$handler->display->display_options['fields']['draggableviews']['draggableviews']['draggableviews_handler_fieldapi'] = array(
|
||||
'field' => 'field_data_field_weight:field_weight_value',
|
||||
);
|
||||
/* Sort criterion: Content: Weight (field_weight) */
|
||||
$handler->display->display_options['sorts']['field_weight_value']['id'] = 'field_weight_value';
|
||||
$handler->display->display_options['sorts']['field_weight_value']['table'] = 'field_data_field_weight';
|
||||
$handler->display->display_options['sorts']['field_weight_value']['field'] = 'field_weight_value';
|
||||
/* Filter criterion: Content: Published */
|
||||
$handler->display->display_options['filters']['status']['id'] = 'status';
|
||||
$handler->display->display_options['filters']['status']['table'] = 'node';
|
||||
$handler->display->display_options['filters']['status']['field'] = 'status';
|
||||
$handler->display->display_options['filters']['status']['value'] = 1;
|
||||
$handler->display->display_options['filters']['status']['group'] = 1;
|
||||
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
|
||||
|
||||
/* Display: Set Page */
|
||||
$handler = $view->new_display('page', 'Set Page', 'page');
|
||||
$handler->display->display_options['path'] = 'nodes-set';
|
||||
|
||||
/* Display: Display Page */
|
||||
$handler = $view->new_display('page', 'Display Page', 'page_1');
|
||||
$handler->display->display_options['defaults']['fields'] = FALSE;
|
||||
/* Field: Content: Title */
|
||||
$handler->display->display_options['fields']['title']['id'] = 'title';
|
||||
$handler->display->display_options['fields']['title']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['title']['field'] = 'title';
|
||||
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
|
||||
$handler->display->display_options['path'] = 'nodes-display';
|
||||
|
||||
$views[$view->name] = $view;
|
||||
|
||||
return $views;
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views hooks implementations.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_data_alter().
|
||||
*/
|
||||
function draggableviews_views_data_alter(&$data) {
|
||||
|
||||
$data['draggableviews_structure']['weight'] = array(
|
||||
'title' => t('Weight'),
|
||||
'help' => t('Sort entities by the draggableviews weight table field.'),
|
||||
'group' => t('Draggableviews'),
|
||||
'sort' => array(
|
||||
'handler' => 'draggableviews_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
foreach (entity_get_info() as $entity_type => $info) {
|
||||
if (isset($info['base table']) && isset($data[$info['base table']]['table'])) {
|
||||
$data[$info['base table']]['draggableviews'] = array(
|
||||
'title' => $data[$info['base table']]['table']['group'],
|
||||
'group' => t('Draggableviews'),
|
||||
'help' => t('Provide a draggable functionality.'),
|
||||
'real field' => $info['entity keys']['id'],
|
||||
'field' => array(
|
||||
'handler' => 'draggableviews_handler_field_draggable',
|
||||
'click sortable' => FALSE,
|
||||
),
|
||||
);
|
||||
|
||||
// Explain to every entity how to join with draggableviews structure table.
|
||||
$data['draggableviews_structure']['table']['join'][$info['base table']] = array(
|
||||
'handler' => 'draggableviews_join_handler',
|
||||
'left_table' => $info['base table'], // Because this is a direct link it could be left out.
|
||||
'left_field' => $info['entity keys']['id'],
|
||||
'field' => 'entity_id',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views field handler. Contains all relevant Draggableviews
|
||||
* options and related logic.
|
||||
* Implements the Views Form API.
|
||||
*/
|
||||
|
||||
class draggableviews_handler_field_draggable extends views_handler_field {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['draggableviews'] = array(
|
||||
'contains' => array(
|
||||
'handler' => array('default' => 'draggableviews_handler_native'),
|
||||
'save_button_label' => array('default' => 'Save'),
|
||||
'ajax' => array('default' => FALSE),
|
||||
),
|
||||
);
|
||||
|
||||
// Populate default values of form elements provided by handlers.
|
||||
foreach (draggableviews_get_handlers() as $handler_id => $handler_object) {
|
||||
$options['draggableviews']['contains'][$handler_id] = array('default' => $handler_object->option_definition());
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
// Remove not needed settings options.
|
||||
$form['alter']['#access'] = FALSE;
|
||||
$form['style_settings']['#access'] = FALSE;
|
||||
$form['empty_field_behavior']['#access'] = FALSE;
|
||||
|
||||
$form['draggableviews'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Draggable Views'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
);
|
||||
|
||||
$handler_options = array();
|
||||
$handler_forms = array();
|
||||
foreach (draggableviews_get_handlers() as $handler_id => $handler_object) {
|
||||
$handler = ctools_get_plugins('draggableviews', 'handler', $handler_id);
|
||||
$handler_options[$handler_id] = filter_xss($handler['label']);
|
||||
$handler_forms[$handler_id] = $handler_object->options_form($this);
|
||||
}
|
||||
|
||||
$form['draggableviews']['handler'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Handler'),
|
||||
'#options' => $handler_options,
|
||||
'#default_value' => $this->options['draggableviews']['handler'],
|
||||
);
|
||||
|
||||
// Add handler's form element as fielset that
|
||||
// is active only if handler selected.
|
||||
foreach ($handler_forms as $handler_id => $handler_form_element) {
|
||||
// Skip empty handler's form elements.
|
||||
if (empty($handler_form_element)) {
|
||||
continue;
|
||||
}
|
||||
$form['draggableviews'][$handler_id] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => check_plain($form['draggableviews']['handler']['#options'][$handler_id]),
|
||||
'#collapsible' => FALSE,
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
'select[name="options[draggableviews][handler]"]' => array('value' => $handler_id),
|
||||
),
|
||||
),
|
||||
);
|
||||
foreach ($handler_form_element as $key => $form_element) {
|
||||
$form['draggableviews'][$handler_id][$key] = $form_element;
|
||||
}
|
||||
}
|
||||
|
||||
$form['draggableviews']['save_button_label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Custom Save button label'),
|
||||
'#description' => t("Allow to change Save button Label."),
|
||||
'#default_value' => $this->options['draggableviews']['save_button_label'],
|
||||
);
|
||||
|
||||
$form['draggableviews']['ajax'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Ajax'),
|
||||
'#description' => t('Use ajax in draggable form.'),
|
||||
'#default_value' => $this->options['draggableviews']['ajax'],
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
if (user_access('access draggableviews')) {
|
||||
return '<!--form-item-' . $this->options['id'] . '--' . $this->view->row_index . '-->';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The form which replaces the placeholder from render().
|
||||
*/
|
||||
function views_form(&$form, &$form_state) {
|
||||
// The view is empty, abort.
|
||||
if (empty($this->view->result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$form[$this->options['id']] = array(
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
$range = count($this->view->result);
|
||||
// At this point, the query has already been run, so we can access the results
|
||||
// in order to get the base key value (for example, nid for nodes).
|
||||
foreach ($this->view->result as $row_index => $row) {
|
||||
$entity_id = $this->get_value($row);
|
||||
|
||||
$form[$this->options['id']][$row_index] = array(
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
$handler_object = draggableviews_get_handler_class($this->options['draggableviews']['handler']);
|
||||
|
||||
// Weight field selectbox.
|
||||
$form[$this->options['id']][$row_index]['weight'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => range(-$range, $range),
|
||||
'#attributes' => array('class' => array('draggableviews-weight')),
|
||||
'#default_value' => $handler_object->get($this, $row_index),
|
||||
);
|
||||
// Item to keep id of the entity.
|
||||
$form[$this->options['id']][$row_index]['id'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => $this->view->result[$row_index]->{$this->view->base_field},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Native handler sort.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sort handler for ordering by weight.
|
||||
*/
|
||||
class draggableviews_handler_sort extends views_handler_sort {
|
||||
function query() {
|
||||
$this->ensure_my_table();
|
||||
// If new items should be placed in the bottom.
|
||||
if ($this->options['draggableviews_setting_new_items_bottom_list']) {
|
||||
// ORDER BY COALESCE(weight, 10000)
|
||||
// New items will get big default instead of NULL
|
||||
$as = $this->table_alias . '_' . $this->real_field;
|
||||
$as = $this->query->add_field($this->table_alias, $this->real_field, $as, array());
|
||||
$this->query->orderby[] = array(
|
||||
'field' => 'COALESCE(' . $as . ', 10000)',
|
||||
'direction' => drupal_strtoupper($this->options['order'])
|
||||
);
|
||||
}
|
||||
else {
|
||||
// New items will be placed at the top as have NULL value.
|
||||
$this->query->add_orderby($this->table_alias, $this->real_field);
|
||||
}
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
// This handler invokes few times for one view,
|
||||
// in the first time the $this->view->name is empty,
|
||||
// so we need this check.
|
||||
if (is_object($this->view)) {
|
||||
$options['draggableviews_setting_view'] = array('default' => $this->view->name);
|
||||
}
|
||||
else {
|
||||
$options['draggableviews_setting_view'] = array('default' => NULL);
|
||||
}
|
||||
|
||||
$options['draggableviews_setting_arguments'] = array('default' => 'all');
|
||||
$options['draggableviews_setting_arguments_php'] = array('default' => '');
|
||||
$options['draggableviews_setting_new_items_bottom_list'] = array('default' => TRUE);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['expose_button']['#access'] = FALSE;
|
||||
$form['order']['#description'] = t('Please remember to override settings of the sort criterion if you have display that sets weights and you choose descendling order.');
|
||||
|
||||
// Check whether current views display doesn't have draggableviews field.
|
||||
// If it has, it means that this is setting view so we should set
|
||||
// option draggableviews_setting_view to 'self'
|
||||
$view_clone = clone $this->view;
|
||||
$view_clone->build($view_clone->current_display);
|
||||
$options = 'self';
|
||||
// Check whether field exists. If not it is displaying view so lets show
|
||||
// all options of other setting views.
|
||||
if (!isset($view_clone->field['draggableviews'])) {
|
||||
// Get list of all enabled views.
|
||||
$views_list = views_get_enabled_views();
|
||||
$options = array();
|
||||
|
||||
// Convert list of objects to options for the form.
|
||||
foreach ($views_list as $view_name => $view_object) {
|
||||
foreach ($view_object->display as $display_name => $display) {
|
||||
if ($display_name == 'default') {
|
||||
continue;
|
||||
}
|
||||
// Clone view and build it so we can see all the fields.
|
||||
$view_clone = clone $view_object;
|
||||
$view_clone->build($display_name);
|
||||
|
||||
// If draggableviews field attached, show this view in options.
|
||||
if (isset($view_clone->field['draggableviews'])) {
|
||||
$options[$view_name . ':' . $display_name] = $view_object->human_name . ' (' . $display->display_title . ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If it is setting view.
|
||||
if (!is_array($options)) {
|
||||
$form['order']['#access'] = FALSE;
|
||||
$form['draggableviews_setting_view'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $this->options['draggableviews_setting_view'],
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['draggableviews_setting_view'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Display sort as'),
|
||||
'#default_value' => $this->options['draggableviews_setting_view'],
|
||||
'#options' => $options,
|
||||
'#description' => t('Please choose the view and display that sets the order.')
|
||||
);
|
||||
// If there is no setting views available, show error message.
|
||||
if (empty($options)) {
|
||||
drupal_set_message(t('First you should create a view that sets sorting order.'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
$form['draggableviews_setting_arguments'] = array(
|
||||
'#title' => t('Arguments handling'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
'all' => t('Use all arguments'),
|
||||
'none' => t('Do not use any arguments (use empty arguments)'),
|
||||
'php' => t('Prepare arguments with PHP code'),
|
||||
),
|
||||
'#default_value' => $this->options['draggableviews_setting_arguments'],
|
||||
'#description' => t('When sorting order is saved all arguments passed are saved with order. In display view we can choose how to use these arguments.')
|
||||
);
|
||||
$form['draggableviews_setting_arguments_php'] = array(
|
||||
'#title' => t('PHP code to prepare arguments'),
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => $this->options['draggableviews_setting_arguments_php'],
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
'input[name="options[draggableviews_setting_arguments]"]' => array('value' => 'php'),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['draggableviews_setting_new_items_bottom_list'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('New items appear bottom of the list'),
|
||||
'#description' => t('New items means elements (for example nodes) that do not have saved weight (newly created).'),
|
||||
'#default_value' => $this->options['draggableviews_setting_new_items_bottom_list'],
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Native handler join handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Join handler for extra join conditions.
|
||||
*/
|
||||
class draggableviews_join_handler extends views_join {
|
||||
/**
|
||||
* Build the SQL for the join this object represents.
|
||||
*/
|
||||
function build_join($select_query, $table, $view_query) {
|
||||
if (empty($this->definition['table formula'])) {
|
||||
$right_table = $this->table;
|
||||
}
|
||||
else {
|
||||
$right_table = $this->definition['table formula'];
|
||||
}
|
||||
|
||||
if ($this->left_table) {
|
||||
$left = $view_query->get_table_info($this->left_table);
|
||||
$left_field = "$left[alias].$this->left_field";
|
||||
}
|
||||
else {
|
||||
// This can be used if left_field is a formula or something. It should be used only *very* rarely.
|
||||
$left_field = $this->left_field;
|
||||
}
|
||||
|
||||
$condition = "$left_field = $table[alias].$this->field";
|
||||
|
||||
// Check whether setting view is set.
|
||||
$arguments = array();
|
||||
$weight_key = draggable_views_get_draggable_sort($view_query->view);
|
||||
if (!empty($view_query->view->sort[$weight_key]->options['draggableviews_setting_view'])) {
|
||||
$condition .= " AND $table[alias].view_name = :view_name";
|
||||
$condition .= " AND $table[alias].view_display = :view_display";
|
||||
|
||||
// If it is setting view, set current view name and display name.
|
||||
if ($view_query->view->sort[$weight_key]->options['draggableviews_setting_view'] == 'self') {
|
||||
$arguments[':view_name'] = $view_query->view->name;
|
||||
$arguments[':view_display'] = $view_query->view->current_display;
|
||||
}
|
||||
else {
|
||||
list($setting_view_name, $setting_view_display) = explode(':', $view_query->view->sort[$weight_key]->options['draggableviews_setting_view']);
|
||||
$arguments[':view_name'] = $setting_view_name;
|
||||
$arguments[':view_display'] = $setting_view_display;
|
||||
}
|
||||
|
||||
// Arguments passed to view (including exposed filters).
|
||||
$view_arguments = $view_query->view->args;
|
||||
if (isset($view_query->view->exposed_raw_input)) {
|
||||
$view_arguments += $view_query->view->exposed_raw_input;
|
||||
ksort($view_arguments);
|
||||
}
|
||||
// Alter arguments according to sort criteria settings.
|
||||
if ($view_query->view->sort[$weight_key]->options['draggableviews_setting_arguments'] == 'none') {
|
||||
$view_arguments = array();
|
||||
}
|
||||
// If PHP arguments processing is set.
|
||||
if ($view_query->view->sort[$weight_key]->options['draggableviews_setting_arguments'] == 'php') {
|
||||
$view_arguments = draggableviews_eval_return($view_query->view->sort[$weight_key]->options['draggableviews_setting_arguments_php'], $view_arguments);
|
||||
}
|
||||
$condition .= " AND $table[alias].args = :view_arguments";
|
||||
$arguments[':view_arguments'] = json_encode($view_arguments);
|
||||
}
|
||||
|
||||
$select_query->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user