Skip to content

Commit

Permalink
Merge branch 'LH_25' into suite_standard_edition
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Hoyt authored and Jonathan Hoyt committed Apr 10, 2009
2 parents 407d00b + 15fb88b commit 729e8ca
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/controllers/tickets_controller.rb
Expand Up @@ -3,7 +3,7 @@ class TicketsController < ApplicationController
before_filter :load_totals, :except => [:create, :update]

def index
@tickets = Ticket.limit(params[:status], params[:scope], current_user, params[:device])
@tickets = Ticket.limit(params[:status], current_user, params[:scope])

@tickets = @tickets.sort_by{|ticket| [ticket.status, ticket.id]}

Expand Down
19 changes: 15 additions & 4 deletions app/models/ticket.rb
Expand Up @@ -46,7 +46,10 @@ def owner
Client.find(self.client_id)
end

def self.limit(status, scope, user, device)
def self.limit(status, user, scope)
if scope == nil
scope = user.id
end
future = Date.today + 100.years
past = Date.today - 100.years
if status == nil || status == "open"
Expand All @@ -60,12 +63,20 @@ def self.limit(status, scope, user, device)
elsif status == "all"
conditions = {:archived_on => nil}
end
if scope == "user" || status == nil
conditions[:user_id] = user.id
end
if scope != "all" then conditions[:user_id] = User.find(scope) end
self.find(:all, :conditions => conditions)
end

def limit(scope)
new_array = ()
self.each do |ticket|
if ticket.user_id == scope

end
end
return self
end

def self.totals(user)
future = Date.today + 100.years
past = Date.today - 100.years
Expand Down
65 changes: 60 additions & 5 deletions app/views/layouts/tickets.html.erb
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Suite</title>
<%= javascript_include_tag "jquery", "jquery-ui" %>
<%= javascript_include_tag "jquery.metadata", "quicksilver", "jquery.quickselect" %>
<%= javascript_include_tag "jquery.metadata", "quicksilver", "jquery.quickselect", "jquery.url" %>
<%= javascript_include_tag "common", "tickets" %>
<%= stylesheet_link_tag "blueprint/screen", "jquery-theme", "common", "tickets", :media => "screen", :cache => "tickets-css-combined" %>
<%= stylesheet_link_tag "blueprint/print", "print", :media => "print", :cache => "print-css-combined" %>
Expand All @@ -27,15 +27,20 @@
<div id="sidebar">
<h2>Tickets</h2>
<ul class="m">
<li><a href="/tickets/?status=open&scope=user" class="open">Open</a><%= totals_helper(:open) %></li>
<li><a href="/tickets/?status=scheduled&scope=user" class="scheduled">Scheduled</a><%= totals_helper(:scheduled) %></li>
<li><a href="/tickets/?status=completed&scope=user" class="completed">Completed</a><%= totals_helper(:completed) %></li>
<li><a href="/tickets/?status=open" class="open">Open</a><%= totals_helper(:open) %></li>
<li><a href="/tickets/?status=scheduled" class="scheduled">Scheduled</a><%= totals_helper(:scheduled) %></li>
<li><a href="/tickets/?status=completed" class="completed">Completed</a><%= totals_helper(:completed) %></li>
<li><a href="/tickets/?status=all" class="all">All</a><%= totals_helper(:all) %></li>
<li><a href="/tickets/?status=archived" class="archived">Archived</a></li>
</ul>
</div>

<div id="center">
<div id="content_search">
<div id="applesearch"><form action="/tickets/search"><span class="sbox_l"></span><span class="sbox"><input type="search" id="srch_fld" name="q" placeholder="Search..." autosave="applestyle_srch" results="5" onkeyup="" /></span><span class="sbox_r" id="srch_clear"></span> <input id="srch_button" name="commit" type="submit" value="Search" onclick="" /></form></div>
<% @users = User.find(:all).collect {|c| [c.name, c.id]} %>
<div id="user_select"></div>
</div>
<%= yield %>
</div>

Expand All @@ -49,4 +54,54 @@
</div>
</div>
</body>
</html>
</html>

