logo
down
shadow

create an add/remove or refresh function in a boilerplate plugin


create an add/remove or refresh function in a boilerplate plugin

By : Никита Мусалов
Date : November 22 2020, 11:17 AM
this one helps. I am going to answer this myself :) Basically I decided that this was not the best way to handle my widget, so I used the widget factory boilerplate to sort out my issue. I modified my click event to this:
code :
$("#assets").on("click", ".glyphicon", function () {
    var $asset = $(this).parent(); // Get our asset element
    var $actionBar = $("#action-bar"); // Get the action bar
    var $selected = $("#selected-asset");// Get our selected asset counter

    var currentSelected = parseInt($selected.text()); // Get our current counter value
    var assetId = parseInt($asset.attr("id")); // Get the asset id
    var asset = $.grep(assets, function (obj) { // Find our asset from our array
        return obj.Id == assetId;
    });

    if ($asset.hasClass("active")) { // If our asset is already selected, then we must unselect it
        $selected.text(currentSelected - 1); // First, decrease our counter
        tableWidget.tableBuilder("remove", asset[0]); // Then call our widget and remove the current asset from the table
        activeItems = $.grep(activeItems, function (obj) { // Repopulate our array of active assets
            return obj != asset;
        });
        $asset.removeClass("active"); // And remove the active class from our element

        if (activeItems.length <= 0) { // Finally, if this is the only selected asset
            $actionBar.hide(); // Hide our actionbar
        }
    } else { // Else, we are selecting an asset
        $selected.text(currentSelected + 1); // Increase our counter
        tableWidget.tableBuilder("add", asset[0]); // Add a row to our widget
        activeItems.push(asset[0]); // Add the asset to our array of active assets
        $asset.addClass("active"); // Add our active alss to our element

        $actionBar.show(); // And show our actionbar
    }
});
var row = "<tr data-id=\"{Id}\"><td>{FileName}</td><td>{Metadata.FileSize}</td><td></td><td><button type=\"button\" class=\"close\" data-id=\"{Id}\" aria-hidden=\"true\">&times;</button></td></tr>"
var tableWidget;

