Exemple #1
0
func (a *Handler) PostSaved(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	c, err := rellenv.FromContext(ctx)
	if err != nil {
		return err
	}
	if !rellenv.IsEmployee(ctx) {
		return ctxerr.Wrap(ctx, errSaveDisabled)
	}
	if !a.Xsrf.Validate(r.FormValue(paramName), w, r, savedPath) {
		return ctxerr.Wrap(ctx, errTokenMismatch)
	}
	content := strings.TrimSpace(r.FormValue("code"))
	content = strings.Replace(content, "\x13", "", -1) // remove CR
	id := examples.ContentID(content)
	db := a.ExampleStore.DB
	example, ok := db.Reverse[id]
	if ok {
		http.Redirect(w, r, c.ViewURL(example.URL), 302)
		return nil
	}
	err = a.ExampleStore.Save(id, content)
	if err != nil {
		return err
	}
	http.Redirect(w, r, c.ViewURL(savedPath+id), 302)
	return nil
}
Exemple #2
0
func (e *editorTop) HTML(ctx context.Context) (h.HTML, error) {
	left := h.Frag{
		&h.A{
			ID: "rell-login",
			Inner: &h.Span{
				Inner: h.String(" Log In"),
			},
		},
		h.String(" "),
		&h.Span{ID: "auth-status-label", Inner: h.String("Status:")},
		h.String(" "),
		&h.Span{ID: "auth-status", Inner: h.String("waiting")},
		h.String(" "),
		&h.Span{Class: "bar", Inner: h.String("|")},
		h.String(" "),
		&h.A{
			ID:    "rell-disconnect",
			Inner: h.String("Disconnect"),
		},
		h.String(" "),
		&h.Span{Class: "bar", Inner: h.String("|")},
		h.String(" "),
		&h.A{
			ID:    "rell-logout",
			Inner: h.String("Logout"),
		},
	}

	if rellenv.IsEmployee(e.Context) {
		return &h.Div{
			Class: "row-fluid form-inline",
			Inner: h.Frag{
				&h.Div{
					Class: "span8",
					Inner: left,
				},
				&h.Div{
					Class: "span4",
					Inner: &h.Div{
						Class: "pull-right",
						Inner: &envSelector{
							Context: e.Context,
							Env:     e.Env,
							Example: e.Example,
						},
					},
				},
			},
		}, nil
	}
	return &h.Div{
		Class: "row-fluid form-inline",
		Inner: h.Frag{
			&h.Div{
				Class: "span12",
				Inner: left,
			},
		},
	}, nil
}
Exemple #3
0
func (e *envSelector) HTML(ctx context.Context) (h.HTML, error) {
	if !rellenv.IsEmployee(e.Context) {
		return nil, nil
	}
	fbEnv := rellenv.FbEnv(e.Context)
	frag := h.Frag{
		h.HiddenInputs(url.Values{
			"server": []string{fbEnv},
		}),
	}
	for _, pair := range sortutil.StringMapByValue(envOptions) {
		if fbEnv == pair.Key {
			continue
		}
		ctxCopy := e.Env.Copy()
		ctxCopy.Env = pair.Key
		frag = append(frag, &h.Li{
			Inner: &h.A{
				Inner:  h.String(pair.Value),
				Target: "_top",
				HREF:   ctxCopy.ViewURL(e.Example.URL),
			},
		})
	}

	title := envOptions[fbEnv]
	if title == "" {
		title = fbEnv
	}
	return &h.Div{
		Class: "btn-group",
		Inner: h.Frag{
			&h.Button{
				Class: "btn",
				Inner: h.Frag{
					&h.I{Class: "icon-road"},
					h.String(" "),
					h.String(title),
				},
			},
			&h.Button{
				Class: "btn dropdown-toggle",
				Data: map[string]interface{}{
					"toggle": "dropdown",
				},
				Inner: &h.Span{
					Class: "caret",
				},
			},
			&h.Ul{
				Class: "dropdown-menu",
				Inner: frag,
			},
		},
	}, nil
}
Exemple #4
0
func (e *contextEditor) HTML(ctx context.Context) (h.HTML, error) {
	if !rellenv.IsEmployee(e.Context) {
		return h.HiddenInputs(e.Env.Values()), nil
	}
	return &h.Div{
		Class: "well form-horizontal",
		Inner: h.Frag{
			&ui.TextInput{
				Label:      h.String("Application ID"),
				Name:       "appid",
				Value:      rellenv.FbApp(e.Context).ID(),
				InputClass: "input-medium",
				Tooltip:    "Make sure the base domain in the application settings for the specified ID allows fbrell.com.",
			},
			&ui.ToggleGroup{
				Inner: h.Frag{
					&ui.ToggleItem{
						Name:        "init",
						Checked:     e.Env.Init,
						Description: h.String("Automatically initialize SDK."),
						Tooltip:     "This controls if FB.init() is automatically called. If off, you'll need to call it in your code.",
					},
					&ui.ToggleItem{
						Name:        "status",
						Checked:     e.Env.Status,
						Description: h.String("Automatically trigger status ping."),
						Tooltip:     "This controls the \"status\" parameter to FB.init.",
					},
					&ui.ToggleItem{
						Name:        "frictionlessRequests",
						Checked:     e.Env.FrictionlessRequests,
						Description: h.String("Enable frictionless requests."),
						Tooltip:     "This controls the \"frictionlessRequests\" parameter to FB.init.",
					},
				},
			},
			&h.Div{
				Class: "form-actions",
				Inner: h.Frag{
					&h.Button{
						Type:  "submit",
						Class: "btn btn-primary",
						Inner: h.Frag{
							&h.I{Class: "icon-refresh icon-white"},
							h.String(" Update"),
						},
					},
				},
			},
		},
	}, nil
}
Exemple #5
0
func (a *Handler) Handler(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	if !rellenv.IsEmployee(ctx) {
		return ctxerr.Wrap(ctx, errEmployeesOnly)
	}

	switch r.URL.Path {
	case Path:
		return a.Start(ctx, w, r)
	case Path + resp:
		return a.Response(ctx, w, r)
	}
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	w.WriteHeader(http.StatusNotFound)
	h.WriteResponse(w, r, &h.Script{
		Inner: h.Unsafe("top.location='/'"),
	})
	return nil
}
Exemple #6
0
func (e *editorBottom) HTML(ctx context.Context) (h.HTML, error) {
	runButton := &h.A{
		ID:    "rell-run-code",
		Class: "btn btn-primary",
		Inner: h.Frag{
			&h.I{Class: "icon-play icon-white"},
			h.String(" Run Code"),
		},
	}
	if !e.Example.AutoRun {
		runButton.Rel = "popover"
		runButton.Data = map[string]interface{}{
			"title":     "Click to Run",
			"content":   "This example does not run automatically. Click this button to run it.",
			"placement": "top",
			"trigger":   "manual",
		}
	}
	var saveButton h.HTML
	if rellenv.IsEmployee(e.Context) {
		saveButton = h.Frag{
			h.String(" "),
			&h.Div{
				Class: "btn-group",
				Inner: &h.Button{
					Class: "btn",
					Type:  "submit",
					Inner: h.Frag{
						&h.I{Class: "icon-file"},
						h.String(" Save Code"),
					},
				},
			},
		}
	}
	return &h.Div{
		Class: "row-fluid form-inline",
		Inner: h.Frag{
			&h.Strong{
				Class: "span4",
				Inner: &h.A{
					HREF:  e.Env.URL("/examples/").String(),
					Inner: h.String("Examples"),
				},
			},
			&h.Div{
				Class: "span8",
				Inner: &h.Div{
					Class: "btn-toolbar pull-right",
					Inner: h.Frag{
						&viewModeDropdown{
							Context: e.Context,
							Env:     e.Env,
							Example: e.Example,
						},
						saveButton,
						h.String(" "),
						&h.Div{
							Class: "btn-group",
							Inner: runButton,
						},
					},
				},
			},
		},
	}, nil
}