<script>
$(document).ready(function() {
// Put select box there as long as this isn't a search results or ticket show page
if($.url.segment(1)){
}else{
$('div#user_select').append("<select></select>");
};

// setup my select box for the technician we're viewing
var technicians = new Array();
var row = ""
var tech_id = ""
var tech_name = ""
<% User.find(:all, :order => 'updated_at desc').each do |technician| %>
tech_id = "<%= technician.id %>"
tech_name = "<%= technician.name %>"
technicians[tech_id] = tech_name;
row = '<option value='+tech_id+'>'+tech_name+'</option>'
$('div#user_select select').append(row);
<% end %>
row = '<option value="all">All</option>'
$('div#user_select select').append(row);

// Get the scope, set the select box to the correct value
var scope = $.url.param("scope");
if(scope*1){
$("div#user_select select").val(scope);
}else if(scope == 'all'){
$("div#user_select select").val(scope);
}else{
$("div#user_select select").val(<% current_user.id %>);
};

// Update page based on selection
var url = $.url.attr("source");
url = url.replace(/\/tickets(.*)$/, "/")
if($.url.param("status")){
var status = $.url.param("status");
}else{
var status = "open";
};
$('div#user_select select').change(function(){
scope = $(this).val()
url = url+"tickets/?status="+status+"&scope="+scope
window.location.replace(url);
})

});
</script>
4 changes: 0 additions & 4 deletions app/views/tickets/index.html.erb
@@ -1,7 +1,3 @@
<div id="content_search">
<div id="applesearch"><form action="/tickets/search"><span class="sbox_l"></span><span class="sbox"><input type="search" id="srch_fld" name="q" placeholder="Search..." autosave="applestyle_srch" results="5" onkeyup="" /></span><span class="sbox_r" id="srch_clear"></span> <input id="srch_button" name="commit" type="submit" value="Search" onclick="" /></form></div>
</div>

<div id="tickets">
<table total="<%= @tickets.length %>" class="itu">
<thead>
Expand Down
4 changes: 0 additions & 4 deletions app/views/tickets/search.html.erb
@@ -1,7 +1,3 @@
<div id="content_search">
<div id="applesearch"><form action="/tickets/search"><span class="sbox_l"></span><span class="sbox"><input type="search" id="srch_fld" name="q" placeholder="Search..." autosave="applestyle_srch" results="5" onkeyup="" /></span><span class="sbox_r" id="srch_clear"></span> <input id="srch_button" name="commit" type="submit" value="Search" onclick="" /></form></div>
</div>

<div id="tickets">
<table total="<%= @tickets.length %>" class="itu">
<thead>
Expand Down
214 changes: 214 additions & 0 deletions public/javascripts/jquery.url.js
@@ -0,0 +1,214 @@
/* ===========================================================================
*
* JQuery URL Parser
* Version 1.0
* Parses URLs and provides easy access to information within them.
*
* Author: Mark Perkins
* Author email: mark@allmarkedup.com
*
* For full documentation and more go to http://projects.allmarkedup.com/jquery_url_parser/
*
* ---------------------------------------------------------------------------
*
* CREDITS:
*
* Parser based on the Regex-based URI parser by Stephen Levithian.
* For more information (including a detailed explaination of the differences
* between the 'loose' and 'strict' pasing modes) visit http://blog.stevenlevithan.com/archives/parseuri
*
* ---------------------------------------------------------------------------
*
* LICENCE:
*
* Released under a MIT Licence. See licence.txt that should have been supplied with this file,
* or visit http://projects.allmarkedup.com/jquery_url_parser/licence.txt
*
* ---------------------------------------------------------------------------
*
* EXAMPLES OF USE:
*
* Get the domain name (host) from the current page URL
* jQuery.url.attr("host")
*
* Get the query string value for 'item' for the current page
* jQuery.url.param("item") // null if it doesn't exist
*
* Get the second segment of the URI of the current page
* jQuery.url.segment(2) // null if it doesn't exist
*
* Get the protocol of a manually passed in URL
* jQuery.url.setUrl("http://allmarkedup.com/").attr("protocol") // returns 'http'
*
*/

jQuery.url = function()
{
var segments = {};

var parsed = {};

/**
* Options object. Only the URI and strictMode values can be changed via the setters below.
*/
var options = {

url : window.location, // default URI is the page in which the script is running

strictMode: false, // 'loose' parsing by default

key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], // keys available to query

q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},

parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, // more intuitive, fails on relative paths and deviates from specs
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ //less intuitive, more accurate to the specs
}

};

/**
* Deals with the parsing of the URI according to the regex above.
* Written by Steven Levithan - see credits at top.
*/
var parseUri = function()
{
str = decodeURI( options.url );

var m = options.parser[ options.strictMode ? "strict" : "loose" ].exec( str );
var uri = {};
var i = 14;

while ( i-- ) {
uri[ options.key[i] ] = m[i] || "";
}

uri[ options.q.name ] = {};
uri[ options.key[12] ].replace( options.q.parser, function ( $0, $1, $2 ) {
if ($1) {
uri[options.q.name][$1] = $2;
}
});

return uri;
};

