1293
1294
1295
1296
1297
1298
1299
|
cgi_reset_content();
webpage_error("assertion fault at %s:%d - %s", zFile, iLine, zExpr);
}
#if INTERFACE
# define webpage_assert(T) if(!(T)){webpage_assert_page(__FILE__,__LINE__,#T);}
#endif
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
|
cgi_reset_content();
webpage_error("assertion fault at %s:%d - %s", zFile, iLine, zExpr);
}
#if INTERFACE
# define webpage_assert(T) if(!(T)){webpage_assert_page(__FILE__,__LINE__,#T);}
#endif
/*
** Outputs a labeled checkbox element. zFieldName is the form element
** name. zLabel is the label for the checkbox. zValue is the optional
** value for the checkbox. zTip is an optional tooltip, which gets set
** as the "title" attribute of the outermost element. If isChecked is
** true, the checkbox gets the "checked" attribute set, else it is
** not.
**
** Resulting structure:
**
** <div class='input-with-label' title={{zTip}}>
** <input type='checkbox' name={{zFieldName}} value={{zValue}}
** {{isChecked ? " checked : ""}}/>
** <span>{{zLabel}}</span>
** </div>
**
** zFieldName, zLabel, and zValue are required. zTip is optional.
**
** Be sure that the input-with-label CSS class is defined sensibly, in
** particular, having its display:inline-block is useful for alignment
** purposes.
*/
void style_labeled_checkbox(const char *zFieldName, const char * zLabel,
const char * zValue, const char * zTip,
int isChecked){
CX("<div class='input-with-label'");
if(zTip && *zTip){
CX(" title='%h'", zTip);
}
CX("><input type='checkbox' name='%s' value='%T'%s/>",
zFieldName,
zValue ? zValue : "", isChecked ? " checked" : "");
CX("<span>%h</span></div>", zLabel);
}
/*
** Outputs a SELECT list from a compile-time list of integers.
** The vargs must be a list of (const char *, int) pairs, terminated
** with a single NULL. Each pair is interpreted as...
**
** If the (const char *) is NULL, it is the end of the list, else
** a new OPTION entry is created. If the string is empty, the
** label and value of the OPTION is the integer part of the pair.
** If the string is not empty, it becomes the label and the integer
** the value. If that value == selectedValue then that OPTION
** element gets the 'selected' attribute.
**
** Note that the pairs are not in (int, const char *) order because
** there is no well-known integer value which we can definitively use
** as a list terminator.
**
** zFieldName is the value of the form element's name attribute.
**
** zLabel is an optional string to use as a "label" for the element
** (see below).
**
** zTooltip is an optional value for the SELECT's title attribute.
**
** The structure of the emitted HTML is:
**
** <div class='input-with-label' title={{zToolTip}}>
** <span>{{zLabel}}</span>
** <select>...</select>
** </div>
**
** Example:
**
** style_select_list_int("my_field", "Grapes",
** "Select the number of grapes",
** atoi(PD("my_field","0")),
** "", 1, "2", 2, "Three", 3,
** NULL);
**
*/
void style_select_list_int(const char *zFieldName, const char * zLabel,
const char * zToolTip, int selectedVal,
... ){
va_list vargs;
va_start(vargs,selectedVal);
CX("<div class='input-with-label'");
if(zToolTip && *zToolTip){
CX(" title='%h'",zToolTip);
}
CX(">");
if(zLabel && *zLabel){
CX("<span>%h</span>", zLabel);
}
CX("<select name='%s'>",zFieldName);
while(1){
const char * zOption = va_arg(vargs,char *);
int v;
if(NULL==zOption){
break;
}
v = va_arg(vargs,int);
CX("<option value='%d'%s>",
v, v==selectedVal ? " selected" : "");
if(*zOption){
CX("%s", zOption);
}else{
CX("%d",v);
}
CX("</option>\n");
}
CX("</select>\n");
if(zLabel && *zLabel){
CX("</div>\n");
}
va_end(vargs);
}
/*
** If passed 0, it emits a script opener tag with this session's
** nonce. If passed non-0 it emits a script closing tag. The very
** first time it is called, it emits some bootstrapping JS code
** immediately after the script opener. Specifically, it defines
** window.fossil if it's not already defined, and may set some
** properties on it.
*/
void style_emit_script_tag(int phase){
static int once = 0;
if(0==phase){
CX("<script nonce='%s'>", style_nonce());
if(0==once){
once = 1;
CX("\nif(!window.fossil) window.fossil={};\n");
CX("window.fossil.version = %Q;\n", get_version());
}
}else{
CX("</script>\n");
}
}
|