parent
f2a301eba9
commit
9304e655b4
|
@ -8,13 +8,9 @@
|
|||
<li><a href="/account/">Account</a></li>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra-scripts %}
|
||||
<script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="snipts" id="snipts"></section>
|
||||
<section class="profile group" ng-app="Account" ng-controller="MainController">
|
||||
<section class="profile group" ng-controller="AccountController">
|
||||
<aside>
|
||||
<ul class="nav nav-list ng-cloak" ng-cloak>
|
||||
<li class="nav-header">Account</li>
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2004,7 +2004,14 @@ body.search {
|
|||
margin-bottom: 0;
|
||||
|
||||
input.search-query {
|
||||
width: 564px;
|
||||
width: 460px;
|
||||
}
|
||||
label.mine-only {
|
||||
margin: -7px 10px 0 10px;
|
||||
|
||||
input {
|
||||
margin-right: 7px;
|
||||
}
|
||||
}
|
||||
button {
|
||||
padding: 4px 16px 4px;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,3 +1,4 @@
|
|||
// Angular app init.
|
||||
(function() {
|
||||
|
||||
if (typeof angular !== 'undefined') {
|
||||
|
@ -5,11 +6,10 @@
|
|||
var root = this;
|
||||
var $ = root.jQuery;
|
||||
var controllers = {};
|
||||
var app = root.app;
|
||||
|
||||
// App definition.
|
||||
var app = angular.module('Account', [], function($routeProvider, $locationProvider) {
|
||||
|
||||
$locationProvider.html5Mode(true);
|
||||
// Configure account routes.
|
||||
app.config(function($routeProvider) {
|
||||
|
||||
// Routes.
|
||||
$routeProvider.when('/account/', {
|
||||
|
@ -29,11 +29,6 @@
|
|||
controller: controllers.EditorController
|
||||
});
|
||||
|
||||
// I have absolutely no idea why I need to do this. Angular shouldn't touch URLs
|
||||
// that don't match above. But for some reason, it does. So if you have a non-routed
|
||||
// URL inside of your controller, your browser won't redirect.
|
||||
//
|
||||
// -10 points, Angular.
|
||||
$routeProvider.otherwise({
|
||||
'redirectTo': function(routeParams, locationPath) {
|
||||
window.location = locationPath;
|
||||
|
@ -42,12 +37,6 @@
|
|||
|
||||
});
|
||||
|
||||
// Use non-Django-style interpolation.
|
||||
app.config(function($interpolateProvider) {
|
||||
$interpolateProvider.startSymbol('[[');
|
||||
$interpolateProvider.endSymbol(']]');
|
||||
});
|
||||
|
||||
// Services.
|
||||
app.factory('AccountStorage', function($http) {
|
||||
return {
|
||||
|
@ -142,7 +131,7 @@
|
|||
];
|
||||
|
||||
};
|
||||
controllers.MainController = function($scope, $route, AccountStorage) {
|
||||
controllers.AccountController = function($scope, $route, AccountStorage) {
|
||||
$scope.errors = [];
|
||||
$scope.saveButtonText = 'Save';
|
||||
$scope.route = $route;
|
||||
|
|
|
@ -18,3 +18,27 @@ jQuery(function($) {
|
|||
window.site = new SiteView();
|
||||
|
||||
});
|
||||
|
||||
// Angular app init.
|
||||
(function() {
|
||||
|
||||
if (typeof angular !== 'undefined') {
|
||||
|
||||
var root = this;
|
||||
|
||||
// App definition.
|
||||
var app = angular.module('Snipt', [], function($locationProvider) {
|
||||
$locationProvider.html5Mode(true);
|
||||
});
|
||||
|
||||
// Use non-Django-style interpolation.
|
||||
app.config(function($interpolateProvider) {
|
||||
$interpolateProvider.startSymbol('[[');
|
||||
$interpolateProvider.endSymbol(']]');
|
||||
});
|
||||
|
||||
root.app = app;
|
||||
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
(function() {
|
||||
|
||||
if (typeof angular !== 'undefined') {
|
||||
|
||||
var root = this;
|
||||
var $ = root.jQuery;
|
||||
var controllers = {};
|
||||
var app = root.app;
|
||||
|
||||
// Services.
|
||||
app.factory('SearchService', function() {
|
||||
return {
|
||||
mineOnly: false,
|
||||
query: ''
|
||||
};
|
||||
});
|
||||
|
||||
// Controllers.
|
||||
controllers.HeaderSearchController = function($scope, SearchService) {
|
||||
|
||||
$scope.search = SearchService;
|
||||
|
||||
};
|
||||
controllers.SearchController = function($scope, SearchService) {
|
||||
|
||||
$scope.search = SearchService;
|
||||
|
||||
$scope.$watch('search.query', function(query) {
|
||||
if (query.indexOf('--mine') !== -1) {
|
||||
$scope.search.mineOnly = true;
|
||||
} else {
|
||||
$scope.search.mineOnly = false;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.toggleMineOnly = function() {
|
||||
if ($scope.search.mineOnly) {
|
||||
|
||||
// Make sure '--mine' exists somewhere in the query.
|
||||
if ($scope.search.query.indexOf('--mine') === -1) {
|
||||
$scope.search.query = $scope.search.query.trim() + ' --mine';
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$scope.search.query = $scope.search.query.replace('--mine', '').trim();
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// Assign the controllers.
|
||||
app.controller(controllers);
|
||||
|
||||
}
|
||||
|
||||
}).call(this);
|
|
@ -1,4 +1,4 @@
|
|||
from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, render_to_response
|
||||
from django.core.paginator import Paginator, InvalidPage
|
||||
from annoying.functions import get_object_or_None
|
||||
|
@ -263,12 +263,22 @@ def rss(request, context):
|
|||
mimetype="application/rss+xml"
|
||||
)
|
||||
|
||||
def search(request, template='search/search.html', load_all=True, form_class=ModelSearchForm, searchqueryset=None, context_class=RequestContext, extra_context=None, results_per_page=None):
|
||||
def search(request, template='search/search.html', load_all=True,
|
||||
form_class=ModelSearchForm, searchqueryset=None,
|
||||
context_class=RequestContext, extra_context=None,
|
||||
results_per_page=None):
|
||||
|
||||
query = ''
|
||||
results = EmptySearchQuerySet()
|
||||
|
||||
# We have a query.
|
||||
if request.GET.get('q'):
|
||||
searchqueryset = SearchQuerySet().filter(Q(public=True) | Q(author=request.user)).order_by('-pub_date')
|
||||
|
||||
if request.user.profile.is_pro and '--mine' in request.GET.get('q'):
|
||||
searchqueryset = SearchQuerySet().filter(author=request.user).order_by('-pub_date')
|
||||
else:
|
||||
searchqueryset = SearchQuerySet().filter(Q(public=True) | Q(author=request.user)).order_by('-pub_date')
|
||||
|
||||
form = ModelSearchForm(request.GET, searchqueryset=searchqueryset, load_all=load_all)
|
||||
|
||||
if form.is_valid():
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% load snipt_tags intercom %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" class="{% block html-class %}{% endblock %}">
|
||||
<html lang="en" class="{% block html-class %}{% endblock %}" ng-app="Snipt">
|
||||
<head>
|
||||
|
||||
<title>{% block page-title %}Snipt{% endblock %}</title>
|
||||
|
@ -64,8 +64,9 @@
|
|||
<script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
|
||||
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
|
||||
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
|
||||
|
||||
</head>
|
||||
<body class="{% block body-class %}{% endblock %} {% if request.user.profile.is_pro %}is-pro{% endif %}">
|
||||
|
@ -74,10 +75,13 @@
|
|||
<div class="inner">
|
||||
<div class="shadey"></div>
|
||||
<h1 class="main-logo"><a href="{% if request.user.is_authenticated %}/{{ request.user.username }}/{% else %}/{% endif %}">snip<span>t</span></a></h1>
|
||||
<form class="search" action="/search/" method="get">
|
||||
<form class="search" action="/search/" method="get" ng-controller="HeaderSearchController">
|
||||
<fieldset>
|
||||
<div class="fields">
|
||||
<input type="text" id="search-query" name="q" value="{{ query }}" placeholder="Search snipts" />
|
||||
<input ng-model="search.query" type="text" class="search-query" name="q"
|
||||
ng-init="search.query='{{ query }}'"
|
||||
placeholder="Search snipts" id="id_q"
|
||||
value="{{ query }}" />
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
@ -373,12 +377,13 @@
|
|||
<script type="text/javascript" src="{{ STATIC_URL }}js/plugins/jquery.hotkeys.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/plugins/jquery.infieldlabel.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/plugins/jquery.chosen.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/src/account.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/libs/codemirror.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/libs/highlight.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/src/application.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/src/modules/site.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/src/modules/snipt.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/src/account.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/src/search.js"></script>
|
||||
{% else %}
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/snipt-all.min.js?48"></script>
|
||||
{% endif %}
|
||||
|
|
|
@ -16,11 +16,22 @@
|
|||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block extra-scripts %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="snipts" id="snipts"></section>
|
||||
<div class="static-box {% if page.object_list|length > 0 %}has-snipts{% endif %}">
|
||||
<form method="get" class="form-search" action=".">
|
||||
<input type="text" class="search-query" name="q" value="{% if form.q.value %}{{ form.q.value }}{% endif %}" placeholder="Search snipts" id="id_q">
|
||||
<form method="get" class="form-search" action="." ng-controller="SearchController">
|
||||
<input ng-model="search.query" type="text" class="search-query" name="q"
|
||||
ng-init="search.query='{{ query }}'"
|
||||
placeholder="Search snipts" id="id_q"
|
||||
value="{{ query }}" />
|
||||
{% if request.user.profile.is_pro %}
|
||||
<label class="checkbox inline mine-only" ng-click="toggleMineOnly()">
|
||||
<input {% if '--mine' in query %}checked="checked"{% endif %} ng-model="search.mineOnly" type="checkbox" id="inlineCheckbox1" value="option1"> Mine only
|
||||
</label>
|
||||
{% endif %}
|
||||
<button type="submit" class="btn">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue