From 1b3a458b239b0a350641abb4b07b40460c865a90 Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Sat, 23 Aug 2025 11:57:10 -0500 Subject: [PATCH] bug fix: menu handling (tabs, window open) --- bin/qcms | 2 +- cms/disk.py | 6 ++++ cms/static/js/qcms/menu.js | 52 ++++++++++++++++++++----------- cms/static/js/qcms/page-loader.js | 18 ++++++----- 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/bin/qcms b/bin/qcms index 7736054..065541a 100755 --- a/bin/qcms +++ b/bin/qcms @@ -293,7 +293,7 @@ def create(folder:Annotated[str,typer.Argument(help="path of the project folder" # # Build the configuration for the project if not os.path.exists(folder) : - root = 'www/html' + root = f'www{os.sep}html' _system = System() _layout = Layout() _layout = _layout.build(root=root, order={'menu':[]}, footer = [{"text":term} for term in footer.split(',')],header={'title':title,'subtitle':subtitle} ) diff --git a/cms/disk.py b/cms/disk.py index 74b1a0a..917a191 100644 --- a/cms/disk.py +++ b/cms/disk.py @@ -69,6 +69,12 @@ def _realpath (uri,_config) : _layout = _config['layout'] _uri = copy.copy(uri) if 'location' in _layout and _layout['location']: + _loc = _layout['location'].strip() + + if _loc.endswith(os.sep) and _uri.endswith(os.sep) : + _uri = os.sep.join(_uri.split(os.sep)[1:]) + print (' *********************************** ') + _uri = os.sep.join([_layout['location'],_uri]) return _uri diff --git a/cms/static/js/qcms/menu.js b/cms/static/js/qcms/menu.js index bc7bda1..14e0209 100644 --- a/cms/static/js/qcms/menu.js +++ b/cms/static/js/qcms/menu.js @@ -72,23 +72,36 @@ qcms.menu.Basic = function (_layout,_outputId,_domId){ $(_div).on('click', function (){ // // how do we process this ... - if(this.data.uri && this.data.type != 'open') { - - if (this.data.type == 'dialog') { + console.log(this.data) + if (this.data.type == 'redirect') { + window.open(this.data.url,_me._format(this.data.text)) + }else if (this.data.type == 'dialog'){ qcms.dialog.show(this.data) - }else{ - _me._open(_me._format(this.data.text),this.data.uri,_parentId) - } + }else if (this.data.type == 'open'){ + window.open(this.data.uri,'_self') }else{ - // - // redirecting - if (this.data.uri != null){ - window.open(this.data.uri,'_self') - }else{ - window.open(this.data.url,_format(this.data.text)) - } + _me._open(_me._format(this.data.text),this.data.uri,_parentId) + } + // if(this.data.uri && this.data.type != 'open') { + + // if (this.data.type == 'dialog') { + // qcms.dialog.show(this.data) + // }else{ + // _me._open(_me._format(this.data.text),this.data.uri,_parentId) + // } + + // }else{ + + // // + // // redirecting + // if (this.data.uri != null){ + // window.open(this.data.uri,'_self') + // }else{ + // window.open(this.data.url,_format(this.data.text)) + // } + // } }) @@ -160,8 +173,10 @@ qcms.menu.Tabs = function (_layout,_outputId,_domId){ // var _parentId = this._parentId var _me = this ; $(_label).on('click',function (){ - - _me._open(this.data.id,this.data.uri,_me._parentId) + alert('....') + // _me._open(this.data.id,this.data.uri,_me._parentId) + console.log([_me._format(this.data.text),this.data.uri,_parentId]) + _me._open(_me._format(this.data.text),this.data.uri,_parentId) }) return [_button,_label] @@ -170,10 +185,11 @@ qcms.menu.Tabs = function (_layout,_outputId,_domId){ var _names = _layout.order.menu.length > 0 ? _layout.order.menu : Object.keys(_layout.menu) // Object.keys(_layout.menu). - _names.forEach(function(_key){ - _item = _layout.menu[_key] + _names.forEach(function(_text){ + _item = _layout.menu[_text] // console.log([_item]) - _tabItem = this._build(_key,_item) + _tabItem = this._build(_text,_item) + $(tabs).append(_tabItem) }) diff --git a/cms/static/js/qcms/page-loader.js b/cms/static/js/qcms/page-loader.js index 1412b6d..b55baad 100644 --- a/cms/static/js/qcms/page-loader.js +++ b/cms/static/js/qcms/page-loader.js @@ -22,20 +22,18 @@ qcms.page.Observer = function (_parentId,_domId,_uri){ _finalize = this.finalize _domId = this._domId - var _id = `${this._parentId} #${this._domId}` + var _id = `${this._parentId} #${this._domId}`.trim() var http = HttpClient.instance() http.setHeader('dom',this._domId) http.setHeader('uri',this._uri) - + var _uri = this._uri http.post(`${qcms.context}/page`,function(x){ + var _dom = $(x.responseText) $(_id).append (_dom) - - _finalize(_id) - - _caller.notify() - // // console.log(['*** ',_uri, ' on ',_domId]) + _finalize(_id) + _caller.notify() }) @@ -46,7 +44,11 @@ qcms.page.Observer = function (_parentId,_domId,_uri){ } qcms.page.loader = function(_parentId,_layout){ - // console.log(_parentId,_layout) + + if (_parentId.constructor == Object) { + _layout = _parentId + _parentId = null + } if (!_layout) { return ; }