Skip to content

Commit

Permalink
Merge branch 'chore/js-file-naming'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwelch committed Sep 11, 2014
2 parents 4b101a2 + 5d77f6e commit ee9d101
Show file tree
Hide file tree
Showing 9 changed files with 351 additions and 347 deletions.
Original file line number Diff line number Diff line change
@@ -1,180 +1,5 @@
//= require jquery.ui.dialog

(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();
};
};


$.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
}
});
};
};

$.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();
};
};

$.PMX.FilterableList = function(el, options) {
var base = this;

Expand Down
29 changes: 29 additions & 0 deletions app/assets/javascripts/jquery.filterable_list/query_field.js
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 app/assets/javascripts/jquery.filterable_list/search_results.js
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);
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);
Loading

0 comments on commit ee9d101

Please sign in to comment.