Pwirth has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/337398 )
Change subject: [WIP] BSFoundation: Added basic oojs ui components for bluespice
......................................................................
[WIP] BSFoundation: Added basic oojs ui components for bluespice
* ApiStoreLookup
* ComboBoxInputBase
Change-Id: Iaaf301d0d7b7a6973cd80cdb55ff9c7f8e76c464
---
M extension.json
A resources/bluespice.oojs/bluespice.ui.js
A resources/bluespice.oojs/mixin/element/ApiStoreLookup.js
A resources/bluespice.oojs/ui/widget/ComboBoxInputBase.js
4 files changed, 138 insertions(+), 0 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation
refs/changes/98/337398/1
diff --git a/extension.json b/extension.json
index aa162bf..370f8bb 100644
--- a/extension.json
+++ b/extension.json
@@ -175,6 +175,23 @@
],
"group": "bsextjs"
},
+ "ext.bluespice.oojs": {
+ "localBasePath": "resources",
+ "remoteExtPath": "BlueSpiceFoundation/resources",
+ "targets": [
+ "mobile", "desktop"
+ ],
+ "scripts": [
+ "bluespice.oojs/bluespice.ui.js",
+
"bluespice.oojs/mixin/element/ApiStoreLookup.js",
+ "bluespice.oojs/ui/widget/ComboBoxInputBase.js"
+ ],
+ "dependencies": [
+ "mediawiki.api",
+ "oojs-ui",
+ "ext.bluespice"
+ ]
+ },
"ext.bluespice.upload": {
"localBasePath": "resources",
"remoteExtPath": "BlueSpiceFoundation/resources",
diff --git a/resources/bluespice.oojs/bluespice.ui.js
b/resources/bluespice.oojs/bluespice.ui.js
new file mode 100644
index 0000000..47a793d
--- /dev/null
+++ b/resources/bluespice.oojs/bluespice.ui.js
@@ -0,0 +1,6 @@
+
+bs = bs || {};
+bs.ui = bs.ui || {};
+bs.ui.mixin = bs.ui.mixin || {};
+bs.ui.mixin.element = bs.ui.mixin.element || {};
+bs.ui.widget = bs.ui.widget || {};
\ No newline at end of file
diff --git a/resources/bluespice.oojs/mixin/element/ApiStoreLookup.js
b/resources/bluespice.oojs/mixin/element/ApiStoreLookup.js
new file mode 100644
index 0000000..d8203df
--- /dev/null
+++ b/resources/bluespice.oojs/mixin/element/ApiStoreLookup.js
@@ -0,0 +1,74 @@
+/**
+ *
+ * @class
+ * @abstract
+ * @extends OO.ui.mixin.LookupElement
+ *
+ * @constructor
+ * @param {Object} [config] Configuration options
+ * @cfg {jQuery} [$overlay] Overlay for the lookup menu; defaults to relative
positioning
+ * @cfg {jQuery} [$container=this.$element] The container element. The lookup
menu is rendered beneath the specified element.
+ * @cfg {boolean} [allowSuggestionsWhenEmpty=false] Request and display a
lookup menu when the text input is empty.
+ * By default, the lookup menu is not generated and displayed until the user
begins to type.
+ * @cfg {boolean} [highlightFirst=true] Whether the first lookup result should
be highlighted (so, that the user can
+ * take it over into the input with simply pressing return) automatically or
not.
+ * @cfg {object} [store=params:{}, labelField, dataField, root ]
+ */
+bs.ui.mixin.element.ApiStoreLookup = function ( cfg ) {
+ var cfg = cfg || {};
+ OO.ui.mixin.LookupElement.call( this, cfg );
+
+ var me = this;
+ me.token = cfg.token || 'csrf';
+ me.store = cfg.store || {};
+ me.store = $.extend( true, {
+ params: {
+ type: "json"
+ },
+ labelField: "text",
+ dataField: "",
+ root: "results"
+ }, me.store );
+ me.api = new mw.Api();
+};
+
+OO.mixinClass( bs.ui.mixin.element.ApiStoreLookup, OO.ui.mixin.LookupElement );
+
+bs.ui.mixin.element.ApiStoreLookup.prototype.getLookupRequest = function() {
+ var me = this;
+ var $dfd = $.Deferred();
+ var api = new mw.Api();
+ this.api.postWithToken( me.token, me.store.params )
+ .done(function( response ){
+ $dfd.resolve( response[me.store.root] );
+ })
+ .fail( function( code, errResp ) {
+ //:(
+ });
+ return $dfd.promise( { abort: me.abort } );
+};
+
+bs.ui.mixin.element.ApiStoreLookup.prototype.abort = function () {
+ //TODO!
+ return null;
+};
+
+bs.ui.mixin.element.ApiStoreLookup.prototype.getLookupCacheDataFromResponse
+ = function ( response ) {
+ return response || [];
+};
+
+bs.ui.mixin.element.ApiStoreLookup.prototype.getLookupMenuOptionsFromData
+ = function ( data ) {
+ var items = [], i;
+ for ( i = 0; i < data.length; i++ ) {
+ items.push( new OO.ui.MenuOptionWidget( {
+ data: !this.store.dataField || this.store.dataField ===
""
+ ? data[i]
+ : data[i][this.store.dataField],
+ text: data[i][this.store.labelField]
+ }));
+ }
+
+ return items;
+};
\ No newline at end of file
diff --git a/resources/bluespice.oojs/ui/widget/ComboBoxInputBase.js
b/resources/bluespice.oojs/ui/widget/ComboBoxInputBase.js
new file mode 100644
index 0000000..42f1d70
--- /dev/null
+++ b/resources/bluespice.oojs/ui/widget/ComboBoxInputBase.js
@@ -0,0 +1,41 @@
+/**
+ *
+ * @class
+ * @abstract
+ * @extends OO.ui.ComboBoxInputWidget
+ *
+ * @constructor
+ * @param {Object} [config] Configuration options
+ * @cfg {Object[]} [options=[]] Array of menu options in the format `{ data:
…, label: … }`
+ * @cfg {Object} [menu] Configuration options to pass to the {@link
OO.ui.FloatingMenuSelectWidget menu select widget}.
+ * @cfg {jQuery} [$overlay] Render the menu into a separate layer. This
configuration is useful in cases where
+ * the expanded menu is larger than its containing `<div>`. The specified
overlay layer is usually on top of the
+ * containing `<div>` and has a larger area. By default, the menu uses
relative positioning.
+ */
+bs.ui.widget.ComboBoxInputBase = function ( cfg ) {
+ var me = this;
+
+ OO.ui.ComboBoxInputWidget.call( this, cfg );
+ bs.ui.mixin.element.ApiStoreLookup.call( this, cfg );
+};
+
+OO.inheritClass( bs.ui.widget.ComboBoxInputBase, OO.ui.ComboBoxInputWidget );
+OO.mixinClass(
+ bs.ui.widget.ComboBoxInputBase,
+ bs.ui.mixin.element.ApiStoreLookup
+);
+
+/*bs.ui.widget.ComboBoxInputBase.prototype.getLookupMenuOptionsFromData
+ = function ( data ) {
+ console.log(data);
+ var items = [], i, number;
+ for ( i = 0; i < data.length; i++ ) {
+ items.push( new OO.ui.MenuOptionWidget( {
+ data: data[i].page_id,
+ label: data[i].page_title
+ }));
+ }
+
+ return items;
+};*/
+OO.initClass( bs.ui.widget.ComboBoxInputBase );
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/337398
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaaf301d0d7b7a6973cd80cdb55ff9c7f8e76c464
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Pwirth <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits