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

From Wikibase Personal data
Jump to navigation Jump to search
m
m
 
(8 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
console.log('Interface handler loading');
 
console.log('Interface handler loading');
  
function interfaceMediaContainer ( wbp, idxb ) {
+
function InterfaceMediaContainer ( WikibaseProcessor, indexedDBobject ) {
 
 
 
this.renderInterface = function( sqitch ) {
 
this.renderInterface = function( sqitch ) {
Line 14: Line 14:
 
break;
 
break;
 
case 'interface_button_id':
 
case 'interface_button_id':
pd_edit_render();
+
personal_data_edit_interface_render();
 
break;
 
break;
 
}
 
}
 
}
 
}
 +
 +
var button_save = [],
 +
button_remove = [],
 +
textInput = [];
  
 
async function controller_render(){
 
async function controller_render(){
Line 27: Line 31:
 
};
 
};
  
async function pd_edit_render(){
+
async function personal_data_edit_interface_render(){
var orig = wbproc.checkentity( { this_concerns: [ wbEStructure['concernsRelation'], wbEStructure['IDPropLoc'], wbEStructure['IDName'] ] } )['this_concerns'][0];
+
clear_render();
var plch = wbproc.checkentity( { default_value: [ wbEStructure['defaultValRelation'], wbEStructure['IDPropLoc'] ] } )['default_value'][0]; //defal
+
var q = idxb.EnqueuePDIO('update record');
+
// Get concerns relation :: Parts of this must be moved upstream, MAIN should know that this is the data the renderer will need and provide it
q.then( function(result) {
+
 
console.log("required data from idxb");
+
var concern_origin = WikibaseProcessor.checkentity( { this_concerns: [ WBEStructure['concernsRelation'], WBEStructure['IDPropLoc'], WBEStructure['IDName'] ] } )['this_concerns'][0];
console.log( orig );
+
 
console.log( plch );
+
// Get defval for entity :: Parts of this must be moved upstream, MAIN should know that this is the data the renderer will need and provide it
console.log( q );
+
 
 +
var default_value = WikibaseProcessor.checkentity( { default_value: [ WBEStructure['defaultValRelation'], WBEStructure['IDPropLoc'] ] } )['default_value'][0]; //defal
 +
 
 +
var get_record = indexedDBobject.EnqueuePDIO('get record');
 +
 
 +
get_record.then( function(result) {
  
 
mw.loader.using( 'oojs-ui-core' ).done( function () {
 
mw.loader.using( 'oojs-ui-core' ).done( function () {
 
console.log("loaded uicore")
 
  
var button_save = [],
+
button_save = [],
button_delete = [],
+
button_remove = [],
textInput = [];
+
textInput = [];
  
var extrafield = ( result[orig] != undefined ) ? Object.keys(result[orig]).length : 0;
+
var extrafield = ( result[concern_origin] != undefined ) ? Object.keys(result[concern_origin]).length : 0;
  
button_save[ extrafield ] = new OO.ui.ButtonWidget( { label: "Save", classes: [ 'pddh' ] } );
+
button_save[ extrafield ] = new OO.ui.ButtonWidget( { label: "Save", classes: [ 'pduimark' ] } );
 +
 
textInput[ extrafield ] = new OO.ui.TextInputWidget( {  
 
textInput[ extrafield ] = new OO.ui.TextInputWidget( {  
placeholder: plch,
+
placeholder: default_value,
classes: [ 'pddh' ]
+
classes: [ 'pduimark' ]
 
} );
 
} );
  
 
button_save[ extrafield ].on( 'click', function () {
 
button_save[ extrafield ].on( 'click', function () {
console.log( "this is happening " + orig + ' ' + extrafield);
+
indexedDBobject.EnqueuePDIO('update record', concern_origin, extrafield, textInput[ extrafield ].value );
idxb.EnqueuePDIO('update record', orig, extrafield, textInput[ extrafield ].$element.value )
+
personal_data_edit_interface_render();
 
});
 
});
  
 +
$( '#mw-content-text' ).prepend( button_save[ extrafield ].$element );
 
$( '#mw-content-text' ).prepend( textInput[ extrafield ].$element );
 
$( '#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) {
 
if ( extrafield > 0) {
Object.keys( result[orig] ).forEach( function(data) {
+
Object.keys( result[concern_origin] ).forEach( function(data) {
console.log("iter " + data + 'in');
+
button_save[data] = new OO.ui.ButtonWidget( { label: "Save", classes: [ 'pduimark' ] } );
console.log(result[orig]);
+
button_remove[data] = new OO.ui.ButtonWidget( { label: "Delete", classes: [ 'pduimark' ] } );
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( {  
 
textInput[data] = new OO.ui.TextInputWidget( {  
value: result[orig][data], ///
+
value: result[concern_origin][data], ///
placeholder: plch,
+
placeholder: default_value,
classes: [ 'pddh' ]
+
classes: [ 'pduimark' ]
 
} );
 
} );
 
button_save[data].on( 'click', function () {
 
button_save[data].on( 'click', function () {
idxb.EnqueuePDIO('update record', orig, data, 'holdplace')
+
 
 +
indexedDBobject.EnqueuePDIO('update record', concern_origin, data, textInput[ data ].value );
 +
 
 +
personal_data_edit_interface_render();
 
});
 
});
 +
 +
button_remove[data].on( 'click', function () {
 +
indexedDBobject.EnqueuePDIO('remove from record', concern_origin, data );
 +
personal_data_edit_interface_render();
 +
});
 +
$( '#mw-content-text' ).prepend( button_remove[data].$element );
 +
$( '#mw-content-text' ).prepend( button_save[data].$element );
 
$( '#mw-content-text' ).prepend( textInput[data].$element );
 
$( '#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>' );
 
 
 
  
 
});
 
});
Line 93: Line 99:
 
});
 
});
 
};
 
};
 +
 +
function clear_render() {
 +
var ifel = document.getElementsByClassName('pduimark');
 +
while( ifel[0] ) {
 +
    ifel[0].parentNode.removeChild(ifel[0]);
 +
};
 +
};
 +
 
}
 
}

Latest revision as of 06:17, 21 May 2019

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

function InterfaceMediaContainer ( WikibaseProcessor, indexedDBobject ) {
	
	this.renderInterface = function( sqitch ) {
		switch( sqitch ) {
			case 'controller_id':
				controller_render();
				break;
			case 'personal_data_id':
				pd_site_render();
				break;
			case 'interface_button_id':
				personal_data_edit_interface_render();
				break;
		}
	}

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

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

	async function pd_site_render(){

	};

	async function personal_data_edit_interface_render(){
		clear_render();
		
		// Get concerns relation :: Parts of this must be moved upstream, MAIN should know that this is the data the renderer will need and provide it 

		var concern_origin = WikibaseProcessor.checkentity( { this_concerns: [ WBEStructure['concernsRelation'], WBEStructure['IDPropLoc'], WBEStructure['IDName'] ] } )['this_concerns'][0];

		// Get defval for entity :: Parts of this must be moved upstream, MAIN should know that this is the data the renderer will need and provide it 

		var default_value = WikibaseProcessor.checkentity( { default_value: [ WBEStructure['defaultValRelation'], WBEStructure['IDPropLoc'] ] } )['default_value'][0]; //defal

		var get_record = indexedDBobject.EnqueuePDIO('get record');

		get_record.then( function(result) {

			mw.loader.using( 'oojs-ui-core' ).done( function () {

				button_save = [],
				button_remove = [],
				textInput = [];

				var extrafield = ( result[concern_origin] != undefined ) ? Object.keys(result[concern_origin]).length : 0;

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

				button_save[ extrafield ].on( 'click', function () {
							indexedDBobject.EnqueuePDIO('update record', concern_origin, extrafield, textInput[ extrafield ].value );
							personal_data_edit_interface_render();
				});

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

				if ( extrafield > 0) {
					Object.keys( result[concern_origin] ).forEach( function(data) {
						button_save[data] = new OO.ui.ButtonWidget( { label: "Save", classes: [ 'pduimark' ]	} );
						button_remove[data] = new OO.ui.ButtonWidget( { label: "Delete", classes: [ 'pduimark' ] } );
						textInput[data] = new OO.ui.TextInputWidget( { 
							value: result[concern_origin][data],				///
							placeholder: default_value,
							classes: [ 'pduimark' ]
						} );
						button_save[data].on( 'click', function () {

							indexedDBobject.EnqueuePDIO('update record', concern_origin, data, textInput[ data ].value );

							personal_data_edit_interface_render();
						});

						button_remove[data].on( 'click', function () {
							indexedDBobject.EnqueuePDIO('remove from record', concern_origin, data );
							personal_data_edit_interface_render();
						});
						$( '#mw-content-text' ).prepend( button_remove[data].$element );
						$( '#mw-content-text' ).prepend( button_save[data].$element );
						$( '#mw-content-text' ).prepend( textInput[data].$element );

					});

				}
			});
		});
	};

	function clear_render() {
		var ifel = document.getElementsByClassName('pduimark');
		while( ifel[0] ) {
		    ifel[0].parentNode.removeChild(ifel[0]);
		};
	};

}