Created
March 7, 2013 20:48
-
-
Save rubemlrm/5111662 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function() { | |
| $.get(BASE, function(data) { | |
| $.each(data,function(key,value){ | |
| if(value.draft == 1){ | |
| var draft ='<span class="label label-success">Yes</span>'; | |
| }else{ | |
| var draft = '<span class="label label-important">No</span>'; | |
| } | |
| if(value.published == 1){ | |
| var published = '<span class="label label-success">Yes</span>'; | |
| }else{ | |
| var published = '<span class="label label-important">No</span>'; | |
| } | |
| var html = '<tr class="row'+value.id+'"><td class="action-checkbox"><input type="checkbox" class="action-select" value="' + value.id + '" name="value' + value.id + '"/></td><td><a href="'+ TYPE + '/' + value.id +'">'+value.title+'</a></td><td>' + value.created_at + '</td><td>' + draft + '</td><td>'+ published + '</td></tr>'; | |
| $(html).appendTo('#result_list') | |
| }); | |
| }); | |
| $('tbody tr').addClass('visible'); | |
| $('#keyword').keyup(function(event){ | |
| //verify is esc is pressed or nothing is entered | |
| if(event.keycode == 27 || $(this).val() == ''){ | |
| //if esc is pressed we want to clear the value of search box | |
| $(this).val(''); | |
| //we want each row to be visible because if nothing is enterede then all row are matched | |
| $('tbody tr').removeClass('visible').show().addClass('visible'); | |
| }else{ | |
| filter('tbody tr', $(this).val()); | |
| } | |
| }); | |
| //grab all header rows | |
| $('thead th').each(function(column){ | |
| $(this).addClass('sortable').click(function(){ | |
| var findSortKey = function($cell){ | |
| return $cell.find('.sort-key').text().toUpperCase() + ' ' + $cell.text().toUpperCase(); | |
| }; | |
| var sortDirection = $(this).is('.sorted-asc') ? -1 : 1; | |
| //step backup up the tree and get the rows with data | |
| //for sorting | |
| var $rows = $(this).parent() | |
| .parent() | |
| .parent() | |
| .find('tbody tr') | |
| .get(); | |
| //loop throuh all the rows and find | |
| $.each($rows,function(index,row){ | |
| row.sortKey = findSortKey($(row).children('td').eq(column)); | |
| }); | |
| //compare and sort the rows alpha | |
| $rows.sort(function(a,b){ | |
| if(a.sortKey < b.sortKey) return -sortDirection; | |
| if(a.sortKey > b.sortKey) return sortDirection; | |
| return 0; | |
| }); | |
| //add the rows in the correct order to the bottom of the table | |
| $.each($rows,function(index, row){ | |
| $('tbody').append(row); | |
| row.sortKey = null; | |
| }); | |
| //identify the column sort order | |
| $('th').removeClass('sorted-asc sorted-desc'); | |
| var $sortHead = $('th').filter(':nth-child(' +(column + 1) +')'); | |
| sortDirection == 1 ? $sortHead.addClass('sorted-asc') : $sortHead.addClass('sorted-desc'); | |
| //identify the column to be sorted by | |
| $('td').removeClass('sorted') | |
| .filter(':nth-child('+ (column + 1) +')') | |
| .addClass('sorted'); | |
| }); | |
| }); | |
| }); | |
| function filter(selector, query) { | |
| query = $.trim(query); //trim white space | |
| query = query.replace(/ /gi, '|'); //add OR for regex | |
| $(selector).each(function() { | |
| ($(this).text().search(new RegExp(query, "i")) < 0) ? $(this).hide().removeClass('visible') : $(this).show().addClass('visible'); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ul class="breadcrumb"> | |
| <li> | |
| <a href="{{URL::to('/dojo')}}">Home</a> | |
| <span class="divider">/</span> | |
| </li> | |
| <li> | |
| <a href="{{URL::to('/dojo/projects')}}" class="active">Projects</a> | |
| <span class="divider">/</span> | |
| </li> | |
| </ul> | |
| <div id="content" class="flex"> | |
| @if(Session::has('title')) | |
| <h1>{{ Session::get('message') }}</h1> | |
| @else | |
| <h1>List of projects</h1> | |
| @endif | |
| <ul class="object-tools pull-right"> | |
| <li> | |
| <a href="/dojo/projects/new" class="addlink btn btn-primary">Add Project</a> | |
| </li> | |
| </ul> | |
| @if(Session::has('message')) | |
| <div class="alert alert-error"> | |
| <p id="message">{{ Session::get('message') }}</p> | |
| </div> | |
| @endif | |
| </div> | |
| <div id="content-main"> | |
| <div class="module filtered" id="changelist"> | |
| <div class="navbar subnav"> | |
| <div class="navbar-inner"> | |
| <div class="container"> | |
| <a data-target=".navbar-responsive-collapse" data-toggle="collapse" class="btn btn-navbar"> | |
| <span class="icon-bar"></span> | |
| <span class="icon-bar"></span> | |
| <span class="icon-bar"></span> | |
| </a> | |
| <a href="#" title="Users" class="brand"> <i class="icon-th-list pull-left"></i> | |
| </a> | |
| <div class="nav-collapse collapse navbar-responsive-collapse pull-left" id="filters"> | |
| <div class="pull-right"> | |
| <ul class="nav"> | |
| <li class="dropdown"> | |
| <a data-toggle="dropdown" class="dropdown-toggle dropdown-filters" href="#"> | |
| Filters <b class="caret"></b> | |
| </a> | |
| <ul class="dropdown-menu"> | |
| <li class="nav-header">Filter</li> | |
| <li class="dropdown-submenu"> | |
| <a href="#">By draft status</a> | |
| <ul class="dropdown-menu"> | |
| <li class="active"> | |
| <a href="{{URL::to_route('dojo::index_project',array('index'))}}">All</a> | |
| </li> | |
| <li> | |
| <a href="{{URL::to_route('dojo::index_project',array('draft','1'))}}">Yes</a> | |
| </li> | |
| <li> | |
| <a href="{{URL::to_route('dojo::index_project',array('draft','0'))}}">No</a> | |
| </li> | |
| </ul> | |
| </li> | |
| <li class="dropdown-submenu"> | |
| <a href="#">Published</a> | |
| <ul class="dropdown-menu"> | |
| <li class="active"> | |
| <a href="{{URL::to_route('dojo::index_project',array('index'))}}">All</a> | |
| </li> | |
| <li> | |
| <a href="{{URL::to_route('dojo::index_project',array('published','1'))}}">Yes</a> | |
| </li> | |
| <li> | |
| <a href="{{URL::to_route('dojo::index_project',array('published','0'))}}">No</a> | |
| </li> | |
| </ul> | |
| </li> | |
| </ul> | |
| </li> | |
| </ul> | |
| </div> | |
| </div> | |
| <!-- /.nav-collapse --> | |
| <div class="pagination pull-left"> | |
| <ul></ul> | |
| </div> | |
| <div class="nav-collapse collapse navbar-responsive-collapse"> | |
| <div class="pull-right"> | |
| <div class="navbar-search pull-left" id="search-change-list"> | |
| <div class="input-append"> | |
| {{ Form::text('keyword', '', array('id'=>'keyword')) }} | |
| <button type="submit" class="btn">Search</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="clear"></div> | |
| <!-- /.nav-collapse --> </div> | |
| </div> | |
| <!-- /navbar-inner --> </div> | |
| <form id="changelist-form" action="" method="post" class="with-top-actions"> | |
| <div style='display:none'> | |
| {{Form::token()}} | |
| </div> | |
| <div class="well"> | |
| <span class="label label-inverse pull-left info-counter"> | |
| </span> | |
| <div class="divider"></div> | |
| <div class="actions pull-left"> | |
| <div class="input-append"> | |
| <label> | |
| <span>Action:</span> | |
| <select name="action" id="action"> | |
| <option value="" selected="selected">---------</option> | |
| <option value="delete_selected">Delete selected projects</option> | |
| <option value="publish_selected">Publish selected projects</option> | |
| <option value="draft_selected">Draft selected projects </option> | |
| </select> | |
| </label> | |
| <button type="submit" class="btn" title="Run the selected action" name="index" value="0">Go</button> | |
| </div> | |
| </div> | |
| <div class="actions pull-right"> | |
| </div> | |
| </div> | |
| <div class="results"> | |
| <table id="result_list" class="table table-striped table-hover"> | |
| <thead> | |
| <tr> | |
| <th>ID</th> | |
| <th>Title</th> | |
| <th>Published at</th> | |
| <th>Draft</th> | |
| <th>Visible</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| </tbody> | |
| </table> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| <br class="clear" /> | |
| <!-- END Content --> | |
| <div id="footer"></div> | |
| <!-- END Container --> | |
| <script type="text/javascript"> | |
| var BASE = "<?php echo URL::current(); ?>"; | |
| var TYPE = '<?php echo URL::to_route("dojo::edit_project") ?>'; | |
| console.log(TYPE); | |
| </script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment