Skip to content

Commit

Permalink
Factorize both Js and css code associated with download button.
Browse files Browse the repository at this point in the history
* Rename class associated with download button to a more generic
name 'extensionActionButtonWrapper'. Also ensured that the same class and
html is used between the different view.

* Add {js/css}/common/ files for functionality and style shared by the different
view.

* Factorize the existing css used to render the "extension action button"

* Factorize functionality allowing to update the button state into
multiple function:
  - click handler: extensionButtonClick
  - updateExtensionButtonState
  - setExtensionButtonState

* The following design should allow to easily associates new state with
the "extension action" button. (i.e an 'update' state)
  • Loading branch information
jcfr committed Feb 27, 2012
1 parent aa0c69a commit 4c9d6a9
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 91 deletions.
44 changes: 44 additions & 0 deletions public/css/common/common.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
body {
font-family: 'Lucida Grande', 'Lucida Sans Unicode', helvetica, arial, Verdana, sans-serif;
}

input.extensionActionButton {
color: white;
font-weight: bold;
cursor: pointer;
text-align: center;
border: 1px solid white;
line-height: 1.5;
display: block;
text-transform: uppercase;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-khtml-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: black 0 0 3px;
box-shadow: black 0 0 3px;
-moz-box-shadow: 0px 0px 3px black;
font-family: 'Lucida Grande', 'Lucida Sans Unicode', helvetica, arial, Verdana, sans-serif;
}

input.extensionActionButton:hover {
-webkit-box-shadow: black 0 0 6px;
box-shadow: black 0 0 6px;
-moz-box-shadow: 0px 0px 6px black;
}

input.extensionDownloadButton, input.extensionInstallButton {
background-color: #2277aa;
}

input.extensionDownloadButton:hover, input.extensionInstallButton:hover {
background-color: #00aaaa;
}

input.extensionUninstallButton {
background-color: #007f09;
}

input.extensionUninstallButton:hover {
background-color: #6eb04b;
}
34 changes: 7 additions & 27 deletions public/css/extension/extension.view.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
body {
font-family: 'Lucida Grande', 'Lucida Sans Unicode', helvetica, arial, Verdana, sans-serif;
}

