Git Product home page Git Product logo

gs.group.member.invite.csv's Introduction

gs.group.member.invite.csv

Send invitations to join a group in bulk

Author: Michael JasonSmith
Contact: Michael JasonSmith <[email protected]>
Date: 2014-09-17
Organization: GroupServer.org
Copyright: This document is licensed under a Creative Commons Attribution-Share Alike 4.0 International License by OnlineGroups.net.

Introduction

This product is concerned with the issuing of invitations to join an online group in bulk [1], using a CSV file submitted to a form. Most of the page is powered by JavaScript.

Form

The admin_invite_csv.html form, in the Group context, takes a CSV file and invites each person in the file (one per row) to join the group. The work is done in two main steps โ€” parsing and inviting โ€” which is controlled by JavaScript.

Parsing

In the CSV file each row represents a person, and each column represents a profile attribute. The form gs-group-member-invite-csv.json, in the group context [2], parses the information in the CSV file and returns a JSON object: a list of profile data. The JavaScript then handles the inviting.

The parsing form is a "JSON" form, as supplied by gs.content.form.api.json [4]. The HTTP PUT parses in a list of column identifiers and the CSV file, and a JSON object is returned. If successful the object is a list of profile-objects. If there is a problem then a JSON object is returned with status set to one of the following error numbers, and message set to a human readable message.

Error Name Note
-1 Form error "Standard" gs.content.form.api.json error.
-2 Unicode Decode Error The entire file could not be parsed.
-3 Column-count error The column count was different to the ID count.
-4 No rows No rows could be found in the CSV.
-5 Empty The CSV file was empty

Inviting

The inviting is actually carried out by gs.group.member.invite.json. If the CSV is fine then the JavaScript fires off invitation notifications provided by gs.group.member.invite.base. The invitation is responded to using one of the two pages in the gs.profile.invite module [3].

JavaScript

JavaScript is essential to the Invite by CSV system; without full compliance the page simply will not work. I decided to make the JavaScript a requirement because it drastically the system, reducing errors in my code, and drastically improves the usability. (The usability is far from good, but the earlier CSV Invite system would only show a spinner and generally end up showing a TCP Timeout error page.) The code, provided by the resource /++resource++gs-group-member-invite-csv.js, controls the marshalling of user-supplied data, a template generator, the parsing AJAX and the inviting AJAX. All are controlled by some connecting code.

User-supplied data

There are two components to the user-supplied data:

  • The CSV file (which we will ignore for now) and
  • The columns.

The latter is supported by the JavaScript class GSInviteByCSVOptionalAttributes. The page and code provide a table at Twitter Bootstrap dropdown that allows the group administrator to select the optional attributes in the page. The same class can marshal the data out of the HTML-table (embedded in the page) and into a list of profile attributes and names. These are used by the template generator and parsing ajax.

Template Generator

The template-CSV generator is provided by the GSInviteByCSVTemplateGenerator class. It examines the profile-attributes that have been specified by the group administrator and then generates a data-URL. This URL is then set as the href for a (hidden) anchor element that is then added to a page. Finally, a click event is fired, which causes the browser to "download" the CSV template.

Parsing AJAX

The JavaScript that powers the parsing AJAX is one of the reasons that only (relatively) new browsers support the Invite by CSV page. The class GSInviteByCSVParserAJAX makes use of the FormData [5] and File [6] APIs to marshal the data out of the form and to the parsing`_ form.

The same code examines the return value from the parser. If a problem was encountered then the error message is shown. Otherwise the inviting AJAX is called.

Inviting AJAX

The JavaScript code that actually invites each person is provided by the GSInviteByCSVInviterAJAX class. It maintains the list of people that are yet to be invited, updates the progress bar when the inviting form responds, and (depending on the response) updates the New, Ignored or Error lists.

Connecting code

As is fairly standard for GroupServer JavaScript the page uses attributes of the <script> element to pass data (such as URLs and element selectors) to the JavaScript. As is also fairly standard, the JavaScript is only initialised after the window has raised the load event. Events are used to connect one sequence of events (parsing the file) with another (inviting the people).

Finally, the connecting the code is also used to reset the entire form when the group administrator clicks on the Reset button.

Acknowledgements

The template generator code, like much that is tricky with the Web, is helped by Stack Overflow.

Resources

[1]For issuing a single invitation see the base product gs.group.member.invite.base: <https://github.com/groupserver/gs.group.member.invite.base>
[2]The form gs-group-member-invite-csv.json is also available in the site context, for day that the site-wide invite and add systems exist.
[3]See <https://github.com/groupserver/gs.profile.invite>
[4]See <https://github.com/groupserver/gs.content.form.api.json>
[5]See <https://developer.mozilla.org/en-US/docs/Web/API/FormData>
[6]See <https://developer.mozilla.org/en-US/docs/Web/API/File>

gs.group.member.invite.csv's People

Contributors

heldinz avatar mpj17 avatar piersg avatar richardwaid avatar wbushey avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.