Difference between revisions of "MediaWiki:Gadget-pdooui.js"

From Wikibase Personal data
Jump to navigation Jump to search
m
m
Line 45: Line 45:
 
textInput = [];
 
textInput = [];
  
 +
console.log( "why not " + result[orig] );
 
var extrafield = ( result[orig] != undefined ) ? Object.keys(result[orig]).length : 0;
 
var extrafield = ( result[orig] != undefined ) ? Object.keys(result[orig]).length : 0;
 +
console.log(extrafield);
  
 
button_save[ extrafield ] = new OO.ui.ButtonWidget( { label: "Save", classes: [ 'pddh' ] } );
 
button_save[ extrafield ] = new OO.ui.ButtonWidget( { label: "Save", classes: [ 'pddh' ] } );
 +
 
textInput[ extrafield ] = new OO.ui.TextInputWidget( {  
 
textInput[ extrafield ] = new OO.ui.TextInputWidget( {  
 
placeholder: plch,
 
placeholder: plch,
Line 58: Line 61:
 
console.log( "textInput[ extrafield ].value" + textInput[ extrafield ].value );
 
console.log( "textInput[ extrafield ].value" + textInput[ extrafield ].value );
  
idxb.EnqueuePDIO('update record', orig, extrafield, textInput[ extrafield ].$element.value )
+
idxb.EnqueuePDIO('update record', orig, extrafield, textInput[ extrafield ].value )
 
});
 
});
  

Revision as of 06:13, 20 May 2019

// License: GPL
// User Interface Rendering 
console.log('Interface handler loading');

function interfaceMediaContainer ( wbp, idxb ) {
	
	this.renderInterface = function( sqitch ) {
		switch( sqitch ) {
			case 'controller_id':
				controller_render();
				break;
			case 'personal_data_id':
				pd_site_render();
				break;
			case 'interface_button_id':
				pd_edit_render();
				break;
		}
	}

	async function controller_render(){
		console.log("this function is done by the current page controller for now");
	}

	async function pd_site_render(){

	};

	async function pd_edit_render(){
		var orig = wbproc.checkentity( { this_concerns: [ wbEStructure['concernsRelation'], wbEStructure['IDPropLoc'], wbEStructure['IDName'] ] } )['this_concerns'][0];
		var plch = wbproc.checkentity( { default_value: [ wbEStructure['defaultValRelation'], wbEStructure['IDPropLoc'] ] } )['default_value'][0]; //defal
		var q = idxb.EnqueuePDIO('update record');
		q.then( function(result) {
			console.log("required data from idxb");
			console.log( orig );
			console.log( plch );
			console.log( q );

			mw.loader.using( 'oojs-ui-core' ).done( function () {
				
				console.log("loaded uicore")

				var button_save = [],
					button_delete = [],
					textInput = [];

				console.log( "why not " + result[orig] );
				var extrafield = ( result[orig] != undefined ) ? Object.keys(result[orig]).length : 0;
				console.log(extrafield);

				button_save[ extrafield ] = new OO.ui.ButtonWidget( { label: "Save", classes: [ 'pddh' ] } );
				
				textInput[ extrafield ] = new OO.ui.TextInputWidget( { 
						placeholder: plch,
						classes: [ 'pddh' ]
				} );

				button_save[ extrafield ].on( 'click', function () {
							console.log( "this is happening " + orig + ' :: ' + extrafield);

							console.log( "textInput[ extrafield ].value" + textInput[ extrafield ].value );

							idxb.EnqueuePDIO('update record', orig, extrafield, textInput[ extrafield ].value )
				});

				$( '#mw-content-text' ).prepend( textInput[ extrafield ].$element );
				$( '#mw-content-text' ).prepend( '<br>' );
				$( '#mw-content-text' ).prepend( button_save[ extrafield ].$element );
				$( '#mw-content-text' ).prepend( '<br>' );
				$( '#mw-content-text' ).prepend( '<br>' );

				if ( extrafield > 0) {
					Object.keys( result[orig] ).forEach( function(data) {
						console.log("iter " + data + 'in');
						console.log(result[orig]);
						button_save[data] = new OO.ui.ButtonWidget( { label: "Save", classes: [ 'pddh' ]	} );
						button_delete[data] = new OO.ui.ButtonWidget( { label: "Delete", classes: [ 'pddh' ] } );
						textInput[data] = new OO.ui.TextInputWidget( { 
							value: result[orig][data],				///
							placeholder: plch,
							classes: [ 'pddh' ]
						} );
						button_save[data].on( 'click', function () {
							console.log( "this is happening " + orig + ' :: ' + data);

							console.log( "textInput[ extrafield ].value" + textInput[ data ].value );

							idxb.EnqueuePDIO('update record', orig, data, textInput[ data ].value )
						});
						$( '#mw-content-text' ).prepend( textInput[data].$element );
						$( '#mw-content-text' ).prepend( '<br>' );
						$( '#mw-content-text' ).prepend( button_delete[data].$element );
						$( '#mw-content-text' ).prepend( button_save[data].$element );
						$( '#mw-content-text' ).prepend( '<br>' );
						$( '#mw-content-text' ).prepend( '<br>' );



					});

				}
			});
		});
	};
}