-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
351 additions
and
347 deletions.
There are no files selected for viewing
File renamed without changes.
175 changes: 0 additions & 175 deletions
175
...ets/javascripts/jquery.filterable_list.js → ...filterable_list/jquery.filterable_list.js
This file contains 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
29 changes: 29 additions & 0 deletions
29
app/assets/javascripts/jquery.filterable_list/query_field.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(function($){ | ||
|
||
$.PMX.QueryField = function(el) { | ||
var base = this; | ||
|
||
base.$el = $(el); | ||
base.previousTerm = ''; | ||
|
||
base.bindEvents = function() { | ||
base.$el.on('keyup', base.handleChange); | ||
}; | ||
|
||
base.handleChange = function() { | ||
if (base.getTerm().length > 2 && base.getTerm() !== base.previousTerm) { | ||
base.changeCallback.call(base, base.getTerm()); | ||
base.previousTerm = base.getTerm(); | ||
} | ||
}; | ||
|
||
base.onChange = function(callback) { | ||
base.changeCallback = callback; | ||
}; | ||
|
||
base.getTerm = function() { | ||
return base.$el.val(); | ||
}; | ||
}; | ||
|
||
})(jQuery); |
51 changes: 51 additions & 0 deletions
51
app/assets/javascripts/jquery.filterable_list/search_results.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(function($){ | ||
|
||
$.PMX.SearchResults = function(url, limit) { | ||
var base = this; | ||
|
||
base.url = url; | ||
base.limit = limit; | ||
base.templatesXhr = null; | ||
base.localImagesXhr = null; | ||
base.remoteImagesXhr = null; | ||
|
||
base.fetch = function(term) { | ||
if (base.templatesXhr) { base.templatesXhr.abort(); } | ||
if (base.localImagesXhr) { base.localImagesXhr.abort(); } | ||
if (base.remoteImagesXhr) { base.remoteImagesXhr.abort(); } | ||
|
||
base.templatesXhr = base.fetchForType(term, 'template'); | ||
base.localImagesXhr = base.fetchForType(term, 'local_image'); | ||
base.remoteImagesXhr = base.fetchForType(term, 'remote_image'); | ||
}; | ||
|
||
base.templates = function(callback) { | ||
base.templatesXhr.done(function(response, status) { | ||
callback.call(this, response.templates); | ||
}); | ||
}; | ||
|
||
base.localImages = function(callback) { | ||
base.localImagesXhr.done(function(response, status) { | ||
callback.call(this, response.local_images); | ||
}); | ||
}; | ||
|
||
base.remoteImages = function(callback) { | ||
base.remoteImagesXhr.done(function(response, status) { | ||
callback.call(this, response.remote_images); | ||
}); | ||
}; | ||
|
||
base.fetchForType = function(term, type) { | ||
return $.ajax({ | ||
url: base.url, | ||
data: { | ||
'search_result_set[q]': term, | ||
'search_result_set[type]': type, | ||
'search_result_set[limit]': base.limit | ||
} | ||
}); | ||
}; | ||
}; | ||
})(jQuery); |
100 changes: 100 additions & 0 deletions
100
app/assets/javascripts/jquery.filterable_list/template_details_dialog.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//= require jquery.ui.dialog | ||
|
||
(function($){ | ||
$.PMX.TemplateDetailsDialog = function(el, options) { | ||
var base = this; | ||
|
||
base.$el = $(el); | ||
base.xhr = null; | ||
|
||
base.defaultOptions = { | ||
$modalContents: $('#template-details-dialog'), | ||
$titlebarCloseButton: $('button.ui-dialog-titlebar-close'), | ||
$templateRow: $('#template_' + options.template_id), | ||
buttonSelector: '.actions button.button-positive', | ||
dialogContentSelector: '.ui-dialog-content', | ||
loadingTemplate: Handlebars.compile($('#loading_row_template').html()) | ||
}; | ||
|
||
base.init = function() { | ||
base.options = $.extend({}, base.defaultOptions, options); | ||
base.initiateDialog(); | ||
}; | ||
|
||
base.calculateHeight = function() { | ||
var browserHeight = $( window ).height(); | ||
return Math.ceil(browserHeight * 0.9); | ||
}; | ||
|
||
base.initiateDialog = function () { | ||
base.defaultOptions.$modalContents.dialog({ | ||
dialogClass: 'template-details-dialog', | ||
autoOpen: false, | ||
modal: true, | ||
resizable: false, | ||
draggable: true, | ||
width: 860, | ||
height: base.calculateHeight(), | ||
position: ["top", 50], | ||
title: 'Template Details', | ||
close: base.handleClose, | ||
open: base.fetchTemplateDetails, | ||
buttons: [ | ||
{ | ||
text: "Run Template", | ||
class: 'button-positive', | ||
click: base.handleSubmit | ||
}, | ||
{ | ||
text: "Dismiss", | ||
class: 'button-secondary', | ||
click: base.handleClose | ||
} | ||
] | ||
}); | ||
|
||
// must set height here or jQueryUI sets inline style to auto | ||
base.defaultOptions.$modalContents.find(base.options.dialogContentSelector).css('height', '100%'); | ||
|
||
}; | ||
|
||
base.handleClose = function () { | ||
base.defaultOptions.$modalContents.dialog("close"); | ||
base.options.$modalContents.html(''); | ||
$('body').css('overflow', 'auto'); | ||
}; | ||
|
||
base.showTemplateDialog = function() { | ||
base.defaultOptions.$modalContents.dialog("open"); | ||
}; | ||
|
||
base.fetchTemplateDetails = function() { | ||
base.displayLoadingIndicator(); | ||
if (base.xhr) { | ||
base.xhr.abort(); | ||
} | ||
|
||
base.xhr = $.ajax({ | ||
url: base.options.url, | ||
dataType: 'html' | ||
}); | ||
|
||
base.xhr.done(function(response, status) { | ||
base.options.$modalContents.html(response); | ||
}); | ||
}; | ||
|
||
base.displayLoadingIndicator = function() { | ||
var forDetails = base.options.loadingTemplate({loading_copy: 'Loading Template Details'}); | ||
base.options.$modalContents.html(forDetails); | ||
}; | ||
|
||
base.handleSubmit = function(e) { | ||
var $actionsFormSubmit = base.options.$templateRow.find(base.options.buttonSelector); | ||
e.preventDefault(); | ||
|
||
$actionsFormSubmit.click(); | ||
base.handleClose(); | ||
}; | ||
}; | ||
})(jQuery); |
File renamed without changes.
Oops, something went wrong.