div.viewWrapper {
padding-right: 25px !important;
Expand Down Expand Up @@ -52,7 +49,7 @@ div.viewWrapper {
}

.category {

}

.left_column {
Expand All @@ -78,7 +75,7 @@ div.viewWrapper {
margin-left: 25px;
}

.download_button {
.extensionActionButtonWrapper {
margin-bottom: 15px;
margin-left: 15px;
}
Expand Down Expand Up @@ -145,36 +142,19 @@ div.viewWrapper {
border: 1px solid #ddd8d8;
}

#downloadButton {
input.extensionActionButton {
width: 127px;
color: white;
font-size: 15px;
background-color: #2277aa;
font-weight: bold;
cursor: pointer;
text-align: center;
border: 1px solid white;
margin-left: 11px;
margin-top: 5px;
line-height: 1.5;
display: block;
text-transform: uppercase;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-khtml-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: black 0 0 3px;
box-shadow: black 0 0 3px;
-moz-box-shadow: 0px 0px 3px black;
font-family: 'Lucida Grande', 'Lucida Sans Unicode', helvetica, arial, Verdana, sans-serif;
}

#downloadButton:hover {
}
/*
#extensionActionButton:hover {
background-color: #00aaaa;
-webkit-box-shadow: black 0 0 7px;
box-shadow: black 0 0 7px;
-moz-box-shadow: 0px 0px 7px black;
}
}*/

/* Breadcrumbs */
.category {
Expand Down
33 changes: 3 additions & 30 deletions public/css/index/index.index.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
body {
font-family: 'Lucida Grande', 'Lucida Sans Unicode', helvetica, arial, Verdana, sans-serif;
}

div.viewWrapper {
width: 100% !important;
Expand Down Expand Up @@ -107,37 +104,13 @@ span.subtitle {
font-size: 12px;
}

input.downloadButton {
input.extensionActionButton {
width: 130px;
color: white;
font-size: 13px;
background-color: #2277aa;
font-weight: bold;
cursor: pointer;
text-align: center;
border: 1px solid white;
margin-top: 5px;
line-height: 1.5;
margin-left: auto;
margin-right: auto;
display: block;
text-transform: uppercase;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-khtml-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: black 0 0 3px;
box-shadow: black 0 0 3px;
-moz-box-shadow: 0px 0px 3px black;
font-family: 'Lucida Grande', 'Lucida Sans Unicode', helvetica, arial, Verdana, sans-serif;
}

input.downloadButton:hover {
background-color: #00aaaa;
-webkit-box-shadow: black 0 0 6px;
box-shadow: black 0 0 6px;
-moz-box-shadow: 0px 0px 6px black;
}
}

.extensionRatings {
height: 20px;
Expand Down Expand Up @@ -168,7 +141,7 @@ ul.categoriesList li,ul.categoriesSubList li {
}

ul.categoriesList li:hover,ul.categoriesSubList li:hover {

color: #222222;
}

Expand Down
50 changes: 50 additions & 0 deletions public/js/common/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var midas = midas || {};
midas.slicerappstore = midas.slicerappstore || {};

/**
* Called when a user clicks the extension button (download, install or uninstall)
*/
midas.slicerappstore.extensionButtonClick = function() {
var extensionId = $(this).attr('element');
if(!window.extensions_manager_model || $(this).hasClass('extensionDownloadButton')) {
var url = json.global.webroot+'/slicerappstore/index/downloadextension?extensionId='+extensionId;
window.location.assign(url);
} else if($(this).hasClass('extensionInstallButton')) {
window.extensions_manager_model.downloadAndInstallExtension(extensionId);
} else if($(this).hasClass('extensionUninstallButton')) {
window.extensions_manager_model.uninstallExtension($(this).attr('extensionname'));
}
}

/**
* Update extension button state considering 'window.extensions_manager_model'
* @param extensionName Name of the extension associated with the button to update
*/
midas.slicerappstore.updateExtensionButtonState = function(extensionName) {
if(!window.extensions_manager_model) {
midas.slicerappstore.setExtensionButtonState(extensionName, 'download');
} else {
var buttonState = 'install';
if(window.extensions_manager_model.isExtensionInstalled(extensionName)) {
buttonState = 'uninstall';
}
midas.slicerappstore.setExtensionButtonState(extensionName, buttonState);
}
}

/**
* Set extension button state
* @param extensionName Name of the extension associated with the button to update
* @param buttonState Either 'download', 'install' or 'uninstall'
*/
midas.slicerappstore.setExtensionButtonState = function(extensionName, buttonState) {
if (buttonState != 'download' && buttonState != 'install' && buttonState != 'uninstall') {
alert('Unknown buttonState:' + buttonState);
}
var buttonText = buttonState.charAt(0).toUpperCase() + buttonState.slice(1);
var buttonClass = 'extension' + buttonText + 'Button';
$('input[extensionname="' + extensionName + '"]').val(buttonText)
.removeClass('extensionDownloadButton extensionInstallButton extensionUninstallButton')
.addClass(buttonClass)
.unbind('click').click(midas.slicerappstore.extensionButtonClick);
}
5 changes: 5 additions & 0 deletions public/js/extension/extension.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ $(document).ready(function() {
midas.slicerappstore.renderCategory(json.extension.category);
midas.slicerappstore.renderScreenshots(json.extension.screenshots);

$('input.extensionActionButton')
.attr('element', json.extension.slicerpackages_extension_id)
.attr('extensionname', json.extension.productname);
midas.slicerappstore.updateExtensionButtonState(json.extension.productname);

if(json.slicerView) {
createNotice = function() {}; //dummy function definition to prevent exceptions
}
Expand Down
36 changes: 13 additions & 23 deletions public/js/index/index.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,25 @@ var json = null;
* Called when a user clicks to view the extension page
*/
midas.slicerappstore.extensionClick = function() {
var url = json.webroot+'/slicerappstore/extension/view?extensionId='+$(this).attr('element');
var url = json.global.webroot+'/slicerappstore/extension/view?extensionId='+$(this).attr('element');
if(json.slicerView) {
url += '&slicerView';
}
window.location.assign(url);
}

/**
* Called when a user clicks the download or install button
*/
midas.slicerappstore.downloadClick = function() {
var extensionId = $(this).attr('element');
if(json.slicerView) {
if(window.extensions_manager_model) {
window.extensions_manager_model.downloadExtension(extensionId);
}
} else {
var url = json.webroot+'/slicerappstore/index/downloadextension?extensionId='+extensionId;
window.location.assign(url);
}
}

/**
* Render the extension result in the result list area
* @param extension Json-ified slicerpackages_extension dao
*/
midas.slicerappstore.renderExtension = function(extension) {
var extensionName = extension.productname;
var extDiv = $('#extensionTemplate').clone()
.attr('id', 'extensionWrapper_'+extension.slicerpackages_extension_id);
var buttonText = json.slicerView ? 'Install' : 'Download';
extDiv.attr('element', extension.slicerpackages_extension_id);
extDiv.find('a.extensionName').html(extension.productname)
.attr('qtip', extension.productname)
extDiv.attr('element', extension.slicerpackages_extension_id)
.attr('extensionname', extensionName);
extDiv.find('a.extensionName').html(extensionName)
.attr('qtip', extensionName)
.attr('element', extension.slicerpackages_extension_id)
.qtip({
content: {
Expand All @@ -56,10 +42,11 @@ midas.slicerappstore.renderExtension = function(extension) {
extDiv.find('span.subtitle').html(extension.subtitle);
extDiv.find('img.extensionIcon').attr('src', extension.icon)
.attr('element', extension.slicerpackages_extension_id)
.attr('extensionname', extensionName)
.click(midas.slicerappstore.extensionClick);
extDiv.find('input.downloadButton').val(buttonText)
extDiv.find('input.extensionActionButton')
.attr('element', extension.slicerpackages_extension_id)
.click(midas.slicerappstore.downloadClick);
.attr('extensionname', extensionName);

var average = Math.round(extension.ratings.average * 100) / 100;
var starSelect = Math.round(average * 2);
Expand All @@ -72,6 +59,9 @@ midas.slicerappstore.renderExtension = function(extension) {
extDiv.find('span.totalVotes').html('('+extension.ratings.total+')');

extDiv.appendTo('#extensionsContainer');

midas.slicerappstore.updateExtensionButtonState(extensionName);

extDiv.show();
}

Expand All @@ -81,7 +71,7 @@ midas.slicerappstore.renderExtension = function(extension) {
midas.slicerappstore.applyFilter = function() {
$('#extensionsContainer').html('');
$('.loadingExtensions').show();
$.post(json.webroot+'/slicerappstore/index/listextensions', {
$.post(json.global.webroot+'/slicerappstore/index/listextensions', {
category: midas.slicerappstore.category,
os: midas.slicerappstore.os,
arch: midas.slicerappstore.arch,
Expand Down
13 changes: 8 additions & 5 deletions views/extension/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if($this->slicerView)
echo '<script type="text/javascript" src="'.$this->coreWebroot.'/public/js/layout/jquery.treeTable.js"></script>';
echo '<script type="text/javascript" src="'.$this->coreWebroot.'/public/js/layout/jquery.qtip.min.js"></script>';
echo '<script type="text/javascript" src="'.$this->coreWebroot.'/public/js/layout/midas.callback.js"></script>';
echo '<script type="text/javascript" src="'.$this->moduleWebroot.'/public/js/common/common.js"></script>';
echo '<script type="text/javascript" src="'.$this->moduleWebroot.'/public/js/extension/extension.view.js"></script>';
echo '<script type="text/javascript" src="'.$this->moduleWebroot.'/public/js/lightbox/jquery.lightbox-0.5.pack.js"></script>';
echo '<script type="text/javascript" src="'.$this->webroot.'/modules/ratings/public/js/common/common.ratings.js"></script>';
Expand All @@ -36,13 +37,15 @@ else
$this->headScript()->appendFile($this->coreWebroot.'/public/js/jquery/jqplot/jqplot.categoryAxisRenderer.min.js');
$this->headScript()->appendFile($this->coreWebroot.'/public/js/jquery/jqplot/jqplot.pointLabels.min.js');
$this->headScript()->appendFile($this->coreWebroot.'/public/js/jquery/jquery.autogrow-textarea.js');
$this->headScript()->appendFile($this->moduleWebroot.'/public/js/common/common.js');
$this->headScript()->appendFile($this->moduleWebroot.'/public/js/extension/extension.view.js');
$this->headScript()->appendFile($this->moduleWebroot.'/public/js/lightbox/jquery.lightbox-0.5.pack.js');
$this->headScript()->appendFile($this->webroot.'/modules/ratings/public/js/star_rating/jquery.ui.stars.min.js');
$this->headScript()->appendFile($this->webroot.'/modules/ratings/public/js/common/common.ratings.js');
$this->headScript()->appendFile($this->webroot.'/modules/comments/public/js/item/item.comments.js');
}
?>
<link type="text/css" rel="stylesheet" href="<?php echo $this->moduleWebroot?>/public/css/common/common.css" />
<link type="text/css" rel="stylesheet" href="<?php echo $this->moduleWebroot?>/public/css/extension/extension.view.css" />
<link type="text/css" rel="stylesheet" href="<?php echo $this->moduleWebroot?>/public/css/lightbox/jquery.lightbox-0.5.css" />
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/layout/jquery.qtip.min.css" />
Expand All @@ -51,7 +54,7 @@ else
<link type="text/css" rel="stylesheet" href="<?php echo $this->webroot?>/modules/comments/public/css/item/item.comments.css" />

<div id="container_main">
<div id="extension_banner">
<div id="extension_banner">
<div class="title">
<div class="extension_title"><?php echo $this->extension->getProductname()?></div>
<div class="group_title">
Expand All @@ -62,7 +65,7 @@ else
<a class="breadcrumbLink" href="<?php echo $this->webroot?>/slicerappstore<?php if($this->slicerView) echo '?slicerView'?>">Slicer Extensions</a>
</span>
</div>
</div>
</div>
<div class="button_bar">
<img qtip="+1 on Google+" src="<?php echo $this->moduleWebroot?>/public/images/googleplus.png" width="32" height="32" class="googlePlus"/>
<img qtip="Tweet this" src="<?php echo $this->moduleWebroot?>/public/images/twitter.png" width="32" height="32" class="twitter"/>
Expand All @@ -73,8 +76,8 @@ else
<div class="icon_art">
<img src="<?php echo $this->icon ?>" width="128" height="128" />
</div>
<div class="download_button">
<input type="button" id="downloadButton" value="Install" />
<div class="extensionActionButtonWrapper">
<input type="button" class="extensionActionButton" value=""/>
</div>
<div class="info_list">
<?php echo $this->extension->getItem()->getDownload() ?> downloads<br/>
Expand All @@ -89,7 +92,7 @@ else
<div class="content_header">Description</div>
<div class="description">
<?php echo htmlentities($this->extension->getDescription()) ?>
</div>
</div>
<div class="content_header">
Screenshots
</div>
Expand Down
Loading

0 comments on commit 4c9d6a9

Please sign in to comment.