| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682 |
- /**
- * Loads the TV panel
- *
- * @class MODx.panel.TV
- * @extends MODx.FormPanel
- * @param {Object} config An object of configuration properties
- * @xtype modx-panel-tv
- */
- MODx.panel.TV = function(config) {
- config = config || {};
- config.record = config.record || {};
- config = MODx.setStaticElementsConfig(config, 'tv');
- Ext.applyIf(config,{
- url: MODx.config.connector_url
- ,baseParams: {
- action: 'element/tv/get'
- }
- ,id: 'modx-panel-tv'
- ,cls: 'container form-with-labels'
- ,class_key: 'modTemplateVar'
- ,tv: ''
- ,bodyStyle: ''
- ,items: [{
- html: _('tv_new')
- ,id: 'modx-tv-header'
- ,xtype: 'modx-header'
- },MODx.getPageStructure([{
- title: _('general_information')
- ,defaults: {border: false ,msgTarget: 'side', layout: 'form'}
- ,layout: 'form'
- ,id: 'modx-tv-form'
- ,itemId: 'form-tv'
- ,labelWidth: 150
- ,forceLayout: true
- ,items: [{
- html: '<p>'+_('tv_msg')+'</p>'
- ,id: 'modx-tv-msg'
- ,xtype: 'modx-description'
- },{
- layout: 'column'
- ,border: false
- ,defaults: {
- layout: 'form'
- ,labelAlign: 'top'
- ,anchor: '100%'
- ,border: false
- ,cls:'main-wrapper'
- ,labelSeparator: ''
- }
- ,items: [{
- columnWidth: .6
- ,items: [{
- xtype: 'hidden'
- ,name: 'id'
- ,id: 'modx-tv-id'
- ,value: config.record.id || MODx.request.id
- },{
- xtype: 'hidden'
- ,name: 'props'
- ,id: 'modx-tv-props'
- ,value: config.record.props || null
- },{
- xtype: 'textfield'
- ,fieldLabel: _('name')+'<span class="required">*</span>'
- ,description: MODx.expandHelp ? '' : _('tv_desc_name')
- ,name: 'name'
- ,id: 'modx-tv-name'
- ,anchor: '100%'
- ,maxLength: 100
- ,enableKeyEvents: true
- ,allowBlank: false
- ,value: config.record.name
- ,listeners: {
- 'keyup': {scope:this,fn:function(f,e) {
- var title = Ext.util.Format.stripTags(f.getValue());
- title = _('tv')+': '+Ext.util.Format.htmlEncode(title);
- if (MODx.request.a !== 'element/tv/create' && MODx.perm.tree_show_element_ids === 1) {
- title = title+ ' <small>('+this.config.record.id+')</small>';
- }
- Ext.getCmp('modx-tv-header').getEl().update(title);
- MODx.setStaticElementPath('tv');
- }}
- }
- },{
- xtype: MODx.expandHelp ? 'label' : 'hidden'
- ,forId: 'modx-tv-name'
- ,html: _('tv_desc_name')
- ,cls: 'desc-under'
- },{
- xtype: 'textfield'
- ,fieldLabel: _('tv_caption')
- ,description: MODx.expandHelp ? '' : _('tv_desc_caption')
- ,name: 'caption'
- ,id: 'modx-tv-caption'
- ,anchor: '100%'
- ,value: config.record.caption
- },{
- xtype: MODx.expandHelp ? 'label' : 'hidden'
- ,forId: 'modx-tv-caption'
- ,html: _('tv_desc_caption')
- ,cls: 'desc-under'
- },{
- xtype: 'textarea'
- ,fieldLabel: _('description')
- ,description: MODx.expandHelp ? '' : _('tv_desc_description')
- ,name: 'description'
- ,id: 'modx-tv-description'
- ,anchor: '100%'
- ,maxLength: 255
- ,value: config.record.description || ''
- },{
- xtype: MODx.expandHelp ? 'label' : 'hidden'
- ,forId: 'modx-tv-description'
- ,html: _('tv_desc_description')
- ,cls: 'desc-under'
- },{
- xtype: 'modx-combo-browser'
- ,browserEl: 'modx-browser'
- ,fieldLabel: _('static_file')
- ,description: MODx.expandHelp ? '' : _('static_file_msg')
- ,name: 'static_file'
- // ,hideFiles: true
- ,openTo: config.record.openTo || ''
- ,id: 'modx-tv-static-file'
- ,triggerClass: 'x-form-code-trigger'
- ,anchor: '100%'
- ,maxLength: 255
- ,value: config.record.static_file || ''
- ,hidden: !config.record['static']
- ,hideMode: 'offsets'
- },{
- xtype: MODx.expandHelp ? 'label' : 'hidden'
- ,forId: 'modx-tv-static-file'
- ,id: 'modx-tv-static-file-help'
- ,html: _('static_file_msg')
- ,cls: 'desc-under'
- ,hidden: !config.record['static']
- ,hideMode: 'offsets'
- },{
- html: MODx.onTVFormRender
- ,border: false
- }]
- },{
- columnWidth: .4
- ,items: [{
- xtype: 'modx-combo-category'
- ,fieldLabel: _('category')
- ,name: 'category'
- ,id: 'modx-tv-category'
- ,anchor: '100%'
- ,value: config.record.category || 0
- ,listeners: {
- 'afterrender': {scope:this,fn:function(f,e) {
- setTimeout(function(){
- MODx.setStaticElementPath('tv');
- }, 200);
- }}
- ,'change': {scope:this,fn:function(f,e) {
- MODx.setStaticElementPath('tv');
- }}
- }
- },{
- xtype: MODx.expandHelp ? 'label' : 'hidden'
- ,forId: 'modx-tv-category'
- ,html: _('tv_desc_category')
- ,cls: 'desc-under'
- },{
- xtype: 'numberfield'
- ,fieldLabel: _('tv_rank')
- ,name: 'rank'
- ,id: 'modx-tv-rank'
- ,width: 50
- ,maxLength: 4
- ,allowNegative: false
- ,allowBlank: false
- ,value: config.record.rank || 0
- },{
- xtype: 'xcheckbox'
- ,boxLabel: _('tv_lock')
- ,description: _('tv_lock_msg')
- ,name: 'locked'
- ,id: 'modx-tv-locked'
- ,inputValue: 1
- ,checked: config.record.locked || false
- },{
- xtype: 'xcheckbox'
- ,boxLabel: _('clear_cache_on_save')
- ,description: _('clear_cache_on_save_msg')
- ,hideLabel: true
- ,name: 'clearCache'
- ,id: 'modx-tv-clear-cache'
- ,inputValue: 1
- ,checked: Ext.isDefined(config.record.clearCache) || true
- },{border: false, html: '<br style="line-height: 25px;"/>'},{
- xtype: 'xcheckbox'
- ,hideLabel: true
- ,boxLabel: _('is_static')
- ,description: MODx.expandHelp ? '' : _('is_static_msg')
- ,name: 'static'
- ,id: 'modx-tv-static'
- ,inputValue: 1
- ,checked: config.record['static'] || false
- },{
- xtype: MODx.expandHelp ? 'label' : 'hidden'
- ,forId: 'modx-tv-static'
- ,id: 'modx-tv-static-help'
- ,html: _('is_static_msg')
- ,cls: 'desc-under'
- },{
- xtype: 'modx-combo-source'
- ,fieldLabel: _('static_source')
- ,description: MODx.expandHelp ? '' : _('static_source_msg')
- ,name: 'source'
- ,id: 'modx-tv-static-source'
- ,anchor: '100%'
- ,maxLength: 255
- ,value: config.record.source != null ? config.record.source : MODx.config.default_media_source
- ,hidden: !config.record['static']
- ,hideMode: 'offsets'
- ,baseParams: {
- action: 'source/getList'
- ,showNone: true
- ,streamsOnly: true
- }
- ,listeners: {
- select: {
- fn: this.changeSource
- ,scope: this
- }
- }
- },{
- xtype: MODx.expandHelp ? 'label' : 'hidden'
- ,forId: 'modx-tv-static-source'
- ,id: 'modx-tv-static-source-help'
- ,html: _('static_source_msg')
- ,cls: 'desc-under'
- ,hidden: !config.record['static']
- ,hideMode: 'offsets'
- }]
- }]
- }]
- },{
- xtype: 'modx-panel-element-properties'
- ,itemId: 'panel-properties'
- ,elementPanel: 'modx-panel-tv'
- ,elementId: config.tv
- ,elementType: 'modTemplateVar'
- ,record: config.record
- },{
- xtype: 'modx-panel-tv-input-properties'
- ,record: config.record
- },{
- xtype: 'modx-panel-tv-output-properties'
- ,record: config.record
- },{
- title: _('tv_tmpl_access')
- ,itemId: 'form-template'
- ,hideMode: 'offsets'
- ,defaults: {autoHeight: true}
- ,layout: 'form'
- ,items: [{
- html: '<p>'+_('tv_tmpl_access_msg')+'</p>'
- ,xtype: 'modx-description'
- },{
- xtype: 'modx-grid-tv-template'
- ,itemId: 'grid-template'
- ,cls:'main-wrapper'
- ,tv: config.tv
- ,preventRender: true
- ,anchor: '100%'
- ,listeners: {
- 'rowclick': {fn:this.markDirty,scope:this}
- ,'afteredit': {fn:this.markDirty,scope:this}
- ,'afterRemoveRow': {fn:this.markDirty,scope:this}
- }
- }]
- },{
- title: _('access_permissions')
- ,id: 'modx-tv-access-form'
- ,itemId: 'form-access'
- ,forceLayout: true
- ,hideMode: 'offsets'
- ,defaults: {autoHeight: true}
- ,layout: 'form'
- ,items: [{
- html: '<p>'+_('tv_access_msg')+'</p>'
- ,id: 'modx-tv-access-msg'
- ,xtype: 'modx-description'
- },{
- xtype: 'modx-grid-tv-security'
- ,itemId: 'grid-access'
- ,cls:'main-wrapper'
- ,tv: config.tv
- ,preventRender: true
- ,anchor: '100%'
- ,listeners: {
- 'rowclick': {fn:this.markDirty,scope:this}
- ,'afteredit': {fn:this.markDirty,scope:this}
- ,'afterRemoveRow': {fn:this.markDirty,scope:this}
- }
- }]
- },{
- title: _('sources')
- ,id: 'modx-tv-sources-form'
- ,itemId: 'form-sources'
- ,defaults: {autoHeight: true}
- ,layout: 'form'
- ,hideMode: 'offsets'
- ,items: [{
- html: '<p>'+_('tv_sources.intro_msg')+'</p>'
- ,id: 'modx-tv-sources-msg'
- ,xtype: 'modx-description'
- },{
- xtype: 'modx-grid-element-sources'
- ,itemId: 'grid-sources'
- ,cls:'main-wrapper'
- ,id: 'modx-grid-element-sources'
- ,tv: config.tv
- ,preventRender: true
- ,listeners: {
- 'rowclick': {fn:this.markDirty,scope:this}
- ,'afteredit': {fn:this.markDirty,scope:this}
- ,'afterRemoveRow': {fn:this.markDirty,scope:this}
- }
- }]
- }],{
- id: 'modx-tv-tabs'
- ,forceLayout: true
- ,deferredRender: false
- ,stateful: true
- ,stateId: 'modx-tv-tabpanel-'+config.tv
- ,stateEvents: ['tabchange']
- ,hideMode: 'offsets'
- ,anchor: '100%'
- ,getState:function() {
- return {activeTab:this.items.indexOf(this.getActiveTab())};
- }
- })]
- ,useLoadingMask: true
- ,listeners: {
- 'setup': {fn:this.setup,scope:this}
- ,'success': {fn:this.success,scope:this}
- ,'beforeSubmit': {fn:this.beforeSubmit,scope:this}
- ,'failureSubmit': {
- fn: function () {
- this.showErroredTab(['modx-tv-form'], 'modx-tv-tabs')
- },
- scope: this
- }
- }
- });
- MODx.panel.TV.superclass.constructor.call(this,config);
- var isStatic = Ext.getCmp('modx-tv-static');
- if (isStatic) { isStatic.on('check',this.toggleStaticFile); }
- };
- Ext.extend(MODx.panel.TV,MODx.FormPanel,{
- initialized: false
- ,setup: function() {
- if (this.initialized) { this.clearDirty(); return true; }
- this.getForm().setValues(this.config.record);
- if (!Ext.isEmpty(this.config.record.name)) {
- var title = _('tv')+': '+this.config.record.name;
- if (MODx.perm.tree_show_element_ids === 1) {
- title = title+ ' <small>('+this.config.record.id+')</small>';
- }
- Ext.getCmp('modx-tv-header').getEl().update(title);
- }
- var d;
- if (!Ext.isEmpty(this.config.record.properties)) {
- d = this.config.record.properties;
- var g = Ext.getCmp('modx-grid-element-properties');
- if (g) {
- g.defaultProperties = d;
- g.getStore().loadData(d);
- }
- }
- if (!Ext.isEmpty(this.config.record.sources) && !this.initialized) {
- Ext.getCmp('modx-grid-element-sources').getStore().loadData(this.config.record.sources);
- }
- Ext.getCmp('modx-panel-tv-output-properties').showOutputProperties(Ext.getCmp('modx-tv-display'));
- Ext.getCmp('modx-panel-tv-input-properties').showInputProperties(Ext.getCmp('modx-tv-type'));
- this.fireEvent('ready',this.config.record);
- if (MODx.onLoadEditor) {MODx.onLoadEditor(this);}
- this.clearDirty();
- this.initialized = true;
- MODx.fireEvent('ready');
- return true;
- }
- /**
- * Set the browser window "media source" source
- */
- ,changeSource: function() {
- var browser = Ext.getCmp('modx-tv-static-file')
- ,source = Ext.getCmp('modx-tv-static-source').getValue();
- browser.config.source = source;
- }
- ,beforeSubmit: function(o) {
- var g = Ext.getCmp('modx-grid-tv-template');
- var rg = Ext.getCmp('modx-grid-tv-security');
- var sg = Ext.getCmp('modx-grid-element-sources');
- Ext.apply(o.form.baseParams,{
- templates: g.encodeModified()
- ,resource_groups: rg.encodeModified()
- ,sources: sg.encode()
- ,propdata: Ext.getCmp('modx-grid-element-properties').encode()
- });
- this.cleanupEditor();
- return this.fireEvent('save',{
- values: this.getForm().getValues()
- ,stay: MODx.config.stay
- });
- }
- ,success: function(r) {
- Ext.getCmp('modx-grid-tv-template').getStore().commitChanges();
- Ext.getCmp('modx-grid-tv-security').getStore().commitChanges();
- Ext.getCmp('modx-grid-element-sources').getStore().commitChanges();
- if (MODx.request.id) Ext.getCmp('modx-grid-element-properties').save();
- this.getForm().setValues(r.result.object);
- var t = Ext.getCmp('modx-tree-element');
- if (t) {
- var c = Ext.getCmp('modx-tv-category').getValue();
- var u = c != '' && c != null && c != 0 ? 'n_tv_category_'+c : 'n_type_tv';
- var node = t.getNodeById('n_tv_element_' + Ext.getCmp('modx-tv-id').getValue() + '_' + r.result.object.previous_category);
- if (node) node.destroy();
- t.refreshNode(u,true);
- }
- }
- ,changeEditor: function() {
- this.cleanupEditor();
- this.submit();
- }
- ,cleanupEditor: function() {
- if (MODx.onSaveEditor) {
- var fld = Ext.getCmp('modx-tv-default-text');
- MODx.onSaveEditor(fld);
- }
- }
- ,toggleStaticFile: function(cb) {
- var flds = ['modx-tv-static-file','modx-tv-static-file-help','modx-tv-static-source','modx-tv-static-source-help'];
- var fld,i;
- if (cb.checked) {
- for (i in flds) {
- fld = Ext.getCmp(flds[i]);
- if (fld) { fld.show(); }
- }
- } else {
- for (i in flds) {
- fld = Ext.getCmp(flds[i]);
- if (fld) { fld.hide(); }
- }
- }
- }
- });
- Ext.reg('modx-panel-tv',MODx.panel.TV);
- MODx.panel.TVInputProperties = function(config) {
- config = config || {};
- Ext.applyIf(config,{
- id: 'modx-panel-tv-input-properties'
- ,title: _('tv_input_options')
- ,header: false
- ,border: false
- ,defaults: { border: false }
- ,cls: 'form-with-labels'
- ,items: [{
- html: _('tv_input_options_msg')
- ,itemId: 'desc-tv-input-properties'
- ,xtype: 'modx-description'
- },{
- layout: 'form'
- ,border: false
- ,cls:'main-wrapper'
- ,labelAlign: 'top'
- ,labelSeparator: ''
- ,items: [{
- xtype: 'modx-combo-tv-input-type'
- ,fieldLabel: _('tv_type')
- ,description: MODx.expandHelp ? '' : _('tv_type_desc')
- ,name: 'type'
- ,id: 'modx-tv-type'
- ,itemid: 'fld-type'
- ,anchor: '100%'
- ,value: config.record.type || 'text'
- ,listeners: {
- 'select': {fn:this.showInputProperties,scope:this}
- }
- },{
- xtype: 'label'
- ,forId: 'modx-tv-type'
- ,html: _('tv_type_desc')
- ,cls: 'desc-under'
- },{
- xtype: 'textarea'
- ,fieldLabel: _('tv_elements')
- ,description: MODx.expandHelp ? '' : _('tv_elements_desc')
- ,name: 'els'
- ,id: 'modx-tv-elements'
- ,itemId: 'fld-els'
- ,anchor: '100%'
- ,grow: true
- ,maxHeight: 160
- ,value: config.record.elements || ''
- ,listeners: {
- 'change': {fn:this.markPanelDirty,scope:this}
- }
- },{
- xtype: MODx.expandHelp ? 'label' : 'hidden'
- ,forId: 'modx-tv-elements'
- ,html: _('tv_elements_desc')
- ,cls: 'desc-under'
- },{
- xtype: 'textarea'
- ,fieldLabel: _('tv_default')
- ,description: MODx.expandHelp ? '' : _('tv_default_desc')
- ,name: 'default_text'
- ,id: 'modx-tv-default-text'
- ,itemId: 'fld-default_text'
- ,anchor: '100%'
- ,grow: true
- ,maxHeight: 250
- ,value: config.record.default_text || ''
- ,listeners: {
- 'change': {fn:this.markPanelDirty,scope:this}
- }
- },{
- xtype: MODx.expandHelp ? 'label' : 'hidden'
- ,forId: 'modx-tv-default-text'
- ,html: _('tv_default_desc')
- ,cls: 'desc-under'
- },{
- id: 'modx-input-props'
- ,autoHeight: true
- }]
- }]
- });
- MODx.panel.TVInputProperties.superclass.constructor.call(this,config);
- };
- Ext.extend(MODx.panel.TVInputProperties,MODx.Panel,{
- markPanelDirty: function() {
- Ext.getCmp('modx-panel-tv').markDirty();
- }
- ,showInputProperties: function(cb,rc,i) {
- var element = Ext.getCmp('modx-tv-elements');
- if (element) {
- element.show();
- }
- this.markPanelDirty();
- var pu = Ext.get('modx-input-props').getUpdater();
- pu.loadScripts = true;
- try {
- pu.update({
- url: MODx.config.connector_url
- ,method: 'GET'
- ,params: {
- 'action': 'element/tv/renders/getInputProperties'
- ,'context': 'mgr'
- ,'tv': this.config.record.id
- ,'type': cb.getValue() || 'default'
- }
- ,scripts: true
- });
- } catch(e) {MODx.debug(e);}
- }
- });
- Ext.reg('modx-panel-tv-input-properties',MODx.panel.TVInputProperties);
- MODx.panel.TVOutputProperties = function(config) {
- config = config || {};
- Ext.applyIf(config,{
- id: 'modx-panel-tv-output-properties'
- ,title: _('tv_output_options')
- ,header: false
- ,layout: 'form'
- ,cls: 'form-with-labels'
- ,defaults: {border: false}
- ,items: [{
- html: _('tv_output_options_msg')
- ,itemId: 'desc-tv-output-properties'
- ,xtype: 'modx-description'
- },{
- layout: 'form'
- ,border: false
- ,cls:'main-wrapper'
- ,labelAlign: 'top'
- ,items: [{
- xtype: 'modx-combo-tv-widget'
- ,fieldLabel: _('tv_output_type')
- ,name: 'display'
- ,hiddenName: 'display'
- ,id: 'modx-tv-display'
- ,itemId: 'fld-display'
- ,value: config.record.display || 'default'
- ,anchor: '100%'
- ,listeners: {
- 'select': {fn:this.showOutputProperties,scope:this}
- }
- },{
- xtype: MODx.expandHelp ? 'label' : 'hidden'
- ,labelSeparator: ''
- ,forId: 'modx-tv-display'
- ,html: _('tv_output_type_desc')
- ,cls: 'desc-under'
- },{
- id: 'modx-widget-props'
- ,autoHeight: true
- }]
- }]
- });
- MODx.panel.TVOutputProperties.superclass.constructor.call(this,config);
- };
- Ext.extend(MODx.panel.TVOutputProperties,MODx.Panel,{
- showOutputProperties: function(cb,rc,i) {
- Ext.getCmp('modx-panel-tv').markDirty();
- var pu = Ext.get('modx-widget-props').getUpdater();
- pu.loadScripts = true;
- try {
- pu.update({
- url: MODx.config.connector_url
- ,method: 'GET'
- ,params: {
- 'action': 'element/tv/renders/getProperties'
- ,'context': 'mgr'
- ,'tv': this.config.record.id
- ,'type': cb.getValue() || 'default'
- }
- ,scripts: true
- });
- } catch(e) {MODx.debug(e);}
- }
- });
- Ext.reg('modx-panel-tv-output-properties',MODx.panel.TVOutputProperties);
- MODx.grid.ElementSources = function(config) {
- var src = new MODx.combo.MediaSource();
- src.getStore().load();
- config = config || {};
- Ext.applyIf(config,{
- id: 'modx-grid-element-sources'
- ,fields: ['context_key','source','name']
- ,autoHeight: true
- ,primaryKey: 'id'
- ,columns: [{
- header: _('context')
- ,dataIndex: 'context_key'
- },{
- header: _('source')
- ,dataIndex: 'source'
- ,xtype: 'combocolumn'
- ,editor: src
- ,gridId: 'modx-grid-element-sources'
- }]
- });
- MODx.grid.ElementSources.superclass.constructor.call(this,config);
- this.propRecord = Ext.data.Record.create(['context_key','source']);
- };
- Ext.extend(MODx.grid.ElementSources,MODx.grid.LocalGrid,{
- getMenu: function() {
- return [];
- }
- });
- Ext.reg('modx-grid-element-sources',MODx.grid.ElementSources);
|