bug fixes, and new menu delegate function

v2.1
Steve Nyemba 3 months ago
parent 5b9d7033ca
commit 4382bb2ec7

@ -97,11 +97,10 @@ def read (**_args):
# Inferring the type of the data to be returned # Inferring the type of the data to be returned
_mimeType = 'application/octet-stream' _mimeType = 'application/octet-stream'
_extension = _uri.split('.')[-1] _extension = _uri.split('.')[-1]
if _extension in ['css','js','csv'] : if _extension in ['css','js','csv','html'] :
_mimeType = f'text/{_extension}' _mimeType = f'text/{_extension}'
elif _extension in ['png','jpg','jpeg'] : elif _extension in ['png','jpg','jpeg'] :
_mimeType = f'image/{_extension}' _mimeType = f'image/{_extension}'
return _stream, _mimeType return _stream, _mimeType
return None,_mimeType return None,_mimeType
def exists(**_args): def exists(**_args):
@ -123,6 +122,7 @@ def html(_uri,_config) :
if not _config : if not _config :
_api = os.sep.join(['api/disk/read?uri=',_layout['root']]) _api = os.sep.join(['api/disk/read?uri=',_layout['root']])
else: else:
_api = os.sep.join([f'{_context}/api/disk/read?uri=',_layout['root']]) _api = os.sep.join([f'{_context}/api/disk/read?uri=',_layout['root']])
if f"{_layout['root']}{os.sep}" in _html : if f"{_layout['root']}{os.sep}" in _html :
_html = _html.replace(f"{_layout['root']}",_api) _html = _html.replace(f"{_layout['root']}",_api)

@ -170,6 +170,7 @@ class Initializer :
_index = 0 _index = 0
for _item in _submenu : for _item in _submenu :
text = _item['text'].strip() text = _item['text'].strip()
if text in _overwrite : if text in _overwrite :
if 'uri' in _item and 'url' in _overwrite[text] : if 'uri' in _item and 'url' in _overwrite[text] :
del _item['uri'] del _item['uri']
@ -204,6 +205,7 @@ class Initializer :
# #
# If there are missing items in the sorting # If there are missing items in the sorting
_missing = list(set(self._menu.keys()) - set(_sortedmenu)) _missing = list(set(self._menu.keys()) - set(_sortedmenu))
if _missing : if _missing :
for _name in _missing : for _name in _missing :
_menu[_name] = self._menu[_name] _menu[_name] = self._menu[_name]
@ -234,6 +236,13 @@ class Initializer :
# #
# update the menu items and the configuration # update the menu items and the configuration
# #
_keys = list(_menu.keys())
# for _key in _keys :
# if len(_menu[_key]) == 0 :
# del _menu[_key]
# #
# # doing some house-keeping work here to make sure the front-end gets clean data
# #
_layout['menu'] = _menu _layout['menu'] = _menu
self._config['layout'] = _layout self._config['layout'] = _layout
def _ilogo(self): def _ilogo(self):

@ -130,9 +130,9 @@ def _aindex (app,resource=None):
# """ # """
# global _config # global _config
# return "0",200 # return "0",200
@_app.route('/<app>/dialog')
@_app.route('/dialog') @_app.route('/dialog',defaults={'app':'main'})
def _dialog (): def _dialog (app):
# global _config # global _config
global _route global _route
_handler = _route.get() _handler = _route.get()
@ -140,7 +140,7 @@ def _dialog ():
_id = request.headers['dom'] _id = request.headers['dom']
# _html = ''.join(["<div style='padding:1%'>",str( e.render(**_args)),'</div>']) # _html = ''.join(["<div style='padding:1%'>",str( e.render(**_args)),'</div>'])
_args = _route.render(_uri,'html',session.get('app_id','main')) _args = _route.render(_uri,'html',app) #session.get('app_id','main'))
_args['title'] = _id _args['title'] = _id
return render_template('dialog.html',**_args) #title=_id,html=_html) return render_template('dialog.html',**_args) #title=_id,html=_html)