$(function () {
    tableWidget = $("#assets-table").tableBuilder({
        rowTemplate: row
    });
});
/*!
 * jQuery UI Widget-factory plugin boilerplate (for 1.8/9+)
 * Author: @addyosmani
 * Further changes: @peolanha
 * Licensed under the MIT license
 */

    String.prototype.format = function (values) {

        var regex = /\{([\w-.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g;

        var getValue = function (key) {
            var value = values,
                arr, type;

            if (values == null || typeof values === 'undefined') return null;

            if (key.indexOf('.')) {
                arr = key.split('.');

                while (arr.length && value) {
                    value = value[arr.shift()];
                }
            } else {
                value = val && val[key] || values[key];
            }

            type = typeof value;

            return type === 'string' || type === 'number' ? value : null;
        };

        return this.replace(regex, function (match) {
            //match will look like {sample-match}
            //key will be 'sample-match';
            var key = match.substr(1, match.length - 2);

            var value = getValue(key);

            return value != null ? value : match;
        });
    };

; (function ($, window, document, undefined) {

    // define your widget under a namespace of your choice
    //  with additional parameters e.g.
    // $.widget( "namespace.widgetname", (optional) - an
    // existing widget prototype to inherit from, an object
    // literal to become the widget's prototype );

    $.widget("skipstone.tableBuilder", {

        //Options to be used as defaults
        options: {
            json: null,
            rowTemplate: null
        },

        //Setup widget (eg. element creation, apply theming
        // , bind events etc.)
        _create: function () {

            // _create will automatically run the first time
            // this widget is called. Put the initial widget
            // setup code here, then you can access the element
            // on which the widget was called via this.element.
            // The options defined above can be accessed
            // via this.options this.element.addStuff();

            this.rows = [];

            if (this.options.json != null) {
                this._buildRow();
                this._display();
            }
        },

        _buildRow: function () {
            var self = this;

            $.each(self.options.json, function (i, item) {
                self.rows.push(self.options.rowTemplate.format(item));
            });
        },

        _display: function (el, options) {
            $(this.element).html(this.rows.join());
        },

        add: function (row) {
            this.rows.push(this.options.rowTemplate.format(row));
            this._display();
        },

        remove: function(row) {
            var match = this.options.rowTemplate.format(row);
            this.rows = $.grep(this.rows, function (obj) {
                return obj != match;
            });
            this._display();
        },

        // Destroy an instantiated plugin and clean up
        // modifications the widget has made to the DOM
        destroy: function () {

            // this.element.removeStuff();
            // For UI 1.8, destroy must be invoked from the
            // base widget
            $.Widget.prototype.destroy.call(this);
            // For UI 1.9, define _destroy instead and don't
            // worry about
            // calling the base widget
        }
    });

})(jQuery, window, document);
tableWidget.tableBuilder("add", asset[0]);
tableWidget.tableBuilder("remove", asset[0]);


Share : facebook icon twitter icon
Backbone Boilerplate - fetch method don't refresh collection

Backbone Boilerplate - fetch method don't refresh collection


By : Sifat Hossain
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further is my first question here, so I please about some patience and forgive my english:) , I belive you should set the catalog in the initialize function
code :
app.catalog = new Browser.Catalog();
initialize: function (options) {
    app.catalog = new Browser.Catalog();
}
AMD plugin boilerplate: how to execute the plugin in non-AMD environment?

AMD plugin boilerplate: how to execute the plugin in non-AMD environment?


By : Suraj Kumar
Date : March 29 2020, 07:55 AM
seems to work fine I use the following template for jQuery plugins with AMD support
https://gist.github.com/simonsmith/4353587
Plugin based on WP Plugin Boilerplate returning error "Warning: call_user_func_array() expects parameter 1 to be a

Plugin based on WP Plugin Boilerplate returning error "Warning: call_user_func_array() expects parameter 1 to be a


By : user3712740
Date : March 29 2020, 07:55 AM
To fix this issue I am building a Wordpress plugin based on the Wordpress Plugin Boilerplate (Object-Orientated Programming) and I am facing a difficulty when calling the function displaying my plugin admin page in my custom admin dashboard menu. , Try to put your display_admin_page() method outside the class
code :
function display_admin_page() {

    echo '<div class="wrap">';
    echo '<h2>Welcome To WordPets</h2>';
    echo '<p>This is the custom admin page created from the custom admin menu.</p>';


    echo '</div><!-- end .wrap -->';
    echo '<div class="clear"></div>';
}
Wordpress plugin boilerplate table create

Wordpress plugin boilerplate table create


By : Der Kaiser
Date : March 29 2020, 07:55 AM
To fix this issue Hi I have a terrible problem. I generated the code plug on the page: http://wppb.me/
code :
        register_activation_hook( __FILE__,array( 'My_Activator', 'activate' )  );
class My_Activator {
    public static function activate() {
global $wpdb;
        global $jal_db_version;
        $table_name = $wpdb->prefix . 'fnotice';
        $charset_collate = $wpdb->get_charset_collate();

        $sql = "CREATE TABLE $table_name (
                    id INT NOT NULL AUTO_INCREMENT,
                    msg varchar(500) NOT NULL,
                    time DATETIME NOT NULL,
                    type varchar(350) NOT NULL,
                    link varchar(350) NOT NULL,
                    status ENUM('0', '1') NOT NULL default '1',
                    PRIMARY KEY (id) )";

        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
        dbDelta( $sql );

        add_option( 'jal_db_version', $jal_db_version );

    }

}
Refresh permissions from in-memory cache with ASP.NET Boilerplate

Refresh permissions from in-memory cache with ASP.NET Boilerplate


By : brandon gray
Date : March 29 2020, 07:55 AM
should help you out When I explicitly set a permission for a user in the database by running a SQL update script, the particular permission with the latest grant is not reflecting in the system. However when I recycle the IIS process or rebuild the solution, it only then seems to update. , You can inject ICacheManager and clear the cache:
code :
public void ForceRefresh()
{
    _cacheManager.GetUserPermissionCache().Clear();
 // _cacheManager.GetRolePermissionCache().Clear();
}
Related Posts Related Posts :
  • How to fix "Object is possibly undefined"?
  • How can one use TensorFlow.js tf.data.generator for remote data sources since generators can't use callbacks
  • How can I unescape a string from python using javascript
  • How to add days into my date using angular pipe?
  • Keydown not firing on page loaded in <object> element
  • Refetch queries in react-native with graphql
  • How to execute functions across objects identically to executing the function itself with a this reference
  • NGRX Effect withLatestFrom Typescript error ts2345 troubleshooting
  • Make a checkbox checked if its id is present in an array
  • Remove disabled class when response code is 1 in each element javascript
  • Creating an input select in an editable form
  • How to convert string of ASCII codes to string of characters?
  • Detect system time and set css animation start time in browser
  • How can I build a dataTable, with a dropbox filter on top, calculated on backend?
  • What needs to be done to make multiple screen support for Javascript happen?
  • How to format a full year date/time
  • this.props.match.params passed into child component after authorisation
  • Highcharts: create multiple series grouped my month and year using JSON data
  • JS: Keep variable values for onclick event attached inside for loop
  • Failed prop type. Required prop types are undefined in my redux store
  • How to not import Vue in main js and store
  • Javascript make table with rows and columns given by user and change each cells colour onclick
  • How do you fix "ERROR in Path must be a string. Received undefined" in webpack4/copy-webpack-plugin
  • Protractor Fetching Email with Mail Listener: TypeError: deferred.fulfill is not a function
  • date-time picker bootstrap Tempus Dominus
  • How do I get all radio button id's via the name
  • Using d3 in for loop
  • Impact an array of objects
  • JS split string and return index of each split
  • Javascript/JS - Referring to classes and variables dynamically within a change event loop
  • Query a specific GET field?
  • Mapping multiple form inputs of the same name into a JavaScript object
  • How can I not to return a field from object in JavaScript?
  • Creating and testing a single Javascript nested function
  • Formatting server side jQuery Datatable
  • How to show tooltips onmouseover in p:calendar
  • typescript - calling function at random intervals in ionic
  • Correct way to populate an array from a promise
  • JavaScript Mini-Max Sum - Returns 0
  • canvas not clearing while radius of circle decreasing..?
  • Dynamically Growing Dropdown Component with clickoutside directive
  • MultichoiceField in ModelForm for Django with DB relations
  • React Native "if" statement behaviour? Early exit or full evaluation?
  • Call Jquery function on Input tag having data-slider
  • How to process negative shifts in Caesars Cipher (Javascript)
  • Animating Line position in Konva
  • Why a state is not resolved as a variable in nextjs
  • How to efficiently evaluate element in javascript array by using reduce function
  • Google script web app goes blank page after submit
  • Event for the load-end of dynamically added CSS files through innerHTML
  • How to retrieve some text from a sibling div element in jQuery
  • How to display half star rating in my following custom angular star rating example?
  • Angular 8: ternary operation for img src attribute?
  • Is this proper JS for this J-Query expanding textArea? Is 'this' the same as event.target in JS also?
  • How to fix user fetching from a collection in discord.js?
  • Can I create an item id when adding it to a collection?
  • Temporarily disable a specific option after it has been selected (in any selector) for all instances of that selector in
  • Vis.js timeline item align property not working
  • How to select one element instead of all elements using 'clicked' in a Django for loop
  • How to check if 2 <img> tags contain the same image
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org