/**
* Returns the value of the passed in key from the parsed URI.
*
* @param string key The key whose value is required
*/
var key = function( key )
{
if ( ! parsed.length )
{
setUp(); // if the URI has not been parsed yet then do this first...
}
if ( key == "base" )
{
if ( parsed.port !== null && parsed.port !== "" )
{
return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/";
}
else
{
return parsed.protocol+"://"+parsed.host+"/";
}
}

return ( parsed[key] === "" ) ? null : parsed[key];
};

/**
* Returns the value of the required query string parameter.
*
* @param string item The parameter whose value is required
*/
var param = function( item )
{
if ( ! parsed.length )
{
setUp(); // if the URI has not been parsed yet then do this first...
}
return ( parsed.queryKey[item] === null ) ? null : parsed.queryKey[item];
};

/**
* 'Constructor' (not really!) function.
* Called whenever the URI changes to kick off re-parsing of the URI and splitting it up into segments.
*/
var setUp = function()
{
parsed = parseUri();

getSegments();
};

/**
* Splits up the body of the URI into segments (i.e. sections delimited by '/')
*/
var getSegments = function()
{
var p = parsed.path;
segments = []; // clear out segments array
segments = parsed.path.length == 1 ? {} : ( p.charAt( p.length - 1 ) == "/" ? p.substring( 1, p.length - 1 ) : path = p.substring( 1 ) ).split("/");
};

return {

/**
* Sets the parsing mode - either strict or loose. Set to loose by default.
*
* @param string mode The mode to set the parser to. Anything apart from a value of 'strict' will set it to loose!
*/
setMode : function( mode )
{
strictMode = mode == "strict" ? true : false;
return this;
},

/**
* Sets URI to parse if you don't want to to parse the current page's URI.
* Calling the function with no value for newUri resets it to the current page's URI.
*
* @param string newUri The URI to parse.
*/
setUrl : function( newUri )
{
options.url = newUri === undefined ? window.location : newUri;
setUp();
return this;
},

/**
* Returns the value of the specified URI segment. Segments are numbered from 1 to the number of segments.
* For example the URI http://test.com/about/company/ segment(1) would return 'about'.
*
* If no integer is passed into the function it returns the number of segments in the URI.
*
* @param int pos The position of the segment to return. Can be empty.
*/
segment : function( pos )
{
if ( ! parsed.length )
{
setUp(); // if the URI has not been parsed yet then do this first...
}
if ( pos === undefined )
{
return segments.length;
}
return ( segments[pos] === "" || segments[pos] === undefined ) ? null : segments[pos];
},

attr : key, // provides public access to private 'key' function - see above

param : param // provides public access to private 'param' function - see above

};

}();
2 changes: 1 addition & 1 deletion public/stylesheets/common.css
Expand Up @@ -67,7 +67,7 @@ div#container.login {width:600px;margin:auto;}
#center h4 {font-weight:bold;font-size:1.2em;color:#606060;margin:.5em 1em 0;padding:0px;}
#center p {margin:.5em 1.5em;padding:0px;}
#center ol.align, #center ul.align {margin:.5em 3em;padding:0px;}
div#content_search {padding:5px;background-color:#ccc;border-bottom:1px solid #505050;}
div#content_search {padding:5px;background-color:#ccc;border-bottom:1px solid #505050;position:relative;}

/* Tables */
table.itu {border-bottom:1px solid #505050;width:100%;}
Expand Down
5 changes: 3 additions & 2 deletions public/stylesheets/tickets.css
Expand Up @@ -15,7 +15,7 @@

/* ticket */
#ticket {margin:0 1em;padding:1.5em 0 0 0;}
#ticket table.details {position:absolute;right:1.5em;top:1em;}
#ticket table.details {position:absolute;right:1.5em;top:3.8em;}
#ticket div.description {width:50%;min-height:5em;}
div#ticket_entries {margin:1em;}
div.ticket_entry {position:relative;border-top:1px solid #ddd;padding:5px;}
Expand All @@ -42,4 +42,5 @@ input#ticket_active_on {width:8em;}
/* devices details pop up */

/* Search box */
#applesearch .sbox input {width:300px;}
#applesearch .sbox input {width:300px;}
div#user_select {position:absolute;top:3px;right:1em;}

0 comments on commit 729e8ca

Please sign in to comment.