-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from mdenet/102-add-support-for-panel-customi…
…sation-in-activity-files Support for panel customisation in activity files
- Loading branch information
Showing
8 changed files
with
206 additions
and
112 deletions.
There are no files selected for viewing
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,80 @@ | ||
|
||
var buttonTypes= { | ||
BUTTON_ACTION: 'BUTTON_ACTION', | ||
BUTTON_HELP: 'BUTTON_HELP' | ||
} | ||
|
||
class Button { | ||
id; | ||
icon; | ||
hint; | ||
action; | ||
type; | ||
|
||
/** | ||
* Create a Button | ||
* @param {object} buttonConfigObject | ||
* @param {string} parentPanel | ||
*/ | ||
constructor(buttonConfigObject, parentPanel){ | ||
this.id= buttonConfigObject.id; | ||
this.icon= buttonConfigObject.icon; | ||
this.hint= buttonConfigObject.hint; | ||
this.action = buttonConfigObject.action; | ||
|
||
// Set button's onclick action | ||
if (buttonConfigObject["url"] != undefined) { | ||
this.type = buttonTypes.BUTTON_HELP; | ||
this.action = "window.open('" + buttonConfigObject.url + "');"; | ||
|
||
} else if (buttonConfigObject["actionfunction"] != undefined) { | ||
this.type = buttonTypes.BUTTON_ACTION; | ||
this.action = "runAction( '" + parentPanel + "', '" + buttonConfigObject.id +"' )"; | ||
|
||
} else if (buttonConfigObject["internal"] != undefined) { | ||
this.action = buttonConfigObject.internal; | ||
|
||
} else { | ||
console.log( "Button '" + buttonConfigObject.id + "' with uknown key."); | ||
} | ||
} | ||
|
||
|
||
buttonHtml() { | ||
return "<span class='mif-" + this.icon + "' data-role='hint' data-hint-text='" + this.hint + "' data-hint-position='bottom'></span>"; | ||
} | ||
|
||
/** | ||
* Get a string representation of the button for its display | ||
* @returns {String} DOM object with html, cls and onclick properties | ||
*/ | ||
getView() { | ||
var buttonData={}; | ||
|
||
buttonData.html= this.buttonHtml(); | ||
buttonData.cls= "sys-button"; | ||
buttonData.onclick= this.action; | ||
|
||
return buttonData; | ||
} | ||
|
||
|
||
/** | ||
* Create an array of buttons from an array of configurations | ||
* @param {object[]} buttonConfigs | ||
* @param {string} parentPanel | ||
* @returns {Button[]} the Button objects | ||
*/ | ||
static createButtons(buttonConfigs, parentPanel){ | ||
|
||
let buttons= []; | ||
|
||
buttonConfigs.forEach((config)=>{ | ||
buttons.push( new Button(config, parentPanel) ); | ||
}) | ||
|
||
return buttons; | ||
} | ||
} | ||
|
||
export {Button} |
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
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
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
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
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
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
Oops, something went wrong.