@ -117,7 +117,7 @@ menu.events._dialog = function (_item,_context){
http.get(_context+'/dialog',function(x){ http.get(_context+'/dialog',function(x){
jx.modal.show({html:x.responseText,id:'dialog'}) jx.modal.show({html:x.responseText,id:'dialog'})
// menu.events.finalize ('.jxmodal') menu.events.finalize ('.jxmodal')
}) })
} }
@ -129,6 +129,7 @@ menu.events._open = function (id,uri,_context){
$('.content').children().slideUp() $('.content').children().slideUp()
$('#'+id).remove() $('#'+id).remove()
var httpclient = HttpClient.instance() var httpclient = HttpClient.instance()
_context = (_context == null)?'':_context; _context = (_context == null)?'':_context;
httpclient.setHeader('uri',uri) httpclient.setHeader('uri',uri)
@ -138,14 +139,13 @@ menu.events._open = function (id,uri,_context){
var _html = x.responseText var _html = x.responseText
var _dom = $(_html) var _dom = $(_html)
if(jx.dom.exists(pid) && jx.dom.exists(id)){ if(jx.dom.exists(pid) && jx.dom.exists(id)){
jx.dom.remove(id) jx.dom.remove(id)
} }
$(pid).append(_dom) $(pid).append(_dom)
var ref = pid + ' #'+id var ref = pid + ' #'+id
menu.events.finalize (ref) // menu.events.finalize (ref)
$(pid).children().slideUp('fast', function(){ $(pid).children().slideUp('fast', function(){
$(ref ).slideDown('fast',function(){ $(ref ).slideDown('fast',function(){
@ -174,6 +174,20 @@ menu.utils = {}
menu.utils.format = function(text){ menu.utils.format = function(text){
return text.replace(/(-|_)/g,' ').trim() return text.replace(/(-|_)/g,' ').trim()
} }
menu.utils._delegate = function (_id,_itemIndex,_index) {
if ($(_id).children().length >= _itemIndex ){
var _node = $(_id).children()[_itemIndex ]
if ($(_node).children().length >= _index ){
var _node = $(_node).children()[_index]
_node = $(_node).find('.active')
if ($(_node).length > 0 ){
$(_node)[0].click()
}
}
}
}
menu.events.finalize = function (ref) { menu.events.finalize = function (ref) {
var scripts = $(ref+' script') var scripts = $(ref+' script')
@ -202,6 +216,7 @@ var QCMSBasic= function(_layout,_context,_clickEvent) {
this._make = function (_items){ this._make = function (_items){
var _panes = [] var _panes = []
var _context = this._context ; var _context = this._context ;
_items.forEach(_item=>{ _items.forEach(_item=>{
var _div = jx.dom.get .instance('DIV') var _div = jx.dom.get .instance('DIV')
@ -215,17 +230,20 @@ var QCMSBasic= function(_layout,_context,_clickEvent) {
$(_div).on('click', function (){ $(_div).on('click', function (){
// //
// how do we process this ... // how do we process this ...
if(this.data.uri && this.data.type != 'open') {
if(this.data.uri) {
if (this.data.type == 'dialog') { if (this.data.type == 'dialog') {
menu.events._dialog(this.data,_context) menu.events._dialog(this.data,_context)
}else{ }else{
menu.events._open(menu.utils.format(this.data.text),this.data.uri,_context) menu.events._open(menu.utils.format(this.data.text),this.data.uri,_context)
} }
}else{
if (this.data.uri != null){
window.open(this.data.uri,'_self')
}else{ }else{
window.open(this.data.url,menu.utils.format(this.data.text)) window.open(this.data.url,menu.utils.format(this.data.text))
} }
}
}) })
@ -242,6 +260,7 @@ var QCMSBasic= function(_layout,_context,_clickEvent) {
// Object.keys(this._layout.menu) // Object.keys(this._layout.menu)
_names.forEach(function(_name){ _names.forEach(function(_name){
var _div = _me._make(_layout.menu[_name]) ; var _div = _me._make(_layout.menu[_name]) ;

Loading…
Cancel
Save