Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

popover working, started the modal

  • Loading branch information...
commit f0fa2a85998b03dd0d7f5ec7b2e5454adb9bb39b 1 parent ea22485
@danpalmer danpalmer authored
Showing with 52 additions and 33 deletions.
  1. +0 −13 css/style.css
  2. +5 −11 index.html
  3. +47 −9 js/projectviz.js
View
13 css/style.css
@@ -1,16 +1,3 @@
-#modal-test {
- margin: 50px auto 40px auto;
-}
-
-#modal-test .modal {
- position: relative;
- top: auto;
- left: auto;
- margin: 0 auto;
- z-index: 1;
- max-width: 100%;
-}
-
.project-info-trigger {
color:red;
}
View
16 index.html
@@ -13,6 +13,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
<script src="js/bootstrap.min.js"></script>
+ <script src="js/sparql/sparql.js"></script>
<link rel="stylesheet" href="css/style.css">
@@ -28,7 +29,7 @@
Your bones don't break, mine do. That's clear. Your cells react to bacteria and viruses differently than mine. You don't get sick, I do. That's also clear. But for some reason, you and I react the exact same way to water. We swallow it too fast, we choke. We get some in our lungs, we drown. However unreal it may seem, we are connected, you and I. We're on the same curve, just on opposite ends.
<h3>Uuummmm, this is a tasty burger!</h3>
- Now that there is the Tec-9, a crappy spray gun from <span class="project-info-trigger" data-itai="GB-1-113933">Unicef Water and Sanitation</span>. This gun is advertised as the most popular gun in American crime. Do you believe that shit? It actually says that in the little book that comes with it: the most popular gun in American crime. Like they're actually proud of that shit.
+ Now that there is the Tec-9, a crappy spray gun from <a class="project-info-trigger" data-itai="GB-1-113933">Unicef Water and Sanitation</a>. This gun is advertised as the most popular gun in American crime. Do you believe that shit? It actually says that in the little book that comes with it: the most popular gun in American crime. Like they're actually proud of that shit.
<h3>Hold on to your butts</h3>
Look, just because I don't be givin' no man a foot massage don't make it right for Marsellus to throw Antwone into a glass motherfuckin' house, fuckin' up the way the nigger talks. Motherfucker do that shit to me, he better paralyze my ass, 'cause I'll kill the motherfucker, know what I'm sayin'?
@@ -41,8 +42,6 @@
</div>
<script type="application/x-underscore-template" id="project-retrieve-sparql-template">
- PREFIX dc: <http://purl.org/dc/elements/1.1/>
- PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX iati: <http://tools.aidinfolabs.org/linked-iati/def/iati-1.01#>
PREFIX activity: <http://data.kasabi.com/dataset/iati/activity/>
@@ -55,7 +54,6 @@
</script>
<script type="application/x-underscore-template" id="transaction-retrieve-sparql-template">
- PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX iati: <http://tools.aidinfolabs.org/linked-iati/def/iati-1.01#>
PREFIX activity: <http://data.kasabi.com/dataset/iati/activity/>
@@ -69,7 +67,7 @@
</script>
<script type="application/x-underscore-template" id="project-view-template">
- <div class="modal">
+ <div class="modal hide" id="<%= id %>">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="project-name">Project Name <small class="charity-name">Charity Name</small></h3>
@@ -85,16 +83,12 @@ <h3 class="project-name">Project Name <small class="charity-name">Charity Name</
</script>
<script type="application/x-underscore-template" id="project-popover-template">
- <% if (id) { %>
- <%= id %>
- <% } else { %>
- ID Not Found
- <% } %>
+ <%= description %>
</script>
<script>
$(function() {
- $('.project-info-trigger').projectViz();
+ $('.project-info-trigger').projectViz('http://api.kasabi.com/dataset/iati/apis/sparql?apikey=92912a588c30a6617ac21a69412b9a22f7f6e34d');
});
</script>
View
56 js/projectviz.js
@@ -1,8 +1,11 @@
(function( $ ){
var Project = Backbone.Model.extend({});
+
+ // Templates
var projectViewTemplate = $('#project-view-template').html();
var projectPopoverTemplate = $('#project-popover-template').html();
+ var projectRetrieveSparqlTemplate = $('#project-retrieve-sparql-template').html();
var ProjectView = Backbone.View.extend({
tagName: 'div',
@@ -28,12 +31,13 @@
render: function() {
var attributes = this.model.toJSON();
+ console.log(attributes);
this.$el.html(this.template(attributes));
return this;
},
});
- $.fn.projectViz = function( type ) {
+ $.fn.projectViz = function( url ) {
return this.each(function() {
var $this = $(this);
@@ -42,16 +46,50 @@
var project = new Project();
project.set({id:$this.attr('data-itai')});
- // TODO: get more data from query
+ var sparql = new SPARQL.Service(url);
+ sparql.setPrefix("foaf", "http://xmlns.com/foaf/0.1/");
+ sparql.setPrefix("dct", "http://purl.org/dc/terms/");
+ sparql.setPrefix("rdfs", 'http://www.w3.org/2000/01/rdf-schema#');
+ sparql.setPrefix('owl', 'http://www.w3.org/2002/07/owl#');
+ sparql.setPrefix('dc', 'http://purl.org/dc/elements/1.1/');
+ sparql.setOutput('json');
+ sparql.setMethod('POST');
+
+ var query = sparql.createQuery();
+ query.query(
+ _.template(projectRetrieveSparqlTemplate)({project_id:project.id}),
+ {
+ success: function(json) {
+
+ project.set({
+ description: json.results.bindings[0].description.value,
+ title: json.results.bindings[0].title.value
+ });
+
+ var projectPopover = new ProjectPopover({
+ model:project
+ }).render();
+
+ $this.popover({
+ title: project.get('title'),
+ content: projectPopover.el
+ });
+
+ var projectView = new ProjectView({
+ model:project
+ }).render();
+
+ $('body').append(projectView.el);
+ $this.attr('data-toggle', project.get('id'));
+ },
+
+ failure: function() {
+ console.log('Oops, something went wrong. <sadface.jpg>');
+ }
+ }
+ );
- var projectPopover = new ProjectPopover({
- model:project
- }).render();
- $this.popover({
- title:'Test',
- content: projectPopover.el
- });
});
};
Please sign in to comment.
Something went wrong with that request. Please try again.