Skip to content

Commit

Permalink
#106 Load sub-item on click : option to no reload immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
troussej committed Dec 5, 2016
1 parent a22b147 commit 1ef5980
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 121 deletions.
227 changes: 118 additions & 109 deletions bda.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ try {
tag.name = tagName;
tags[tagName] = tag;
}
console.log('buildTagsFromArray ' + JSON.stringify(tags));
logTrace('buildTagsFromArray ' + JSON.stringify(tags));
return tags;
},

Expand All @@ -81,15 +81,15 @@ try {
// First check cache value if any
var rawXmlDef = getXmlDef(getCurrentComponentPath());
if (rawXmlDef !== null) {
console.log("Getting XML def from cache");
logTrace("Getting XML def from cache");
var xmlDoc = jQuery.parseXML(rawXmlDef);
if (callback !== undefined)
callback($(xmlDoc));
}
// If no cache entry, fetch the XML def in ajax
else {
var url = location.protocol + '//' + location.host + location.pathname + "?propertyName=" + property;
console.log(url);
logTrace(url);
jQuery.ajax({
url: url,
success: function(result) {
Expand All @@ -103,14 +103,14 @@ try {
.replace(" ", "")
.replace("<!DOCTYPE gsa-template SYSTEM \"dynamosystemresource:/atg/dtds/gsa/gsa_1.0.dtd\">", "");
try {
console.log("XML def length : " + rawXmlDef.length);
logTrace("XML def length : " + rawXmlDef.length);
var xmlDoc = jQuery.parseXML(rawXmlDef);
storeXmlDef(getCurrentComponentPath(), rawXmlDef);
callback($(xmlDoc));
} catch (err) {
console.log("Unable to parse XML def file !");
logTrace("Unable to parse XML def file !");
callback(null);
console.log(err);
logTrace(err);
}
} else
callback(null);
Expand All @@ -121,20 +121,20 @@ try {
};

this.getXmlDef = function(componentPath) {
console.log("Getting XML def for : " + componentPath);
logTrace("Getting XML def for : " + componentPath);
var timestamp = Math.floor(Date.now() / 1000);
var xmlDefMetaData = JSON.parse(localStorage.getItem("XMLDefMetaData"));
if (!xmlDefMetaData)
return null;
if (xmlDefMetaData.componentPath != componentPath || (xmlDefMetaData.timestamp + xmlDefinitionCacheTimeout) < timestamp) {
console.log("Xml def is outdated or from a different component");
logTrace("Xml def is outdated or from a different component");
return null;
}
return localStorage.getItem("XMLDefData");
};

this.storeXmlDef = function(componentPath, rawXML) {
console.log("Storing XML def : " + componentPath);
logTrace("Storing XML def : " + componentPath);
var timestamp = Math.floor(Date.now() / 1000);

localStorage.setItem("XMLDefMetaData", JSON.stringify({
Expand Down Expand Up @@ -184,7 +184,7 @@ try {
componentPath = componentPath.substr(0, componentPath.length - 1);

var tab = componentPath.split("/");
//console.log("For component :" + componentPath + ", name is : " + (tab[tab.length - 1]));
//logTrace("For component :" + componentPath + ", name is : " + (tab[tab.length - 1]));
return tab[tab.length - 1];
};

Expand All @@ -208,7 +208,7 @@ try {

this.logTrace = function() {
if (isLoggingTrace) {
console.log.apply(this, arguments);
logTrace.apply(this, arguments);
}
};

Expand Down Expand Up @@ -433,8 +433,8 @@ try {
$.fn.sortContent = function(selector, sortFunction) {
var $this = $(this);
var $elems = $this.find(selector);
console.log('selector ' + selector);
console.log($elems.length);
logTrace('selector ' + selector);
logTrace($elems.length);
$elems = $elems.sort(sortFunction);
$elems.detach().appendTo($this);
return this;
Expand Down Expand Up @@ -513,121 +513,130 @@ Johann Burkard
};


// CUSTOM ALERT with multiple options
const BDA_ALERT_CONFIG = {};
const bdaDefaults = {
msg: '',
options: []
};
const pluginName = "bdaAlert";

const templates = {
ALERT_MODAL_TEMPLATE: '<div class="bda-alert-wrapper twbs">' +
'<div class="modal fade bda-modal" tabindex="-1" role="dialog">' +
'<div class="modal-dialog" role="document">' +
'<div class="modal-content ">' +
'<div class="modal-body bda-alert-body"></div>' +
'<div class="modal-footer bda-alert-footer"></div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>'
};

function BdaAlert(parent, options) {
console.log('BdaAlert');
console.log(parent)
this.$parent = $(parent);
(function($) {
// CUSTOM ALERT with multiple options
const BDA_ALERT_CONFIG = {};
const bdaAlertDefaults = {
msg: '',
options: []
};
const pluginName = "bdaAlert";

const templates = {
ALERT_MODAL_TEMPLATE: '<div class="bda-alert-wrapper twbs">' +
'<div class="modal fade bda-modal" tabindex="-1" role="dialog">' +
'<div class="modal-dialog" role="document">' +
'<div class="modal-content ">' +
'<div class="modal-body bda-alert-body"></div>' +
'<div class="modal-footer bda-alert-footer"></div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>'
};

this.options = $.extend({}, bdaDefaults, options);
this._defaults = bdaDefaults;
this._name = pluginName;
function BdaAlert(parent, inOptions) {
// logTrace('BdaAlert');
//logTrace(parent)
this.$parent = $(parent);

this._init();
}
logTrace('in options: %s', JSON.stringify(inOptions));

BdaAlert.prototype = {
_init: function() {
logTrace('build bdaAlert');
logTrace(arguments)
logTrace(this.$parent.get());

this.$parent.append(templates.ALERT_MODAL_TEMPLATE);
this.modal = this.$parent.find('.modal');
this.options = inOptions //$.extend({}, bdaAlertDefaults, inOptions);
logTrace('options:');
logTrace( this.options);
this._defaults = bdaAlertDefaults;
this._name = pluginName;

this._init();
}

},
_show: function() {
logTrace('bdaAlert show');
this.modal.modal('show');
},
_hide: function() {
logTrace('bdaAlert hide');
this.modal.modal('hide');
},
confirm: function(opts) {
var plugin = this;
logTrace('bdaAlert confirm');
logTrace(opts);
//set msg
plugin.modal.find('.bda-alert-body').html(opts.msg);
//clean
var $footer = plugin.modal.find('.bda-alert-footer').empty();

for (var i = 0; i < opts.options.length; i++) {
var opt = opts.options[i];
$('<input></input>', {
type: 'button',
value: opt.label,
class: 'btn btn-default'
})
.on('click', function() {
logTrace('bdaAlert click');
if (!isNull(opt.callback)) {
opt.callback($modal);
BdaAlert.prototype = {
_init: function() {
logTrace('build bdaAlert');
logTrace(arguments)
logTrace(this.$parent.get());

this.wrapper = $(templates.ALERT_MODAL_TEMPLATE);
this.$parent.append(this.wrapper );
this.modal = this.wrapper.find('.modal');
},
_show: function() {
logTrace('bdaAlert show');
this.modal.modal('show');
},
_hide: function() {
logTrace('bdaAlert hide');
this.modal.modal('hide');
this._destroy();
},
_destroy: function(){
logTrace('bdaAlert destroy');
this.wrapper.detach();
},
confirm: function() {
var plugin = this;
var opts = plugin.options;
logTrace('bdaAlert confirm');
logTrace(opts);
//set msg
plugin.modal.find('.bda-alert-body').html(opts.msg);
//clean
var $footer = plugin.modal.find('.bda-alert-footer').empty();

var buildOuterCallback = function(callback){
return function(){
logTrace('bdaAlert click');
logTrace(callback);
if (!isNull(callback)) {
callback.apply(this.$modal);
}
plugin._hide();
})
.appendTo($footer);
}
plugin._show();
}
}

$.fn[pluginName] = function(options) {
logTrace("call " + pluginName);
logTrace(options);
logTrace(arguments);
var args = arguments;

}
}

if (options === undefined || typeof options === 'object') {
return this.each(function() {
for (var i = 0; i < opts.options.length; i++) {
var opt = opts.options[i];
logTrace( opt);

if (!$.data(this, 'plugin_' + pluginName)) {


$.data(this, 'plugin_' + pluginName, new BdaAlert(this, options));
$('<input></input>', {
type: 'button',
value: opt.label,
class: 'btn btn-default',
data: opts.options[i]
})
.on('click', buildOuterCallback(opt._callback))
.appendTo($footer);
}
});

} else if (typeof options === 'string' && options[0] !== '_' ) {
plugin._show();
}
}

var returns;
$.fn[pluginName] = function(options) {
logTrace('in function bdaAlert');
try {

this.each(function() {
var instance = $.data(this, 'plugin_' + "bdaAlert");
logTrace("call " + pluginName);
logTrace(options);

if (instance instanceof BdaAlert && typeof instance[options] === 'function') {
returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
}
return this.each(function() {

});
var data = new BdaAlert(this, options);
data.confirm();

return returns !== undefined ? returns : this;
});
} catch (e) {
console.error(e);
}
return this;
}
};

})(jQuery);


} catch (e) {
console.log(e);
logTrace(e);
}
26 changes: 22 additions & 4 deletions bda.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -1046,14 +1046,32 @@
}

$(".loadable_property").click(function() {
console.log('click on loadable');
var $elm = $(this);
var id = $elm.attr("data-id");
var itemDesc = $elm.attr("data-descriptor");
var query = "<print-item id='" + id + "' item-descriptor='" + itemDesc + "' />\n";
if (confirm("You are about to add this query and reload the page : \n" + query)) {
BDA_REPOSITORY.setQueryEditorValue(BDA_REPOSITORY.getQueryEditorValue() + query);
$("#RQLForm").submit();
}



$('body').bdaAlert({
msg: 'You are about to add this query and reload the page: \n' + query,
options: [{
label: 'Add & Reload',
_callback: function() {
BDA_REPOSITORY.setQueryEditorValue(BDA_REPOSITORY.getQueryEditorValue() + query);
$("#RQLForm").submit();
}
}, {
label: 'Just Add',
_callback: function() {
BDA_REPOSITORY.setQueryEditorValue(BDA_REPOSITORY.getQueryEditorValue() + query);
}
}, {
label: 'Cancel'
}]
});

});

if (isItemTree)
Expand Down
8 changes: 0 additions & 8 deletions bda.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,6 @@ jQuery(document).ready(function() {

$().bdaScheduler();

/* $('<div id="bdaAlert"></div>').insertAfter(BDA.logoSelector).bdaAlert().bdaAlert('confirm',{
msg:'test msg',
options:[
{label:'toto'},
{label:'tata'},
]
});*/

var autocomplete = $.fn.bdaStorage.getBdaStorage().getConfigurationValue('search_autocomplete');
autocomplete = (autocomplete == true) ? true : false;
if (autocomplete) {
Expand Down

0 comments on commit 1ef5980

Please sign in to comment.