Skip to content
Snippets Groups Projects
Commit 05f3c829 authored by Chris Hallberg's avatar Chris Hallberg
Browse files

Lightbox fixes. Export, saving, collapsing. Part 1 of 2.

parent 2707d318
No related merge requests found
...@@ -42,6 +42,7 @@ function changeModalContent(html) { ...@@ -42,6 +42,7 @@ function changeModalContent(html) {
*/ */
function closeLightbox() { function closeLightbox() {
$('#modal').modal('hide'); $('#modal').modal('hide');
cartAction = false;
} }
/** /**
* This function is attached to the lightbox close event, * This function is attached to the lightbox close event,
...@@ -170,8 +171,10 @@ function getLightboxByUrl(url, post, callback, pop) { ...@@ -170,8 +171,10 @@ function getLightboxByUrl(url, post, callback, pop) {
changeModalContent(html); changeModalContent(html);
} }
}, },
error:function(d,e) { error:function(d,e, xhr, $form) {
//window.location.replace(url);
console.log(url,e,d); // Error reporting console.log(url,e,d); // Error reporting
console.log(xhr);
} }
}); });
// Store current "page" context for empty targets // Store current "page" context for empty targets
...@@ -203,24 +206,16 @@ function getLightbox(controller, action, get, post, callback, pop) { ...@@ -203,24 +206,16 @@ function getLightbox(controller, action, get, post, callback, pop) {
/** /**
* Call this function after a form is submitted * Call this function after a form is submitted
*/ */
function ajaxSubmit($form, callback) { var cartAction = false;
// Default callback is to close function getDataFromForm($form) {
if(!callback) {
if(callbackStack.length > 0) {
callback = callbackStack.pop();
//console.log("Pop:",callback);
} else {
callback = closeLightbox;
}
}
// Gather all the data // Gather all the data
var inputs = $form.find('*[name]'); var inputs = $form.find('*[name]');
var data = {}; var data = {};
for(var i=0;i<inputs.length;i++) { for(var i=0;i<inputs.length;i++) {
var currentName = inputs[i].name; var currentName = inputs[i].name;
var array = currentName.substring(currentName.length-2) == '[]'; var array = currentName.substring(currentName.length-2) == '[]';
if(array && !data[currentName]) { if(array && !data[currentName.substring(0,currentName.length-2)]) {
data[currentName] = []; data[currentName.substring(0,currentName.length-2)] = [];
} }
// Submit buttons // Submit buttons
if(inputs[i].type == 'submit') { if(inputs[i].type == 'submit') {
...@@ -231,7 +226,8 @@ function ajaxSubmit($form, callback) { ...@@ -231,7 +226,8 @@ function ajaxSubmit($form, callback) {
} else if(inputs[i].type == 'radio') { } else if(inputs[i].type == 'radio') {
if(inputs[i].checked) { if(inputs[i].checked) {
if(array) { if(array) {
data[currentName][data[currentName].length] = inputs[i].value; var n = currentName.substring(0,currentName.length-2);
data[n].push(inputs[i].value);
} else { } else {
data[currentName] = inputs[i].value; data[currentName] = inputs[i].value;
} }
...@@ -239,12 +235,27 @@ function ajaxSubmit($form, callback) { ...@@ -239,12 +235,27 @@ function ajaxSubmit($form, callback) {
// Checkboxes // Checkboxes
} else if($(inputs[i]).attr('type') != 'checkbox' || inputs[i].checked) { } else if($(inputs[i]).attr('type') != 'checkbox' || inputs[i].checked) {
if(array) { if(array) {
data[currentName][data[currentName].length] = inputs[i].value; var n = currentName.substring(0,currentName.length-2);
data[n].push(inputs[i].value);
} else { } else {
data[currentName] = inputs[i].value; data[currentName] = inputs[i].value;
} }
} }
} }
return data;
}
function ajaxSubmit($form, callback) {
cartAction = $form.attr('name');
// Default callback is to close
if(!callback) {
if(callbackStack.length > 0) {
callback = callbackStack.pop();
//console.log("Pop:",callback);
} else {
callback = closeLightbox;
}
}
var data = getDataFromForm($form);
// If we have an action: parse // If we have an action: parse
var POST = $form.attr('method') && $form.attr('method').toUpperCase() == 'POST'; var POST = $form.attr('method') && $form.attr('method').toUpperCase() == 'POST';
if($form.attr('action')) { if($form.attr('action')) {
...@@ -271,6 +282,7 @@ function ajaxSubmit($form, callback) { ...@@ -271,6 +282,7 @@ function ajaxSubmit($form, callback) {
*/ */
// Logging in // Logging in
function ajaxLogin(form) { function ajaxLogin(form) {
console.log('ajaxLogin');
$.ajax({ $.ajax({
url: path + '/AJAX/JSON?method=getSalt', url: path + '/AJAX/JSON?method=getSalt',
dataType: 'json', dataType: 'json',
...@@ -347,19 +359,15 @@ function ajaxLogin(form) { ...@@ -347,19 +359,15 @@ function ajaxLogin(form) {
} }
}); });
} }
// and we update the modal // and we update the modal
if(callbackStack.length > 0) { if(!cartAction && callbackStack.length > 0) {
var callback = callbackStack.pop(); var callback = callbackStack.pop();
//console.log("Pop:",callback); //console.log("Pop:",callback);
if(callback == changeModalContent) { // We don't have good data for changeModalContent callback();
getLightboxByUrl(lastLightboxURL, lastLightboxPOST);
} else {
callback();
}
} else if(lastLightboxPOST && lastLightboxPOST['loggingin']) { } else if(lastLightboxPOST && lastLightboxPOST['loggingin']) {
closeLightbox(); closeLightbox();
} else { } else {
console.log('lastLightboxPOST', lastLightboxPOST);
getLightboxByUrl(lastLightboxURL, lastLightboxPOST); getLightboxByUrl(lastLightboxURL, lastLightboxPOST);
} }
} else { } else {
...@@ -375,31 +383,12 @@ function ajaxLogin(form) { ...@@ -375,31 +383,12 @@ function ajaxLogin(form) {
} }
// Cart submission // Cart submission
function cartSubmit($form) { function cartSubmit($form) {
var submit = $form.find('input[type="submit"][clicked=true]').attr('name'); var submit = $form.find('input[type="submit"][clicked=true]').attr('name');
switch(submit) { switch(submit) {
case 'saveCart':
case 'email':
case 'export':
ajaxSubmit($form, changeModalContent);
break;
case 'delete':
case 'empty':
ajaxSubmit($form, closeLightbox);
break;
case 'print': case 'print':
//redirect page //redirect page
var checks = $form.find('input.checkbox-select-item:checked'); var checks = $form.find('input.checkbox-select-item:checked');
if(checks.length == 0) { if(checks.length > 0) {
$.ajax({
url:path+'/Cart/PrintCart',
data:{},
success:function(html) {
var newDoc = document.open("text/html", "replace");
newDoc.write(html);
newDoc.close();
}
});
} else {
var url = path+'/Records/Home?print=true'; var url = path+'/Records/Home?print=true';
for(var i=0;i<checks.length;i++) { for(var i=0;i<checks.length;i++) {
url += '&id[]='+checks[i].value; url += '&id[]='+checks[i].value;
...@@ -407,6 +396,8 @@ function cartSubmit($form) { ...@@ -407,6 +396,8 @@ function cartSubmit($form) {
window.location.replace(url); window.location.replace(url);
} }
break; break;
default:
ajaxSubmit($form, changeModalContent);
} }
} }
...@@ -458,14 +449,40 @@ function registerModalForms(modal) { ...@@ -458,14 +449,40 @@ function registerModalForms(modal) {
cartSubmit($(this)); cartSubmit($(this));
return false; return false;
}); });
$(modal).find('form[name="newList"]').unbind('submit').submit(function(){ $(modal).find('form[name="bulkSave"]').unbind('submit').submit(function(){
ajaxSubmit($(this), changeModalContent); ajaxSubmit($(this), function() {
changeModalContent('<div class="alert alert-info">'+vufindString['bulk_save_success']+'</div><button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>');
});
callbackStack.unshift(function() {
window.location.replace(path+'/MyResearch/MyList/'+lastLightboxPOST['list']);
});
return false;
});
$(modal).find('form[name="exportForm"]').unbind('submit').submit(function(){
var form = $(this);
$.ajax({
url: path + '/AJAX/JSON?' + $.param({method:'exportFavorites'}),
type:'POST',
dataType:'json',
data:getDataFromForm($(this)),
success:function(data) {
changeModalContent(data.data.result_additional);
},
error:function(d,e) {
console.log(d,e); // Error reporting
}
});
//ajaxSubmit($(this), changeModalContent);
return false; return false;
}); });
$(modal).find('form[name="loginForm"]').unbind('submit').submit(function(){ $(modal).find('form[name="loginForm"]').unbind('submit').submit(function(){
ajaxLogin(this); ajaxLogin(this);
return false; return false;
}); });
$(modal).find('form[name="newList"]').unbind('submit').submit(function(){
ajaxSubmit($(this), changeModalContent);
return false;
});
} }
/** /**
* This is where you add click events to open the lightbox. * This is where you add click events to open the lightbox.
......
<p> <a class="btn btn-primary" href="<?=$this->escapeHtml($this->url)?>"<?=$this->export()->needsRedirect($this->format) ? ' target="_blank"' : ''?>><?=
<a href="<?=$this->escapeHtml($this->url)?>"<?=$this->export()->needsRedirect($this->format) ? ' target="_blank"' : ''?>><?=
$this->export()->needsRedirect($this->format) $this->export()->needsRedirect($this->format)
? $this->transEsc('export_redirect', array('%%service%%' => $this->translate($this->format))) ? $this->transEsc('export_redirect', array('%%service%%' => $this->translate($this->format)))
: $this->transEsc('export_download') : $this->transEsc('export_download')
?></a> ?></a>
</p>
...@@ -10,14 +10,24 @@ ...@@ -10,14 +10,24 @@
<?=$this->flashmessages()?> <?=$this->flashmessages()?>
<form class="form-horizontal" action="<?=$this->url('cart-email')?>" method="post" name="bulkEmail"> <form class="form-horizontal" action="<?=$this->url('cart-email')?>" method="post" name="bulkEmail">
<? foreach ($this->records as $current): ?> <? foreach ($this->records as $current): ?>
<div class="control-group"> <input type="hidden" name="ids[]" value="<?=$this->escapeHtml($current->getResourceSource() . '|' . $current->getUniqueId())?>" />
<label class="control-label"><?=$this->transEsc('Title')?></label> <? endforeach; ?>
<div class="controls"> <div class="control-group">
<span class="uneditable-input"><?=$this->escapeHtml($current->getBreadcrumb())?></span> <label class="control-label"><?=$this->transEsc('Title')?></label>
<input type="hidden" name="ids[]" value="<?=$this->escapeHtml($current->getResourceSource() . '|' . $current->getUniqueId())?>" /> <div class="controls">
<? if(count($this->records) > 3): ?>
<div class="item-list">
<ul>
<? foreach ($this->records as $current): ?>
<li><?=$this->escapeHtml($current->getBreadcrumb())?></li>
<? endforeach; ?>
</ul>
</div> </div>
<? else: ?>
<span class="uneditable-input"><?=$this->records[0]->getBreadcrumb() ?></span>
<? endif; ?>
</div> </div>
<? endforeach; ?> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="email_to"><?=$this->transEsc('To')?>:</label> <label class="control-label" for="email_to"><?=$this->transEsc('To')?>:</label>
<div class="controls"> <div class="controls">
...@@ -44,3 +54,14 @@ ...@@ -44,3 +54,14 @@
</div> </div>
</div> </div>
</form> </form>
<?
$items = $this->transEsc('items');
$script = <<<JS
var list = $('.item-list');
var items = list.find('li').length;
var bubble = list.html();
list.html('<span class="btn">'+items+' {$items}</span>');
list.find('.btn').popover({html:true,content:bubble});
JS;
?>
<?=$this->inlineScript(\Zend\View\Helper\HeadScript::SCRIPT, $script, 'SET') ?>
\ No newline at end of file
...@@ -14,17 +14,49 @@ ...@@ -14,17 +14,49 @@
<? if (!empty($this->exportOptions)): ?> <? if (!empty($this->exportOptions)): ?>
<form class="form-inline" method="post" action="<?=$this->url('cart-export')?>" name="exportForm" title="<?=$this->transEsc('Export Items')?>"> <form class="form-inline" method="post" action="<?=$this->url('cart-export')?>" name="exportForm" title="<?=$this->transEsc('Export Items')?>">
<? foreach ($this->records as $current): ?> <? foreach ($this->records as $current): ?>
<strong><?=$this->transEsc('Title')?>:</strong> <?=$this->escapeHtml($current->getBreadcrumb())?><br />
<input type="hidden" name="ids[]" value="<?=$this->escapeHtml($current->getResourceSource() . '|' . $current->getUniqueId())?>" /> <input type="hidden" name="ids[]" value="<?=$this->escapeHtml($current->getResourceSource() . '|' . $current->getUniqueId())?>" />
<? endforeach; ?> <? endforeach; ?>
<br /> <div class="control-group">
<label for="format"><?=$this->transEsc('Format')?>:</label> <label class="control-label"><?=$this->transEsc('Title')?></label>
<select name="format" id="format"> <div class="controls">
<? foreach ($this->exportOptions as $exportOption): ?> <? if(count($this->records) > 3): ?>
<option value="<?=$this->escapeHtml($exportOption)?>"><?=$this->transEsc($exportOption)?></option> <div class="item-list">
<? endforeach; ?> <ul>
</select> <? foreach ($this->records as $current): ?>
<br/><br/> <li><?=$this->escapeHtml($current->getBreadcrumb())?></li>
<input class="btn" type="submit" name="submit" value="<?=$this->transEsc('Export') ?>"/> <? endforeach; ?>
</ul>
</div>
<? else: ?>
<span class="uneditable-input"><?=$this->records[0]->getBreadcrumb() ?></span>
<? endif; ?>
</div>
</div>
<div class="control-group">
<label class="control-label" for="format"><?=$this->transEsc('Format')?>:</label>
<div class="controls">
<select name="format" id="format">
<? foreach ($this->exportOptions as $exportOption): ?>
<option value="<?=$this->escapeHtml($exportOption)?>"><?=$this->transEsc($exportOption)?></option>
<? endforeach; ?>
</select>
</div>
</div>
<div class="control-group">
<div class="controls">
<input class="btn" type="submit" name="submit" value="<?=$this->transEsc('Export')?>"/>
</div>
</div>
</form> </form>
<? endif; ?> <? endif; ?>
\ No newline at end of file <?
$items = $this->transEsc('items');
$script = <<<JS
var list = $('.item-list');
var items = list.find('li').length;
var bubble = list.html();
list.html('<span class="btn">'+items+' {$items}</span>');
list.find('.btn').popover({html:true,content:bubble});
JS;
?>
<?=$this->inlineScript(\Zend\View\Helper\HeadScript::SCRIPT, $script, 'SET') ?>
\ No newline at end of file
...@@ -12,22 +12,23 @@ ...@@ -12,22 +12,23 @@
<form class="form-horizontal" method="post" action="<?=$this->url('cart-save')?>" name="bulkSave"> <form class="form-horizontal" method="post" action="<?=$this->url('cart-save')?>" name="bulkSave">
<? $idParams = array(); ?> <? $idParams = array(); ?>
<? foreach ($this->records as $current): ?>
<? $idParams[] = urlencode('ids[]') . '=' . urlencode($current->getResourceSource() . '|' . $current->getUniqueId()) ?>
<input type="hidden" name="ids[]" value="<?=$this->escapeHtml($current->getResourceSource() . '|' . $current->getUniqueId())?>" />
<? endforeach; ?>
<div class="control-group"> <div class="control-group">
<label class="control-label"><?=$this->transEsc('Title')?></label> <label class="control-label"><?=$this->transEsc('Title')?></label>
<div class="controls"> <div class="controls">
<? if(count($this->records) > 1): ?> <? if(count($this->records) > 3): ?>
<div class="item-list"> <div class="item-list">
<ul> <ul>
<? foreach ($this->records as $current): ?> <? foreach ($this->records as $current): ?>
<? $idParams[] = urlencode('ids[]') . '=' . urlencode($current->getResourceSource() . '|' . $current->getUniqueId()) ?>
<li><?=$this->escapeHtml($current->getBreadcrumb())?></li> <li><?=$this->escapeHtml($current->getBreadcrumb())?></li>
<input type="hidden" name="ids[]" value="<?=$this->escapeHtml($current->getResourceSource() . '|' . $current->getUniqueId())?>" />
<? endforeach; ?> <? endforeach; ?>
</ul> </ul>
</div> </div>
<? else: ?> <? else: ?>
<span class="uneditable-input"><?=$this->records[0]->getBreadcrumb() ?></span> <span class="uneditable-input"><?=$this->records[0]->getBreadcrumb() ?></span>
<input type="hidden" name="ids[]" value="<?=$this->escapeHtml($this->records[0]->getResourceSource() . '|' . $this->records[0]->getUniqueId())?>" />
<? endif; ?> <? endif; ?>
</div> </div>
</div> </div>
...@@ -60,7 +61,6 @@ ...@@ -60,7 +61,6 @@
</div> </div>
</div> </div>
</form> </form>
<? <?
$items = $this->transEsc('items'); $items = $this->transEsc('items');
$script = <<<JS $script = <<<JS
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
$this->jsTranslations()->addStrings( $this->jsTranslations()->addStrings(
array( array(
'bulk_noitems_advice' => 'bulk_noitems_advice', 'bulk_noitems_advice' => 'bulk_noitems_advice',
'bulk_save_success' => 'bulk_save_success',
'confirmEmpty' => 'bookbag_confirm_empty', 'confirmEmpty' => 'bookbag_confirm_empty',
'viewBookBag' => 'View Book Bag', 'viewBookBag' => 'View Book Bag',
'addBookBag' => 'Add to Book Bag', 'addBookBag' => 'Add to Book Bag',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment